From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Zelphir Kaltstahl Newsgroups: gmane.lisp.guile.user Subject: Re: map-par slower than map Date: Fri, 11 Nov 2022 12:25:53 +0000 Message-ID: References: <5608809c-89a2-118c-5c05-c46ac3a0e21b@posteo.de> <87mt8yoi0u.fsf@laura> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="38903"; mail-complaints-to="usenet@ciao.gmane.io" Cc: guile-user , Olivier Dion To: Damien Mattei Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Fri Nov 11 13:27: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 1otT7m-0009uZ-8p for guile-user@m.gmane-mx.org; Fri, 11 Nov 2022 13:27:10 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1otT6r-0007iq-LM; Fri, 11 Nov 2022 07:26:13 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1otT6p-0007ih-Hk for guile-user@gnu.org; Fri, 11 Nov 2022 07:26:11 -0500 Original-Received: from mout01.posteo.de ([185.67.36.65]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1otT6n-0003EZ-4H for guile-user@gnu.org; Fri, 11 Nov 2022 07:26:11 -0500 Original-Received: from submission (posteo.de [185.67.36.169]) by mout01.posteo.de (Postfix) with ESMTPS id 91E26240026 for ; Fri, 11 Nov 2022 13:25:58 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.de; s=2017; t=1668169560; bh=DDAloT13Vsc7LcU238HVfVhQOsv3EyHdPHs0ldSgP+k=; h=Date:Subject:To:Cc:From:From; b=WN6GjraVv4sCQsl454BgZ4CBCp6DT9nucmpFoh5dZxAi+V19OyJKkmY9E0kVxT0// I4gkNORfH81KA+XaVppOUglukujLWJhT6KHFmk/iB7m0y20UCvA4yaCRLCZujQNunM Fn8yIbCukxJaVqlHDPT6AcPW/xAa2aaNcYuXvfeUKfdVhgUw7dgjBGKhUv1NzirMVZ BGwWE5UINZcw7TDhP71KiPkky07tC3U4BJdsfBua2TaPtgqa73fEnFdB78GWMnELgZ ybMD5YU1O5PU6GiHmT6mivQ9jCNVC29iUcR8lCDCqDcbSTkMUtmq42FPl5MtniFjNX nmG/9kwwk17Eg== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4N7ybk43k8z6tmh; Fri, 11 Nov 2022 13:25:54 +0100 (CET) Content-Language: en-US In-Reply-To: Received-SPF: pass client-ip=185.67.36.65; envelope-from=zelphirkaltstahl@posteo.de; helo=mout01.posteo.de 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, 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-bounces+guile-user=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.lisp.guile.user:18722 Archived-At: Hi! On 11/11/22 11:26, Damien Mattei wrote: > i rewrote a complete threaded routine both with guile and racket creating > threads and waiting they finish : > ;; run the parallel code >   {threads <+ (map (λ (seg) (call-with-new-thread >     (λ () (proc-unify-minterms-seg seg)))) >   segmts)} > >   (nodebug >    (display-nl "waiting for threads to finish...")) > >   ;; wait for threads to finish >   (map (λ (thread) (join-thread thread)) ;;(+ start-time max-sleep))) >        threads) > >  it does not seems to block but it is a bit slower than on a single CPU. > > i have this config: > Puce : Apple M1 >   Nombre total de cœurs : 8 (4 performance et 4 efficacité) > it is better on a single cpu than with all the cores... > > i read all the doc of Posix Thread, i admit Scheme is not C , i read on forums > a few about C and Scheme comparaison. > In any thread local variables should be on the stack of each thread. > The only doubt i have is in Scheme (but the same question exist in C) what > portions of code are or not copied in any thread? for this reason i tried to > encapsulate all the procedures used in // as internals defines in the > procedure passed at call-with-new-thread hoping they are copied in each > threads. I hope the basic scheme procedures are reentrant... > I have no explaination why is it even a bit slower on multiple core than on one. > > Regards, > Damien Note, that threads in Guile and Racket are different: https://docs.racket-lang.org/reference/eval-model.html#%28part._thread-model%29: > Racket supports multiple threads of evaluation. Threads run concurrently, in the sense that one thread can preempt another without its cooperation, but threads currently all run on the same processor (i.e., the same underlying operating system process and thread). https://www.gnu.org/software/guile/manual/html_node/Threads.html: > The procedures below manipulate Guile threads, which are wrappers around the system’s POSIX threads. For application-level parallelism, using higher-level constructs, such as futures, is recommended (see Futures). I believe another word for Racket's threads is "green threads". They are like (more like?) Python threads, and do not run on another core. If you start multiple Racket threads on the same Racket VM, they will run all on the same core. No speedup to be expected, unless you would be waiting for IO or something, if you did not use threads. Racket threads are concurrent, but not parallel. I think Racket's threads' nature is the answer to why it is slower than single threaded execution. Regards, Zelphir -- repositories:https://notabug.org/ZelphirKaltstahl