I want to parallelize a procedure which looks like this:
~~~
(define (gini-index subsets label-column-index)
(for/sum ([subset (in-list subsets)])
(for/sum ([label (in-list (list 0 1))])
(calc-proportion subset
label
label-column-index))))
~~~

## Advertising

I tried some variations of using places without success and then I found:
https://rosettacode.org/wiki/Parallel_calculations#Racket
Where the code is:
~~~
#lang racket
(require math)
(provide main)
(define (smallest-factor n)
(list (first (first (factorize n))) n))
(define numbers
'(112272537195293 112582718962171 112272537095293
115280098190773 115797840077099 1099726829285419))
(define (main)
; create as many instances of Racket as
; there are numbers:
(define ps
(for/list ([_ numbers])
(place ch
(place-channel-put
ch
(smallest-factor
(place-channel-get ch))))))
; send the numbers to the instances:
(map place-channel-put ps numbers)
; get the results and find the maximum:
(argmax first (map place-channel-get ps)))
~~~
So inside the list places are created and it seems that the whole definition of
what they are supposed to do is wrapped in that (place ...) expression. I tried
to do the same for my example:
~~~
(define (gini-index subsets label-column-index)
(for*/list ([subset (in-list subsets)]
[label (in-list (list 0 1))])
(place pch
(place-channel-put pch (list subset label label-column-index))
(let ([data (place-channel-get pch)])
(calc-proportion (first data)
(second data)
(third data))))))
~~~
The `subset` inside `(place-channel-put pch (list subset label
label-column-index))` gets underlined and the error is:
subset: identifier used out of context
(I) In the example from Rosetta code it is all easy, as here is only passed one
number and is does not need a name or anything, but in my example I am not sure
how to do it.
(II) A second thing I tried to do was using a place more than once (put, get
then put get to the channel again), but it did not work and my program simply
did nothing anymore, no cpu load or anything, but also did not finish, probably
waiting for an answer from the place and never getting any. Is it in general
not possible to use a place more than once?
--
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.