From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from troutmask.apl.washington.edu (troutmask.apl.washington.edu [128.95.76.21]) by sourceware.org (Postfix) with ESMTPS id B9DCB385800A; Mon, 21 Dec 2020 01:04:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org B9DCB385800A Received: from troutmask.apl.washington.edu (localhost [127.0.0.1]) by troutmask.apl.washington.edu (8.16.1/8.16.1) with ESMTPS id 0BL143V1008298 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Sun, 20 Dec 2020 17:04:03 -0800 (PST) (envelope-from sgk@troutmask.apl.washington.edu) Received: (from sgk@localhost) by troutmask.apl.washington.edu (8.16.1/8.16.1/Submit) id 0BL1430v008297; Sun, 20 Dec 2020 17:04:03 -0800 (PST) (envelope-from sgk) Date: Sun, 20 Dec 2020 17:04:03 -0800 From: Steve Kargl To: Thomas Koenig Cc: fortran@gcc.gnu.org, kargl@gcc.gnu.org Subject: Re: co-arrays and libgfortran Message-ID: <20201221010403.GA8268@troutmask.apl.washington.edu> References: <20201218042846.GA94181@troutmask.apl.washington.edu> <203c7d27-2303-f887-ea57-11b860f18a8f@netcologne.de> <20201218155252.GB96460@troutmask.apl.washington.edu> <20201219215944.GA3597@troutmask.apl.washington.edu> <20201220174740.GA7065@troutmask.apl.washington.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201220174740.GA7065@troutmask.apl.washington.edu> X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, KAM_SHORT, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=no autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: fortran@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Fortran mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 21 Dec 2020 01:04:06 -0000 On Sun, Dec 20, 2020 at 09:47:40AM -0800, Steve Kargl wrote: > On Sun, Dec 20, 2020 at 11:52:59AM +0100, Thomas Koenig wrote: > > > > > Well, one possible solution would have conv_intrinsic_random_init() > > > convert random_init(repeatable, image_distinct) into > > > > > > _gfortran_random_init(repeatable, image_distinct, hidden, sub) > > > > > > where hidden is the value of this_image() as before, and sub is the > > > name (or pointer?) to a subroutine. > > > > I think it would be easier to do > > > > if (flag_coarray == GFC_FCOARRAY_LIB) > > tmp = build_call_expr_loc (input_location, gfor_fndecl_caf_ random_init, > > 3, > > arg1, arg2, arg3); > > else if (flag_coarray == GFC_FCOARRAY_SHARED) > > tmp = build_call_expr_loc (input_location, gfor_fndecl_cas_ random_init, > > 3, > > arg1, arg2, arg3); > > else > > tmp = build_call_expr_loc (input_location, gfor_fndecl_random_init, 3, > > arg1, arg2, arg3); > > > > This way, we do not have to change the normal libgfortran, and any > > implementation can then do its own thing. > > > > Yes, that would work, too. If arg3 is the 'hidden' argument that > gfortran generates for the image number, then it is likely unneeded > under your suggestion. Both caf and cas can internally determine > this_image() and the 'none' and 'single' know that there is only > one image. Hmmm, now that I think about it. I guess we cannot > drop the 3rd argument, because it would change the ABI for > libgfortran. I have attached a patch to implements Thomas's idea to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98301 % cat d.f90 program foo call random_init(.true., .true.) call random_init(.true., .false.) call random_init(.false., .true.) call random_init(.false., .false.) end program foo % gfcx -c -fdump-tree-original d.f90 % grep random d.f90.004t.original _gfortran_random_init (1, 1, 0); _gfortran_random_init (1, 0, 0); _gfortran_random_init (0, 1, 0); _gfortran_random_init (0, 0, 0); % gfcx -c -fdump-tree-original -fcoarray=lib d.f90 % grep random d.f90.004t.original _gfortran_caf_random_init (1, 1); _gfortran_caf_random_init (1, 0); _gfortran_caf_random_init (0, 1); _gfortran_caf_random_init (0, 0); The patch includes an #if 0 ... #endif for generating a library routine for -fcoarray=shared, _gfortran_cas_random_init(). Note, that _gfortran_random_init() preserves the current libgfortran ABI. Neither of the last two arguments are needed. For _gfortran_caf_random_init() and _gfortran_cas_random_init(), if someone wants to implement these functions (Hi, Damian!) for OpenCoarray and shared memory coarray in Fortran, I suggest looking at the code in the patch labeled "New diff with improvements" attached to the PR. Thanks for the idea, Thomas. -- Steve