From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Damien Mattei Newsgroups: gmane.lisp.guile.user,gmane.lisp.guile.devel Subject: Re: map-par slower than map Date: Thu, 13 Oct 2022 14:36:18 +0200 Message-ID: References: <87bkqg7lmp.fsf@laura> <8735bs6lac.fsf@laura> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="29700"; mail-complaints-to="usenet@ciao.gmane.io" To: guile-user , guile-devel , Olivier Dion Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Thu Oct 13 14:41:14 2022 Return-path: Envelope-to: guile-user@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oixWT-0007aE-NL for guile-user@m.gmane-mx.org; Thu, 13 Oct 2022 14:41:13 +0200 Original-Received: from localhost ([::1]:46120 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oixWS-0002bv-4r for guile-user@m.gmane-mx.org; Thu, 13 Oct 2022 08:41:12 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:40290) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oixS0-0000p9-On; Thu, 13 Oct 2022 08:36:37 -0400 Original-Received: from mail-ed1-x536.google.com ([2a00:1450:4864:20::536]:44973) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oixRx-0003kS-09; Thu, 13 Oct 2022 08:36:36 -0400 Original-Received: by mail-ed1-x536.google.com with SMTP id g27so2377185edf.11; Thu, 13 Oct 2022 05:36:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=34oKbhnG1od6+nLQYvkxJ447hfZzQd6BJT5801Au57U=; b=ShykOLwQ1MgmDtJWSTEYQ6ZKpivEeFNFI50q2UMZYpZjTbonGJRW2gKPpmWbDXm4qO 7H+eweZs2ZFeU4i8BMLLsKue04UMGZ72x30AAgGx9aALcuKrH2sSQwB/YDbHHodiunP6 PK0Scd/Bq1Fe8Yg9+jBFnDG5MdWX1kwceIxmaSCOx3LbGq7xM9PsSelBqcGlZX6y/upf B5CRJQdOTeoA4EUxWTWs8SpcjmCWVB3jYvqQEW6nUzqsqbgSMJJvMQblwLCWqatyU3qk do41TXwVakePnzhRpIHvtaAGbcsmPqHP+CDlCPBGzYFLelcr7eJUFlUb8v7RAU3xm3ZH 3EMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=34oKbhnG1od6+nLQYvkxJ447hfZzQd6BJT5801Au57U=; b=kwxQwwV9zkgrhO+NUXm+6odL05O7tvIdWnMVCjwEB6LebmznH4awSizLEPwuQC04wu Ytqj9K4N4vYCi+7uggaaqwts56FmGCBbxeCyoRakdIRurpxr3IBKxIDXfDZZuJ7OkEnn mKSRZpH/mZp4a1OtScfG9+KCqIKBUpoX9Qyvn+EZXOvFc2CY1vzfU/u0foet0Pd3eAYv SzrBFEBzmdM9eCKbCPNSbJtWUjwaPV2MR/yanV0noTw8NtZdub2lmvQJFeoSTMOJgugK ASRBAH/1+obpJSYxzz1SdOCrIGsMbgIIKPOzr+nRaPry42ADgujge9ix0Yra4MR/IixZ utUg== X-Gm-Message-State: ACrzQf028j7oDdm/AS5eKvea5bQ3b3utVSSgG5SiEX2tiYcvZwwTxMsg UxC0Qhfd4IrAnfP/CiWAqCsT4Snr6qsQWNFyT+o7sjVMeXq5aQ== X-Google-Smtp-Source: AMsMyM6QovCEVHwRI9LDhTYQi4AsyPYVzzLwDwKpE4fqS6KWqZDwPsx3hWOW9Rr88P8GGBTN+xREI6T1POkeW9/Bdy4= X-Received: by 2002:a05:6402:5255:b0:459:ebaa:c2b8 with SMTP id t21-20020a056402525500b00459ebaac2b8mr31567529edd.150.1665664590599; Thu, 13 Oct 2022 05:36:30 -0700 (PDT) In-Reply-To: Received-SPF: pass client-ip=2a00:1450:4864:20::536; envelope-from=damien.mattei@gmail.com; helo=mail-ed1-x536.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Original-Sender: "guile-user" Xref: news.gmane.io gmane.lisp.guile.user:18640 gmane.lisp.guile.devel:21427 Archived-At: 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 wrote: > sorry google always do reply to single author... > > ---------- Forwarded message --------- > From: Damien Mattei > Date: Thu, Oct 13, 2022 at 1:56 PM > Subject: Re: map-par slower than map > To: Olivier Dion > > > 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 > wrote: > >> On Thu, 13 Oct 2022, Damien Mattei 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 >> >