guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: fibers,questions about thread id and mutation of vectors


From: Maxime Devos
Subject: Re: fibers,questions about thread id and mutation of vectors
Date: Fri, 6 Jan 2023 18:06:39 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.5.1

no it returns something based on address:
scheme@(guile-user)> (current-thread)
$1 = #<thread 8814535936 (102a61d80)>
the good thing it is that it is different for each address, the bad is that i 
do not know how to extract it from the result and anyway i need a number : 
0,1,2,3... ordered and  being a partition to make scheduling that each thread 
deal with a part of the array (vector) the way it is in OpenMP like in the FOR 
example i posted a week ago

You could define a (weak key) hash table from threads to numbers, and whenever a thread is encountered that isn't yet in the table, assign it an unused number and insert it in the table. Requires locking (or an atomics equivalent) though, so not ideal.

(Maybe there's a method to get a number, directly, but I don't know any.)

just do a 'for like in openMP (mentioned above)

In that case, when implementing slicing the array between different new fibers, you can give each of the fibers you spawn (one fiber per slice, if I understand the terminology correctly) an entry in the vector, and after all the fibers complete do the usual 'sum/multiply/... all entries' trick.

As each fiber has its own (independent) storage, not touched by the other fibers, that should be safe.

I suppose this might take more memory storage than with openMP.

i undertand fibers is better for scheduling web server request but not for 
parallelizing like openMP - it is two differents world.

You can do parallelisation with fibers (see ‘In that case, when implementing slicing ...’), but from what I'm reading, it will be somewhat unlike openMP.

On 06-01-2023 16:06, Damien Mattei wrote:

(define omp-get-max-threads
   (pointer->procedure int
                       (dynamic-func "omp_get_max_threads" libomp)
                       (list void)))

but i get this error:
ice-9/boot-9.scm:1685:16: In procedure raise-exception:
In procedure pointer->procedure: Wrong type argument in position 3: 0

i do not understand why.


‘int omp_get_max_thread(void);’ is C's way to declare that omp_get_max_thread has no arguments -- there is no 'void'-typed argument.

Try (untested):

(define omp-get-max-threads
  (pointer->procedure int
                      (dynamic-func "omp_get_max_threads" libomp)
                      (list)))

Greetings,
Maxime.

Attachment: OpenPGP_0x49E3EE22191725EE.asc
Description: OpenPGP public key

Attachment: OpenPGP_signature
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]