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 Subject: Re: fibers,questions about thread id and mutation of vectors Date: Fri, 6 Jan 2023 18:06:19 +0100 Message-ID: References: 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="8936"; mail-complaints-to="usenet@ciao.gmane.io" To: guile-user Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Fri Jan 06 18:07:05 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 1pDqBN-00027j-Gi for guile-user@m.gmane-mx.org; Fri, 06 Jan 2023 18:07:05 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pDqAz-00087v-Nb; Fri, 06 Jan 2023 12:06:41 -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 1pDqAw-00086W-Cx for guile-user@gnu.org; Fri, 06 Jan 2023 12:06:38 -0500 Original-Received: from mail-ej1-x62b.google.com ([2a00:1450:4864:20::62b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pDqAt-0005W5-1e for guile-user@gnu.org; Fri, 06 Jan 2023 12:06:37 -0500 Original-Received: by mail-ej1-x62b.google.com with SMTP id u9so4893096ejo.0 for ; Fri, 06 Jan 2023 09:06:32 -0800 (PST) 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=K6mInOF4a/hfO5O1tRlXPXeCeDCOCn4SLAxeRURp7MY=; b=c4xphl3dhdtAvUjegLi0i1cOeJYnm8KY2wEqXoi6gA/VGQnPC4v/DEnJnBc38MxUhG jhLtDup0RKNYzZ3/RwmBTyDn/doeqmjOCZodtZ7+PbqM+ZqGsaPhW5DBEcYOYLQ3bcDw c5u58NRE7t+/FnQ05JmFovseuLiwIliAH4JOc/ETHOlS2JLpYCLvF3YxrB5hdZ+9juUo eUtsUpWfpB1Flzve2VDn3It0JaBChGIKJPPH8HCSuodSgfp/axgZsFD20ZSDD/8wWeIm aZFNlM8OhHRxRUBn/s9GmVgm3lcdwmmgc9iGMprh23FT+cmc3cz8NDtiawd3UrrBMF3M qNsg== 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=K6mInOF4a/hfO5O1tRlXPXeCeDCOCn4SLAxeRURp7MY=; b=KjNw3IuIfKtWPAteiaV1gIEZkYhlWl89uYaY/PbqWbn6DXzePLdKH8CnSx0hC5OtOl D5ihYh9GOTNj+1vzGfwVxfC42tgWJmtE0qanEXVaS/Q9l5AvE8qH14zgmIUNdyZ4OzD7 Wqr86kYL2erlkO+WFhluNL+Rq67Z7dka0MQ/yLC7x2gR53tM8wesF9OrN3WLuBZtJDzh ac04hwGJilZELlJwM2g5S1Z0Cg5ZFvRsibJJdTRCi0RVBwDSdQw4GSl3qzRwGLHfZzJo O/VaGRNE0LONmMlElS9hg5Zo1dvEUU/KEXu3tSEcSMz5JqZIxpPSUDcqyWOpKBNfmJyR Ki/Q== X-Gm-Message-State: AFqh2kpoKrpStDXgV/avnZiXkEk/K629nhk+kC36lGDVSad4k6H9ZvpL h495S03zXHfGga+HTmgBktv/xnPY62WbfvlQxL9Ose/NyQ8= X-Google-Smtp-Source: AMrXdXsX4kma+iWcSmibx+YGkdYCer1D/ksR1KF2gQQXsxxJAmfKxhwAKgeMzSExmEQRxOcWFV03xG+XT1ZF06FBZjE= X-Received: by 2002:a17:907:2a0f:b0:7be:39de:9529 with SMTP id fd15-20020a1709072a0f00b007be39de9529mr3333583ejc.539.1673024790910; Fri, 06 Jan 2023 09:06:30 -0800 (PST) In-Reply-To: Received-SPF: pass client-ip=2a00:1450:4864:20::62b; envelope-from=damien.mattei@gmail.com; helo=mail-ej1-x62b.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:18841 Archived-At: when void is not empty , the solution was to replace (list void) with '() :-) (define omp-get-max-threads (pointer->procedure int (dynamic-func "omp_get_max_threads" libomp) '())) On Fri, Jan 6, 2023 at 4:06 PM Damien Mattei wrote: > yes sorry i misunderstand the fiber doc about mutation: > https://github.com/wingo/fibers/wiki/Manual#Mutation > set! and vector-set! are not wrapped.(i imaginate it ...) > > reply continue below: > > On Fri, Jan 6, 2023 at 3:12 PM Maxime Devos > wrote: > >> >> >> On 06-01-2023 11:20, Damien Mattei wrote: >> > Hi, >> > is fibers having a way to know the thread number the code is running? >> > i, mean the equivalent of omp_get_thread_num(); in openMP. >> >> There's (current-thread), but that's just Guile; it's not >> Fibers-specific. It's also not a number. I don't know if it's >> equivalent to omp_get_thread_num. >> > > no it returns something based on address: > scheme@(guile-user)> (current-thread) > $1 = # > the good thing it is that it is different for each address, the bad is > that i do not know how to extract it from the result and anyway i need a > number : 0,1,2,3... ordered and being a partition to make scheduling that > each thread deal with a part of the array (vector) the way it is in OpenMP > like in the FOR example i posted a week ago > >> >> >> > let many thread access a vector >> > without time penalty if the index access are differents? (because if >> index >> > are different there is no real concurrency) >> >> I've heard there is some kind of CPU cache migration penalty when >> mutating and reading nearby regions of memory from different CPUs, but >> that's CPU stuff, not fibers-specific or even Guile-specific stuff. >> > > yes it is true > >> >> Going by your previous question 'does fibers have a way to determine the >> thread is running on', I'm assuming your vector has entries per-thread >> and the fibers modify the per-thread entry (maybe some kind of >> accumulator?). >> >> Regardless of the time penalty, it's probably unsafe, because due to >> scheduling, the thread on which a fiber runs can change over time -- >> between determining the index and writing to the vector, the thread can >> have changed. > > > ! if the code change of thread the organisation of computation is > completely broken > in OpenMP (and GPUs too) a thread keep it jobs until it is finished , data > are sliced between threads at beginning, each thread use its number id to > retrieve and compute the data of the array (array defined in shared memory) > there is no concurrency (unless in cpu cache as you mentioned it but i do > not know how openMP deal with that) as each thread use separate regions of > the array (vector) > >> So you'd have to do 'atomic-box-compare-and-swap!' stuff, >> but then you have a time penalty. Or use 'call-with-blocked-asyncs' >> appropriately to temporarily block preemption. >> >> Anyway, this reads as an 'XY problem' >> ( >> https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem/66378#66378); >> >> instead of asking about your attempted solution, could you say what >> problem you are trying to solve? >> > > just do a 'for like in openMP (mentioned above) > i undertand fibers is better for scheduling web server request but not for > parallelizing like openMP - it is two differents world. > > Regards, > Damien > > note: a little question again: > i try to use > > int omp_get_max_threads(void); > > https://www.openmp.org/spec-html/5.0/openmpsu112.html > > from guile with: > (define libomp (dynamic-link "libomp")) > > (define omp-get-max-threads > (pointer->procedure int > (dynamic-func "omp_get_max_threads" libomp) > (list void))) > > but i get this error: > ice-9/boot-9.scm:1685:16: In procedure raise-exception: > In procedure pointer->procedure: Wrong type argument in position 3: 0 > > i do not understand why. > > >> Greetings, >> Maxime. >> >