From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ua1-f43.google.com (mail-ua1-f43.google.com [209.85.222.43]) by sourceware.org (Postfix) with ESMTPS id 894D6385E02D for ; Tue, 4 Jul 2023 15:23:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 894D6385E02D Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=carnegiescience.edu Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ua1-f43.google.com with SMTP id a1e0cc1a2514c-79492b8f4bbso1084752241.2 for ; Tue, 04 Jul 2023 08:23:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688484227; x=1691076227; 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=YDpnfld0zwBcRDXZTbSOFn0+lc1bTCQXmorVEbvrDfo=; b=V8CMgLIQqSP1WIazK7R2Ieiky1FLwsgI4lFUtFIwIc/nrgNCnM60rx/ruMVfPVj8mL LdtRG/QK6KR+RTH24Jvv7YngTartis27Hik82RFvKmxMD1Sx6yeTOYdeb3gT0BfCiT4H oPPGhgAgGg0OKZTVTeYosSjapYptds3rmHF6hzahY/P234WbHLiJn/Z+Q9sAmsbAAy0m zooAb4uBDRQdgzlFtgkSF39Vn/cNmSAcJJMLbvopbloS8mWsNjnG5qOuud8/KL28KVm9 yh6ZLPyDFFCXcesQgf+6Q7UzFs1mpPQN10RdwOGttONPp5eHO5jmbF5vXy0TZ+GmOMxn hozw== X-Gm-Message-State: ABy/qLaAjNVKmejE9x7Q6sgN9pz5+6pCKLYQg9MWHKBYLqgXlWAWf7gq B6Ol5urRR8NlDj0HPrZ9dTkKU1KkFQg= X-Google-Smtp-Source: APBJJlF/fDAD+u6CEOMSZ/CzTTPmp0wMDlitIurgg8QQ/Wyt7sIFqTRzBwyOaPQhDUex2A7CiEqUiA== X-Received: by 2002:ac5:cdc6:0:b0:471:b985:9d2c with SMTP id u6-20020ac5cdc6000000b00471b9859d2cmr6153831vkn.4.1688484226568; Tue, 04 Jul 2023 08:23:46 -0700 (PDT) Received: from mail-vk1-f178.google.com (mail-vk1-f178.google.com. [209.85.221.178]) by smtp.gmail.com with ESMTPSA id t68-20020a1f2d47000000b0045af2062ecasm3611279vkt.56.2023.07.04.08.23.46 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 04 Jul 2023 08:23:46 -0700 (PDT) Received: by mail-vk1-f178.google.com with SMTP id 71dfb90a1353d-47191280066so1675365e0c.2 for ; Tue, 04 Jul 2023 08:23:46 -0700 (PDT) X-Received: by 2002:a1f:bdc8:0:b0:471:5427:39a4 with SMTP id n191-20020a1fbdc8000000b00471542739a4mr6345415vkf.0.1688484226184; Tue, 04 Jul 2023 08:23:46 -0700 (PDT) MIME-Version: 1.0 References: <6924139.eB1hRhsCpy@abensonca-precision-7540> In-Reply-To: <6924139.eB1hRhsCpy@abensonca-precision-7540> From: Andrew Benson Date: Tue, 4 Jul 2023 08:23:34 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: Possible problems with OpenMP task parallelism To: gfortran Cc: Andrew Benson Content-Type: multipart/alternative; boundary="00000000000082be7605ffaade77" X-Spam-Status: No, score=-0.4 required=5.0 tests=BAYES_00,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,HTML_MESSAGE,KAM_DMARC_STATUS,KAM_SHORT,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE,URI_DOTEDU autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: --00000000000082be7605ffaade77 Content-Type: text/plain; charset="UTF-8" I've opened PRs for both of these issues: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110547 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110548 -Andrew -- * Andrew Benson: http://users.obs.carnegiescience.edu/abenson * Galacticus: https://github.com/galacticusorg/galacticus On Wed, Jun 28, 2023, 5:01 PM Andrew Benson wrote: > I've been starting to try using OpenMP task parallelism, but I'm running > into > some issues. I'm not sufficiently experienced with task parallelism in > OpenMP > to know if I'm misunderstanding how it should work, or if there's a > compiler > bug. > > Here's an example code (highly simplified from the actual code I'm working > on): > > module taskerMod > > type :: tasker > integer :: depth=-1 > contains > final :: taskerDestruct > procedure :: compute => taskerCompute > end type tasker > > contains > > subroutine taskerDestruct(self) > !$ use :: OMP_Lib > > > > implicit none > type(tasker), intent(inout) :: self > > write (0,*) "DESTRUCT FROM DEPTH ",self%depth !$ ," : > ",omp_get_thread_num() > > > return > end subroutine taskerDestruct > > recursive subroutine taskerCompute(self) > !$ use :: OMP_Lib > > > > implicit none > class(tasker), intent(inout) :: self > > !$omp atomic > self%depth=self%depth+1 > write (0,*) "DEPTH ",self%depth !$ ," : ",omp_get_thread_num() > > > if (self%depth < 3) then > !$omp task untied > > > call self%compute() > !$omp end task > > > > end if > return > end subroutine taskerCompute > > end module taskerMod > > program testTasks > use :: taskerMod > implicit none > type(tasker) :: tasker_ > > tasker_=tasker(0) > !$omp parallel > > > !$omp single > > > !$omp taskgroup > > > > !$omp task untied > > > > call tasker_%compute() > !$omp end task > > > !$omp end taskgroup > > > > !$omp end single > > > !$omp end parallel > > > end program testTasks > > Compiling without OpenMP results in the expected behavior: > $ gfortran test.F90 > $ ./a.out > DESTRUCT FROM DEPTH -1 > DEPTH 1 > DEPTH 2 > DEPTH 3 > > There's a call to the finalizer for the tasker class (on assignment), and > then > it simply reports the 3 levels of recursion that I've set it to go through. > > But, if I compile with OpenMP and run just a single thread (the same > problem > occurs with multiple threads also): > $ gfortran test.F90 -fopenmp > $ ./a.out > DESTRUCT FROM DEPTH -1 > DEPTH 1 > DEPTH 2 > DESTRUCT FROM DEPTH 2 > DEPTH 3 > DESTRUCT FROM DEPTH 3 > > I now see calls to the finalizer from the 2nd and 3rd recursive calls to > the > taskerCompute function. Since self is intent(inout) to this function I > wouldn't expect it to be finalized. But, this is where I doubt my > understanding of how tasks should behave. > > This happens with versions 12.0.0, 13.0.1, and the current HEAD of the GCC > git > repo. But, ifort, does not produce the extra finalizer calls when used to > compile the above with OpenMP. > > Does anyone have any insights into whether or not the finalizer should be > called in this situation? > > Another issue I find with a modified version of the above: > > module taskerMod > > type :: helper > end type helper > > type :: tasker > integer :: depth=-1 > contains > final :: taskerDestruct > procedure :: compute => taskerCompute > end type tasker > > contains > > subroutine taskerDestruct(self) > !$ use :: OMP_Lib > > > > implicit none > type(tasker), intent(inout) :: self > > write (0,*) "DESTRUCT FROM DEPTH ",self%depth !$ ," : > ",omp_get_thread_num() > > > return > end subroutine taskerDestruct > > recursive subroutine taskerCompute(self,helper_) > !$ use :: OMP_Lib > > > > implicit none > class(tasker), intent(inout) :: self > class(helper), intent(inout), optional :: helper_ > > !$omp atomic > > > self%depth=self%depth+1 > write (0,*) "DEPTH ",self%depth !$ ," : ",omp_get_thread_num() > > > if (self%depth < 3) then > !$omp task untied > > > call self%compute(helper_) > !$omp end task > > > > end if > return > end subroutine taskerCompute > > end module taskerMod > > program testTasks > use :: taskerMod > implicit none > type(tasker) :: tasker_ > type(helper) :: helper_ > > tasker_=tasker(0) > !$omp parallel > > > !$omp single > > > !$omp taskgroup > > > > !$omp task untied > > > > call tasker_%compute() > !$omp end task > > > !$omp end taskgroup > > > > !$omp end single > > > !$omp end parallel > > > end program testTasks > > This one causes a segfault: > $ gfortran test1.F90 -fopenmp > $ ./a.out > DESTRUCT FROM DEPTH -1 > DEPTH 1 > > Program received signal SIGSEGV: Segmentation fault - invalid memory > reference. > > Backtrace for this error: > #0 0x2ac99289a1ef in ??? > #1 0x401840 in ??? > #2 0x2ac9925a9606 in GOMP_task > at ../../../gcc-git/libgomp/task.c:644 > #3 0x401588 in ??? > #4 0x40197b in ??? > #5 0x2ac9925a77a4 in gomp_barrier_handle_tasks > at ../../../gcc-git/libgomp/task.c:1650 > #6 0x2ac9925b058f in gomp_team_barrier_wait_end > at ../../../gcc-git/libgomp/config/linux/bar.c:116 > #7 0x2ac9925aeffc in gomp_team_end > at ../../../gcc-git/libgomp/team.c:956 > #8 0x401692 in ??? > #9 0x4016cd in ??? > #10 0x2ac992886d0c in ??? > #11 0x401128 in ??? > Segmentation fault > > This appears to be due to the optional argument, helper_. If it is present > in > the initial call, i.e.: > call tasker_%compute(helper_) > > then this runs without a segfault. > > -Andrew > > -- > > * Andrew Benson: https://abensonca.github.io > > * Galacticus: https://github.com/galacticusorg/galacticus > > > > --00000000000082be7605ffaade77--