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 15:43:46 +0200 Message-ID: References: <87bkqg7lmp.fsf@laura> <8735bs6lac.fsf@laura> <87zgdz6glm.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="33696"; mail-complaints-to="usenet@ciao.gmane.io" Cc: guile-user , guile-devel To: Olivier Dion Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Thu Oct 13 15:56:23 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 1oiyhC-0008YR-Tb for guile-user@m.gmane-mx.org; Thu, 13 Oct 2022 15:56:22 +0200 Original-Received: from localhost ([::1]:59886 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oiyhB-0003OX-NV for guile-user@m.gmane-mx.org; Thu, 13 Oct 2022 09:56:21 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:37310) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oiyVP-00082F-Sm; Thu, 13 Oct 2022 09:44:14 -0400 Original-Received: from mail-ej1-x629.google.com ([2a00:1450:4864:20::629]:45828) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oiyVM-0007qM-4l; Thu, 13 Oct 2022 09:44:10 -0400 Original-Received: by mail-ej1-x629.google.com with SMTP id sc25so3966296ejc.12; Thu, 13 Oct 2022 06:43:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=8CpO0kiu8Sxa5PaB6vOegystaUKeojfmxZYaI0PT6QM=; b=MdamZ/kPcu2ODQSg+i0cS0WobIDqnTSIfcEX2SEaKotPAVOvfEvAkjtSBIYAGrp8jd doACjSSxJxAXXcwopI2Og2RYwxT64rZwK7u4H+FK7rsMBLjWWlK+ByKzdZICDJ8FT/xW Lppp6VZ5UxRRY4Swo+1nBTVLOET4kS22X7ObUorc1MlBBkEiE+UHYQ8AN+NOCm/hdkU5 ENeB7Zih+JYyt70T0xsm1k0sdoG+rsMtDyLtt6EqWPYRY8+XPYcOp2TaJ41KIAcAvfuV NL0YpDEw0ZkjvF2S31h+KjxFMwJlC/D29fXQlEihcQv7lSqqAi4yWuFI3G9ahxJrSw47 FcNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc: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=8CpO0kiu8Sxa5PaB6vOegystaUKeojfmxZYaI0PT6QM=; b=jt3HPrJtORFAi84QINQaHGZSr/DU5mj+ZG+9jfiUYcRAFzPFgyVP2L+5kHjvwJUWcR xZ75glaM56cTH4nRmCb/M7eoIteGRrjyPDgPEv1Uhf4Arz7tnvUaDMpGKIL/qRGA2Z1n OJ1cQc6rcMYADHB6HXUk9HZRc80LWHjT/MCzh6xdvuH3W0nF07mTck5eoEt6zzHqQktp cIdsrmiTY3GK9TC/Xs6L6Ml0ywZkp5haZ1MMMYKD8Vj/Z6AjBUWz1Fn3nBV+pNGo+QxX QIR5iie2cjz03+60Dh7arq1h5PzM8H1mHLxNyKWVo9zn6QT75L5MPAA0xzBhhFgaISy0 Ks6w== X-Gm-Message-State: ACrzQf3VDFVRuHOn0kRXaJWX+pTDtkD7hhCamiejvbAo13PJmLV88fhr p/qKqmO/veTb64nwiBxO6omx3ZJhuxWvSIii8Ds= X-Google-Smtp-Source: AMsMyM7RcO+eMQdkULNOlE5SAkNKhEjY/LeE/yflStBTHCWfJhvfNDEXNdCGyAPud1/QAZle95Gee906n7GR853D/Gk= X-Received: by 2002:a17:906:5d16:b0:787:a9ee:3c9c with SMTP id g22-20020a1709065d1600b00787a9ee3c9cmr26823241ejt.467.1665668637682; Thu, 13 Oct 2022 06:43:57 -0700 (PDT) In-Reply-To: <87zgdz6glm.fsf@laura> Received-SPF: pass client-ip=2a00:1450:4864:20::629; envelope-from=damien.mattei@gmail.com; helo=mail-ej1-x629.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:18642 gmane.lisp.guile.devel:21430 Archived-At: i do not see what has changed in your code ? really strange,even with bad code the moment it crash should be the same, sometimes works,crash or freeze.... On Thu, Oct 13, 2022 at 2:41 PM Olivier Dion wrote: > On Thu, 13 Oct 2022, Damien Mattei wrote: > > the code did not worked when data length were more little than number of > > cpus (6 on my host) (iota 5) returns #unsepcified: > > Yeah sorry I miss indended the output and the rest. Here's a version > that should work: > --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 >