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 10:20:19 +0200 Message-ID: References: <87bkqg7lmp.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="24140"; mail-complaints-to="usenet@ciao.gmane.io" To: guile-user , guile-devel Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Thu Oct 13 11:06:10 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 1oiuAL-00064y-5q for guile-user@m.gmane-mx.org; Thu, 13 Oct 2022 11:06:09 +0200 Original-Received: from localhost ([::1]:48570 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oiuAJ-0005kx-KY for guile-user@m.gmane-mx.org; Thu, 13 Oct 2022 05:06:07 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:35272) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oitSH-0000TI-GB; Thu, 13 Oct 2022 04:20:38 -0400 Original-Received: from mail-ed1-x534.google.com ([2a00:1450:4864:20::534]:36654) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oitSF-0002un-4f; Thu, 13 Oct 2022 04:20:37 -0400 Original-Received: by mail-ed1-x534.google.com with SMTP id e18so1559415edj.3; Thu, 13 Oct 2022 01:20:33 -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=TsE80/vCVg2mGQHc6G24izxoUeLTNFqAb/UyWVdHOR0=; b=bxlzpv0vKiA+XuISnsfEuZNagl1Pj25ATGwddyscHU5j9D6s6shWx7i1IM+eYsdeP8 DWYMqaiAWljJ2U6OIq7P11yQ1hu0o3ZZU8fq3S3lrfvceO1DE4whgThU130pVZXl6uAv gIybIHyzdFw/apzwTm0CRBHzJ4Ctl4P5dEPnfswNXTy9KVdN1QIEJMPHd9dDvtpYMDX6 I2x5RsyEkMVaIcTi4jdjzWvcIagbFzF4LHtOQu+FIN8CQpLdrF86hRxoRY7b41N6LBQK 4uuBMjULwcHIt4IYhuKZccHpY3xRHlHrRdcs5KB7cmF7l4yd6EbiHCtDl8uM7n4TJRlu N2Lw== 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=TsE80/vCVg2mGQHc6G24izxoUeLTNFqAb/UyWVdHOR0=; b=K3IjW6FakeOohyReEksgyh1Lr6yFiDsLbTzGCuRSGj5e+s57VBJzoBGKHmBErNbQc3 d7G6RtynWOEbqDgsjLDvcC0LU/HzQ8IbxQf9St7f5GDQ3k5DY5sJI6BfSVgcqcK/vkur pmNQiD8IanQNWfNgneiBkkuXb3wuHEc9VWIhdlHIsWReUW6KeqO0iXKpVYW6UoawS7ez Qh7lu+LngKOgUHAVTC2fg0rEFjAOCR8oVWTY8IAb24zhrKMCX5VbRWd6K952RIsdUTTO eMB95G5KN6XOGjJuBACTYSk8ItEeolFPyjPKqnBQD2F7lYSIuu/2NihSj6ljZl1121MP QBjw== X-Gm-Message-State: ACrzQf1aMm9BRCYHkYvQ5I8anX0XvjM81/eO1mA5X3LIX/YwATX/SQA0 Uj/17EB2DwGPU6vR5q4+s9ScDj5/Ct/vZYkFk9vpVIfzXjs= X-Google-Smtp-Source: AMsMyM7YN3GqK3e05tb/DA49tsiUzIrhnAgHd8Tqxg28P6Jkzqgw9WCse2eY1v5STcAy/N54OHIIpE58iQOLnUT4DV4= X-Received: by 2002:a05:6402:5112:b0:45b:ed74:e13f with SMTP id m18-20020a056402511200b0045bed74e13fmr21255644edd.282.1665649231526; Thu, 13 Oct 2022 01:20:31 -0700 (PDT) In-Reply-To: Received-SPF: pass client-ip=2a00:1450:4864:20::534; envelope-from=damien.mattei@gmail.com; helo=mail-ed1-x534.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:18634 gmane.lisp.guile.devel:21421 Archived-At: ok 'parallelization code and hash table' in google show no real solution, i have another idea,instead of function-unify-two-minterms-and-tag ,just unify the minterms and tag them (which use hash table) later out of the // region, after if it still sucks i will drop list for vectors, making it step by step will show where is the bottleneck, let me just a few time and i will go back to the mailing lists with interesting results i hope.... On Thu, Oct 13, 2022 at 9:40 AM Damien Mattei wrote: > ok , i think the problem comes both from my code and from guile parmap so. > Obviously parmap could be slower on other codes because of the nature of > list i think, it is hard to split a list in sublist and send them to thread > and after redo a single list, i better use vector. > As mentioned and forget by me, i apologize, i use an hash table which is a > global variable and mutex can be set on it , no dead lock , here but it > slow down the code than it is dead for speed , but not locked. > > The examples given are good but i do not want to write long and specific > code for //, for // must a ssimple as OpenMP directives (on arrays) not be > a pain in the ass like things i already did at work with GPUs in C or > Fortran,that's nightmare and i do not want to have this in functional > programming. > > ok i will try to modify the code but i do not think there is easy solution > to replace the hash table, any structure i would use would be global and > the problem (this function is not pure, it does a side-effect),at the end i > do not think this code could be // but i'm not a specialist of //. I think > this is a parallelization problem, how can we deal with a global variable > such as an hash table? > > On Wed, Oct 12, 2022 at 11:55 PM Olivier Dion > wrote: > >> On Wed, 12 Oct 2022, Damien Mattei 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 >> >