You are right. The algorithm shown in https://en.wikipedia.org/wiki/Eight_queens_puzzle gives one solution only. I did not realize that you want all solutions. Sorry for that. In order to find all solutions you indeeed need a backtracking algorithm, I think, which requires much more computation. In that respect the times you report seem very reasonably to me. As you have shown it is not too difficult to compute all solutions, but the question which algorithm would be the fast one remains an open question for me too. My advice: first look at the efficiency of the algorithm you want to use. In the past I have run into problems by not doing so, producing programs running parallelly on many processors, but not faster than when running on one processor only. First consider the algorithm, then the implementation. A simple example where the implementation may go wrong in respect to computing time, is in computing binomial coefficients. I am sure there are much more examples. May be a define-with-hash may help, producing functions that use a hash to remember previous calls with the same arguments. It may be necessary to define the hash such as to recognize distinct, but computationaly symmetrical problems. Best wishes, Jos
-----Original Message----- From: Brian Adkins [mailto:lojicdot...@gmail.com] Sent: sábado, 12 de marzo de 2016 23:33 To: Jos Koot Cc: Racket Users Subject: Re: [racket-users] Sequential vs. Parallel 13-Queens program The code is a little difficult for me to read. It doesn't seem to collect *all* solutions for a given N. If that's the case, would you be able to modify it to do so to allow a more direct comparison? > On Mar 12, 2016, at 1:19 PM, Jos Koot <jos.k...@gmail.com> wrote: > > See https://en.wikipedia.org/wiki/Eight_queens_puzzle > For a non recursive non-back-tracking algorithm. > It is a loop that (when using a vector) can easily be unrolled in parallelly > executed loops. > I implemented it as follows running on 2 processors: > snip > > Jos > > > -----Original Message----- > From: racket-users@googlegroups.com [mailto:racket-users@googlegroups.com] > On Behalf Of Brian Adkins > Sent: sábado, 12 de marzo de 2016 1:42 > To: Racket Users > Subject: [racket-users] Sequential vs. Parallel 13-Queens program > > I coded up a sequential and parallel version of N-Queens, then did a ton of > benchmark runs of 13-Queens to compare the time. For each configuration > (sequential or parallel w/ M workers), I ran the programs 6 times, threw out > the high two & low two and averaged the middle two numbers. > > The spreadsheet with timings is here: > > https://docs.google.com/spreadsheets/d/1LFwdZbBveaARY_AquGXY9jgaSJlOA03NQCV9 > TeYQ-l8/edit?usp=sharing > > The code is here: > > https://gist.github.com/lojic/aef0aec491d3dc9cb40b > > I didn't spend any time refining/optimizing, so it's fairly crude, but > informative nonetheless. > > The executive summary of timings for the parallel version: > > # Places Time > 1 34.9 > 2 19.7 > 3 13.8 > 4 12.3 > 5 11.9 > 6 12.9 > 7 12.1 > 8 12.2 > > The sequential version took 31.3 seconds. > > The basic idea for the parallel version is to place the first 13 starting > positions in a queue that the place workers will pull from and produce a set > of solutions with that starting position. Both the parallel and sequential > versions collect all 73,712 solutions in a list and compute the length of > it. I hardcoded the number of solutions as a quick & dirty way of > determining completion in the parallel version just to allow me to get the > timings easily. > > It was great to finally write some Racket code that got all my cores heated > up :) > > Brian > > -- > You received this message because you are subscribed to the Google Groups > "Racket Users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to racket-users+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.