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: fibers,questions about thread id and mutation of vectors Date: Tue, 17 Jan 2023 10:42:33 +0100 Message-ID: References: <97b66c92-d969-a5d1-7371-1ea4a66a0063@telenet.be> 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="16959"; mail-complaints-to="usenet@ciao.gmane.io" Cc: guile-user , guile-devel To: Maxime Devos Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Tue Jan 17 10:44:08 2023 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 1pHiVh-00046y-Gu for guile-user@m.gmane-mx.org; Tue, 17 Jan 2023 10:44:05 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pHiUg-0007td-QK; Tue, 17 Jan 2023 04:43:02 -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 1pHiUY-0007mb-0F; Tue, 17 Jan 2023 04:42:58 -0500 Original-Received: from mail-ej1-x634.google.com ([2a00:1450:4864:20::634]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pHiUS-000594-2i; Tue, 17 Jan 2023 04:42:53 -0500 Original-Received: by mail-ej1-x634.google.com with SMTP id mp20so27382954ejc.7; Tue, 17 Jan 2023 01:42:45 -0800 (PST) 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=na95HM74d/51CupDUotrmMYVwcK4ctHgyUBz4j2LS8A=; b=nqN0C96LZzVsqtyqW1qqSScY4XwuRA6Sx4XrKFH3otG/yjMWPfvEumNUq8VrTQ7ACU bla93uBjuM0igPEYWqy4lXfFDLW+Zi+BkHtKgMXTXcFXDplczZui0sKV1CyxcNkNqLky i5IQgx/xANknFwzY7L0cmpnPNaXZXZfThZWqe1aMO5clv6kDqX9ezV4h04MMK9JNQAzY XbbKkJ+Ej7tnsN+DOAfqMOaCLkEZZPuVJfzs1wcA63JzLpxB/xa3RyWu0HuxOyvuV4k3 Y4H4nXi8D+gtnmWBTBVSsw3eO4/aoDkC24l0NYECJfLL6OagbwCkxvTg3Xz2DzsYQkwX 397w== 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=na95HM74d/51CupDUotrmMYVwcK4ctHgyUBz4j2LS8A=; b=r0hx7U1lbn6JkAzfKaDyI87GPU9u5pxD5L4R5XIHl+hLPRL7ZgVVlqPBbTqonVaTKx kUFYS5a6YGI/N6RmUmYR4Bi0bezmdjFdOCw/Ga6fkrDdx/DdJaXi355JTqwGnq8H9Fj2 GWt2ocKFgeO8VLmq/3T9KntcHnde50mOi8nkXq/EZSKrnxoVRbwFLcMhRR4dIp7wBO+n mdKRk4VkGPE3nRpUDsDDil6UAi7fAJF1U/6TA+epiGwm0DULclPqIy7aizAxoZdw26fg DUWwYpuxMQHlAkJUMKkglDuSeNYXPkNNo+5Lj4YwGqBjlPgD3bWoCkO2NB3jqkcwj63X pCrg== X-Gm-Message-State: AFqh2kpzyiTzS+m322Mf6xXH7X4Ou8WZRaG9+bnAc10k8a6cn5XiJwe2 SpgrEfUDwBtsBMK33kytntKxrLcvLI6pMSh/nJFn0YQC+YM= X-Google-Smtp-Source: AMrXdXuXmwR4azBsUtR16OQroAMHEHNRAPPIPq5LJpsOOVoHRtORWh39wvoxydKdxNiWjkyWg2IHqq3jLpqsJk0IrnQ= X-Received: by 2002:a17:906:abc6:b0:7c1:71ba:9759 with SMTP id kq6-20020a170906abc600b007c171ba9759mr148179ejb.770.1673948564283; Tue, 17 Jan 2023 01:42:44 -0800 (PST) In-Reply-To: Received-SPF: pass client-ip=2a00:1450:4864:20::634; envelope-from=damien.mattei@gmail.com; helo=mail-ej1-x634.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-bounces+guile-user=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.lisp.guile.user:18871 gmane.lisp.guile.devel:21593 Archived-At: Hello Maxime, it runs in the fastest way with your idea, as you said it scm_init_guile() is only needed once by thread. On Fri, Jan 13, 2023 at 1:23 PM Maxime Devos wrote: > > for (i=start; i<=stop; i++) { /* i is private by default */ > > > > scm_init_guile(); > > scm_call_1( func , scm_from_int(i) ); > > IIUC, you are calling scm_init_guile once per index, whereas calling it > yes openMP slice a 1 to N for loop in N/number_of_cpus segments of normal C for loop but run one loop per CPUs so if you do a 'top' command on a C openMP code you will see a load of number_of_cpus*100% for example with 12 cpus top will then display a load for your program of 1200% furthermore if you hit the 1 key you would see in top the load of each CPU (100% each) the same options does not exist with 'top' of BSD like Mac OS. OpenMP do a partition of N and run exactly each part on one thread ,each thread on a different CPU or core, i think it is the only library that can do that , OpenMP is written very near of the compiler and LLVM. In general there is a Master thread and slave threads or you can run a special code only on the first thread to fork (master one or the first to launch) and friday unfortunately i tried the single pragma: https://www.openmp.org/spec-html/5.0/openmpsu38.html but that can not help becaus it run only on the first thread. a solution of the problem could be this one: Executing Code Once Per Thread in an OpenMP Loop https://www.openmp.org/spec-html/5.0/openmpsu38.html but it is (Visual C++) and even with g++ this would be not compatible. so i use a basic C solution with static and array that keep in memory if the scm_init_guile() as already been launch for the current thread the code is running now. I also put omp_get_max_threads() in a static var as openmp() is called many times in my codes and the number of available hardware cpus would change never. the code is here: https://github.com/damien-mattei/library-FunctProg/blob/master/guile-openMP.c unfortunately i find no real speed up, i understood that the only reason of speed up was because the C 'for loop is much faster than the Scheme 'for ones. For this concclusion i compared Scheme and C openmp and C without openMP and in C i got exactly the same time results: Scheme: ... [output cut] Chrono START number: 165 minterms-vector-length = 10944. chrono STOP : elapsedTime = 36.219 ms.totalComputationTime =485311.94 Chrono START number: 166 minterms-vector-length = 12008. chrono STOP : elapsedTime = 39.82 ms.totalComputationTime =485351.76 Chrono START number: 167 minterms-vector-length = 342. chrono STOP : elapsedTime = 1.215 ms.totalComputationTime =485352.97500000003 Scheme with OpenMP call: ...[output cut] Chrono START number: 165 minterms-vector-length = 10944. chrono STOP : elapsedTime = 35.039 ms.Open MP totalComputationTime =385444.1410000001 Chrono START number: 166 minterms-vector-length = 12008. chrono STOP : elapsedTime = 37.792 ms.Open MP totalComputationTime =385481.93300000014 Chrono START number: 167 minterms-vector-length = 342. chrono STOP : elapsedTime = 1.163 ms.Open MP totalComputationTime =385483.09600000014 Scheme with C 'for loop call: ...[output cut] Chrono START number: 165 minterms-vector-length = 10944. chrono STOP : elapsedTime = 33.104 ms.For Funct totalComputationTime =385543.4700000001 Chrono START number: 166 minterms-vector-length = 12008. chrono STOP : elapsedTime = 35.938 ms.For Funct totalComputationTime =385579.4080000001 Chrono START number: 167 minterms-vector-length = 342. chrono STOP : elapsedTime = 1.165 ms.For Funct totalComputationTime =385580.5730000001 on the C codes (// openmp and sequenctial for) the result is almost the same : totalComputationTime =385580.5730000001 ms totalComputationTime =385483.09600000014 ms =385 s i suppose openMP works well by slicing on many processors but the scm_call_1( func , scm_from_int(i) ); works all on the same thread that host the Guile interpreter. Solution would be to have many Guile interpreter running but i do not know how doing that from the C code with OpenMP. Damien note : i did time measure both in C and Scheme with gettimeofday code to compare both 100% scheme code and mixed one: https://github.com/damien-mattei/library-FunctProg/blob/master/guile/logiki%2B.scm#L3500