unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Maxime Devos <maximedevos@telenet.be>
To: Damien Mattei <damien.mattei@gmail.com>
Cc: guile-user <guile-user@gnu.org>
Subject: Re: fibers,questions about thread id and mutation of vectors
Date: Fri, 6 Jan 2023 18:06:39 +0100	[thread overview]
Message-ID: <97b66c92-d969-a5d1-7371-1ea4a66a0063@telenet.be> (raw)
In-Reply-To: <CADEOadfJMG4rM1c=UcK+2+HJFx0WthZM1cXE3qX4P-+v_nOkgQ@mail.gmail.com>


[-- Attachment #1.1.1: Type: text/plain, Size: 2426 bytes --]

> 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 #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 929 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 236 bytes --]

  parent reply	other threads:[~2023-01-06 17:06 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-06 10:20 fibers,questions about thread id and mutation of vectors Damien Mattei
2023-01-06 14:12 ` Maxime Devos
2023-01-06 15:06   ` Damien Mattei
2023-01-06 17:06     ` Damien Mattei
2023-01-06 17:06     ` Maxime Devos [this message]
2023-01-13 11:10       ` Damien Mattei
2023-01-13 12:23         ` Maxime Devos
2023-01-17  9:42           ` Damien Mattei

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=97b66c92-d969-a5d1-7371-1ea4a66a0063@telenet.be \
    --to=maximedevos@telenet.be \
    --cc=damien.mattei@gmail.com \
    --cc=guile-user@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).