Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.forth > #37672

Re: Parallel computing: faster 8 queens

From "WJ" <w_a_x_man@yahoo.com>
Newsgroups comp.lang.forth
Subject Re: Parallel computing: faster 8 queens
Date 2015-03-26 07:26 +0000
Organization A noiseless patient Spider
Message-ID <mf0ca9$ca6$1@dont-email.me> (permalink)
References <mf00ud$e3t$1@dont-email.me>

Show all headers | View raw


WJ wrote:

> Parallel version:
> 
> 
> func: decode-position {ListBuffer init(8, #[8 divrem swap]) nip}
> 
> func: no-dups? {asSet size 8 ==}
> 
> func: skew-board {swap 8 seq zipWith}
> 
> func: check(brd) {#[brd skew-board no-dups?] [#drop, #+, #-] conform
>   ifTrue: [brd println]}
> 
> "37777777" asIntegerOfBase(8) Constant new: middle
> "77777777" asIntegerOfBase(8) Constant new: top
> 
> func: go {
>   [ seqFrom( 0, middle ), seqFrom( middle ++, top ) ]
>   mapParallel( #[ apply( #[ decode-position check ] ) ] )
> }

To easily change the number of cores:


func: decode-position {ListBuffer init(8, #[8 divrem swap]) nip}

func: no-dups? {asSet size 8 ==}

func: skew-board {swap 8 seq zipWith}

func: check(brd) {#[brd skew-board no-dups?] [#drop, #+, #-] conform
  ifTrue: [brd println]}

2 Constant new: num-cores
"77777777" asIntegerOfBase(8) Constant new: top
seq( num-cores ) map(#[ asFloat num-cores / top * floor ])
Constant new: ends

func: go {
  ends
  [0] ends left( num-cores -- ) map( #++ ) +
  zipWith( #seqFrom )
  mapParallel( #[ apply( #[ decode-position check ] ) ] )
  drop }

Back to comp.lang.forth | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Parallel computing: faster 8 queens "WJ" <w_a_x_man@yahoo.com> - 2015-03-26 04:11 +0000
  Re: Parallel computing: faster 8 queens "WJ" <w_a_x_man@yahoo.com> - 2015-03-26 07:26 +0000
    Re: Parallel computing: faster 8 queens franck.bensusan@gmail.com - 2015-03-28 03:32 -0700

csiph-web