From: Damien Mattei <damien.mattei@gmail.com>
To: guile-user <guile-user@gnu.org>,
guile-devel <guile-devel@gnu.org>,
Olivier Dion <olivier.dion@polymtl.ca>
Subject: Re: map-par slower than map
Date: Thu, 13 Oct 2022 14:36:18 +0200 [thread overview]
Message-ID: <CADEOadcnDfLsFFeMayisQsWw3AuvKb+P1GBmgHGUmSHNQ08U9g@mail.gmail.com> (raw)
In-Reply-To: <CADEOadc3+PhPj_UQz18MJCAC-4T7Xm73F9Wv9Kyf_4nmWXcapQ@mail.gmail.com>
the code did not worked when data length were more little than number of
cpus (6 on my host) (iota 5) returns #unsepcified:
scheme@(guile-user)> (use-modules (ice-9 threads))
scheme@(guile-user)> {v <+ (list->vector (iota 5))}
#(0 1 2 3 4)
scheme@(guile-user)> (par-map-vector sqrt v)
scheme@(guile-user)> {v <+ (list->vector (iota 20))}
#(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19)
scheme@(guile-user)> (par-map-vector sqrt v)
#(0 1 1.4142135623730951 1.7320508075688772 2 2.23606797749979
2.449489742783178 2.6457513110645907 2.8284271247461903 3
3.1622776601683795 3.3166247903554 3.4641016151377544 3.605551275463989
3.7416573867739413 3.872983346207417 4 4.123105625617661 4.242640687119285
4.358898943540674)
scheme@(guile-user)> (current-processor-count)
6
scheme@(guile-user)> {v <+ (list->vector (iota 6))}
#(0 1 2 3 4 5)
scheme@(guile-user)> (par-map-vector sqrt v)
#(0 1 1.4142135623730951 1.7320508075688772 2 2.23606797749979)
so i modify it this way:
(define* (par-map-vector proc input
#:optional
(max-thread (current-processor-count)))
(if (< (vector-length input) max-thread)
(list->vector (map proc (vector->list input))) ;; less data than
threads or CPUs
(let* ((block-size (quotient (vector-length input) max-thread))
(rest (remainder (vector-length input) max-thread))
(output (make-vector (vector-length input) #f)))
(when (not (zero? block-size))
(let ((mtx (make-mutex))
(cnd (make-condition-variable))
(n 0))
(fold
(lambda (scale output)
(begin-thread
(let lp ((i 0))
(when (< i block-size)
(let ((i (+ i (* scale block-size))))
(vector-set! output i (proc (vector-ref input i))))
(lp (1+ i))))
(with-mutex mtx
(set! n (1+ n))
(signal-condition-variable cnd)))
output)
output
(iota max-thread))
(with-mutex mtx
(while (not (< n max-thread))
(wait-condition-variable cnd mtx))))
(let ((base (- (vector-length input) rest)))
(let lp ((i 0))
(when (< i rest)
(let ((i (+ i base)))
(vector-set! output i (proc (vector-ref input i))))
(lp (1+ i)))))
output))))
now it works but crash randomly, not even at the same stage, i continue to
test and debug....
On Thu, Oct 13, 2022 at 1:57 PM Damien Mattei <damien.mattei@gmail.com>
wrote:
> sorry google always do reply to single author...
>
> ---------- Forwarded message ---------
> From: Damien Mattei <damien.mattei@gmail.com>
> Date: Thu, Oct 13, 2022 at 1:56 PM
> Subject: Re: map-par slower than map
> To: Olivier Dion <olivier.dion@polymtl.ca>
>
>
> ah just at the end? i had noticed, but i get #unspecifeid ? so my new code
> is not good if your procedure is, i will check it,thanks.
> Damien
>
> On Thu, Oct 13, 2022 at 1:00 PM Olivier Dion <olivier.dion@polymtl.ca>
> wrote:
>
>> On Thu, 13 Oct 2022, Damien Mattei <damien.mattei@gmail.com> wrote:
>> > i trying to use your code but it seems there is a ) mismatch
>> > somewhere?
>>
>> Right there's a missing ')' a the end to close the procedure, sorry
>> about that.
>>
>> --
>> Olivier Dion
>> oldiob.dev
>>
>
next prev parent reply other threads:[~2022-10-13 12:36 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-12 17:19 map-par slower than map Damien Mattei
2022-10-12 18:45 ` Maxime Devos
2022-10-12 20:20 ` Damien Mattei
2022-10-12 20:27 ` Damien Mattei
2022-10-12 21:29 ` Zelphir Kaltstahl
2022-10-14 8:21 ` Damien Mattei
2022-10-14 8:38 ` Zelphir Kaltstahl
2022-10-17 13:17 ` Damien Mattei
2022-10-22 16:01 ` Damien Mattei
2022-10-23 1:06 ` Damien Mattei
2022-10-23 23:18 ` Zelphir Kaltstahl
2022-10-24 3:56 ` Keith Wright
2022-10-24 7:03 ` Zelphir Kaltstahl
2022-10-24 4:39 ` Damien Mattei
2022-10-25 9:07 ` Mikael Djurfeldt
2022-10-25 9:11 ` Mikael Djurfeldt
2022-10-25 14:09 ` Damien Mattei
2022-11-10 10:32 ` Damien Mattei
2022-11-10 10:41 ` Damien Mattei
2022-11-10 10:52 ` Zelphir Kaltstahl
2022-11-10 13:36 ` Damien Mattei
2022-11-10 17:07 ` Olivier Dion via General Guile related discussions
2022-11-11 10:26 ` Damien Mattei
2022-11-11 12:25 ` Zelphir Kaltstahl
2022-11-11 13:36 ` Damien Mattei
2022-11-11 13:37 ` Damien Mattei
2022-11-13 8:23 ` Damien Mattei
2022-10-12 21:44 ` Maxime Devos
2022-10-12 21:55 ` Olivier Dion via Developers list for Guile, the GNU extensibility library
2022-10-13 7:40 ` Damien Mattei
2022-10-13 8:20 ` Damien Mattei
2022-10-13 9:10 ` Olivier Dion via Developers list for Guile, the GNU extensibility library
2022-10-13 10:44 ` Damien Mattei
2022-10-13 11:00 ` Olivier Dion via Developers list for Guile, the GNU extensibility library
[not found] ` <CADEOadfovi8s3OxRcssWOuOW8jjHoL9Z7pD_5FstSm=ZkBHP8g@mail.gmail.com>
2022-10-13 11:57 ` Fwd: " Damien Mattei
2022-10-13 12:36 ` Damien Mattei [this message]
2022-10-13 12:41 ` Olivier Dion via Developers list for Guile, the GNU extensibility library
2022-10-13 13:43 ` Damien Mattei
2022-10-13 14:06 ` Olivier Dion via Developers list for Guile, the GNU extensibility library
2022-10-13 14:10 ` Damien Mattei
2022-10-13 14:21 ` 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=CADEOadcnDfLsFFeMayisQsWw3AuvKb+P1GBmgHGUmSHNQ08U9g@mail.gmail.com \
--to=damien.mattei@gmail.com \
--cc=guile-devel@gnu.org \
--cc=guile-user@gnu.org \
--cc=olivier.dion@polymtl.ca \
/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).