From: Olivier Dion via "Developers list for Guile, the GNU extensibility library" <guile-devel@gnu.org>
To: Damien Mattei <damien.mattei@gmail.com>,
guile-user <guile-user@gnu.org>,
guile-devel <guile-devel@gnu.org>
Subject: Re: map-par slower than map
Date: Wed, 12 Oct 2022 17:55:10 -0400 [thread overview]
Message-ID: <87bkqg7lmp.fsf@laura> (raw)
In-Reply-To: <CADEOadfKc-WvKz-1zLbKAuvmK9j2MgRYMhZA2a0_2RZbOKCOKg@mail.gmail.com>
On Wed, 12 Oct 2022, Damien Mattei <damien.mattei@gmail.com> wrote:
> Hello,
> all is in the title, i test on a approximately 30000 element list , i got
> 9s with map and 3min 30s with par-map on exactly the same piece of
> code!?
I can only speculate here. But trying with a very simple example here:
--8<---------------cut here---------------start------------->8---
(use-modules (statprof))
(statprof (lambda () (par-map 1+ (iota 300000))))
--8<---------------cut here---------------end--------------->8---
Performance are terrible. I don't know how par-map is implemented, but
if it does 1 element static scheduling -- which it probably does because
you pass a linked list and not a vector -- then yeah you can assure that
thing will be very slow.
You're probably better off with dynamic scheduling with vectors. Here's
a quick snippet I made for static scheduling but with vectors. Feel
free to roll your own.
--8<---------------cut here---------------start------------->8---
(use-modules
(srfi srfi-1)
(ice-9 threads))
(define* (par-map-vector proc input
#:optional
(max-thread (current-processor-count)))
(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))
--8<---------------cut here---------------end--------------->8---
--
Olivier Dion
oldiob.dev
next prev parent reply other threads:[~2022-10-12 21:55 UTC|newest]
Thread overview: 27+ 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-25 9:07 ` Mikael Djurfeldt
2022-10-25 9:11 ` Mikael Djurfeldt
2022-10-25 14:09 ` 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 [this message]
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
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=87bkqg7lmp.fsf@laura \
--to=guile-devel@gnu.org \
--cc=damien.mattei@gmail.com \
--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).