[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: map-par slower than map
From: |
Damien Mattei |
Subject: |
Re: map-par slower than map |
Date: |
Thu, 13 Oct 2022 16:21:02 +0200 |
ok i have the proof, this time (second time) the process stopped itself on
your example ("processus stoppé " in french) :
mattei@pc-mattei:~/Dropbox/git/library-FunctProg$ guile
GNU Guile 3.0.1
Copyright (C) 1995-2020 Free Software Foundation, Inc.
Guile comes with ABSOLUTELY NO WARRANTY; for details type `,show w'.
This program is free software, and you are welcome to redistribute it
under certain conditions; type `,show c' for details.
Enter `,help' for help.
scheme@(guile-user)> (use-modules (srfi srfi-1) (ice-9 threads))
scheme@(guile-user)> (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))))
scheme@(guile-user)> (define v (list->vector (iota 100000000) ))
scheme@(guile-user)> (define r (par-map-vector sqrt v))
scheme@(guile-user)> (define v (list->vector (iota 100000000) ))
scheme@(guile-user)> (define r (par-map-vector sqrt v))
Processus arrêté
the first time is ok but the second time, Guile quit to the terminal.
seems something makes the guile system instable after one run,
i test it out of my program and out of my Scheme+
but my .guile is in this directory like that:
; Guile config file
;; history
(use-modules (ice-9 readline)
(ice-9 history)
(srfi srfi-43) ;; vector
;; guile object oriented programming system
(oop goops)
(oop goops describe))
(activate-readline)
;;(disable-value-history!)
;; curly infix as in srfi-105
(read-enable 'curly-infix)
;; set current path in load path
(set! %load-path (reverse (cons "." (reverse %load-path))))
;; other solution is to put this in shell:
;; export GUILE_LOAD_PATH="...:."
On Thu, Oct 13, 2022 at 4:10 PM Damien Mattei <damien.mattei@gmail.com>
wrote:
>
>
> On Thu, Oct 13, 2022 at 4:06 PM Olivier Dion <olivier.dion@polymtl.ca>
> wrote:
>
>> On Thu, 13 Oct 2022, Damien Mattei <damien.mattei@gmail.com> wrote:
>> > i do not see what has changed in your code ?
>>
>> Just copy it. Trust me it has changed.
>>
> really ? :-) i read it 3 times line by line, yes the end is cut ,still no
> ending ) and i use it and freeze,crash or ok randomly, the first times it
> works but try 4 or 5 examples.... :-(
>
>>
>> > really strange,even with bad code the moment it crash should be the
>> same,
>> > sometimes works,crash or freeze....
>>
>> I don't get any of these problem .. running with (iota 100000000) I
>> don't see any synchornization issue also.
>>
>> --
>> Olivier Dion
>> oldiob.dev
>>
>
- Re: map-par slower than map, (continued)
- Re: map-par slower than map, Damien Mattei, 2022/10/13
- Re: map-par slower than map, Olivier Dion, 2022/10/13
- Message not available
- Fwd: map-par slower than map, Damien Mattei, 2022/10/13
- Re: map-par slower than map, Damien Mattei, 2022/10/13
- Re: map-par slower than map, Olivier Dion, 2022/10/13
- Re: map-par slower than map, Damien Mattei, 2022/10/13
- Re: map-par slower than map, Olivier Dion, 2022/10/13
- Re: map-par slower than map, Damien Mattei, 2022/10/13
- Re: map-par slower than map,
Damien Mattei <=