From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mout.gmx.net (mout.gmx.net [212.227.17.21]) by sourceware.org (Postfix) with ESMTPS id 381443ADB463 for ; Fri, 23 Apr 2021 16:44:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 381443ADB463 X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from vepi2 ([79.194.169.29]) by mail.gmx.net (mrgmx104 [212.227.17.168]) with ESMTPSA (Nemesis) id 1N5GE1-1lSJtc2Euj-0118h5; Fri, 23 Apr 2021 18:44:01 +0200 Date: Fri, 23 Apr 2021 18:43:57 +0200 From: Andre Vehreschild To: GCC-Fortran-ML Cc: Steve Kargl , Damian Rouson , Andre Vehreschild Subject: [Patch, Fortran] PR98301 Re: RANDOM_INIT() and coarray Fortran Message-ID: <20210423184357.643efbdf@vepi2> In-Reply-To: <20210404053331.GA18048@troutmask.apl.washington.edu> References: <20210403172846.GA14134@troutmask.apl.washington.edu> <20210404053331.GA18048@troutmask.apl.washington.edu> X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.33; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="MP_/gMgKsDA6135KjQsCMgQwAuI" X-Provags-ID: V03:K1:927BuJeSfdVDi2QcHPCL9rwJ0gzvnuTjzG9jC9jZd9+tfVS1gOL cNOKrbbxn3WxXXLZtSFy2z2lmVA73UcrCGzV78hcelhhCv31/eFuDSPOu8+2Oghc52Dv2vd 4QYm33vLEKe3/2TrA/OFdFuwXkNZA6KiRqEXWk2eYqfrgr9CWGw+1Xv8B+HQBrZ0GWDoXG6 yKdO/L5y1/9YVU9g0ojIg== X-UI-Out-Filterresults: notjunk:1;V03:K0:MU57Mm9L4GU=:k/vx9gxlkMt3/YY6D/NSoS ssfDqrXIS8/9JnpEf8hh6vUj21y7WesVEeyvUl86Nax3YKKLjbmds8g8t89oAQLcDFIquV6PH SHZU+nKvaAag3cA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mYPiPOnYwwyHEzomTFuJxlYgNK7Mxo CgUvtKaRcYWgrHdX+7HbzuBjmsCxGcL1brleC/JrJaQK6FYqSU09SoTDarkMRh+WK9n3Y= X-Spam-Status: No, score=-10.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham 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: Fri, 23 Apr 2021 16:44:22 -0000 --MP_/gMgKsDA6135KjQsCMgQwAuI Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Hi folks, please find attached the library part for supporting RANDOM_INIT for coarray=3Dlib enabled fortran translations. There is also a patch for the Opencoarray library to add RANDOM_INIT there. I am not sure, whether I have modified the gfortran.map file in the libgfo= rtran directory correctly, or even had to. So please take specific care if that = is correct. Bootstrapped and regtested fine on x86_64/f33. Ok for trunk? Regards, Andre PR fortran/98301 - random_init() is broken Correct implementation of random_init() when -fcoarray=3Dlib is given. gcc/fortran/ChangeLog: PR fortran/98301 * trans-decl.c (gfc_build_builtin_function_decls): Move decl. * trans-intrinsic.c (conv_intrinsic_random_init): Use bool for lib-call of caf_random_init instead of logical (4-byte). libgfortran/ChangeLog: PR fortran/98301 * caf/libcaf.h (_gfortran_caf_random_init): New function. * caf/single.c (_gfortran_caf_random_init): New function. * gfortran.map: Added fndecl. * intrinsics/random_init.f90: Modified comment. On Sat, 3 Apr 2021 22:33:31 -0700 Steve Kargl via Fortran wrote: > On Sat, Apr 03, 2021 at 08:30:31PM -0700, Damian Rouson wrote: > > Hi Steve, > > > > I hope the gfortran developers won't commit a patch that replaces > > existing behavior with a stub that simply emits an error message. > > The current behavior is incorrect with respect to the Fortran standard > if one runs a compiled program multiple times. The patch fixes a bug. > > > It has been a while since I looked at the previous emails regarding > > problems with the current behavior so I'm not expressing an opinion > > about the current behavior. I'm simply advocating against breaking > > existing codes that rely on the current behavior if nothing better is > > being provided. > > It cannot be helped. The underlying coarray implementation must > handle RANDOM_INIT(). AFAICT, there must be communication between > images if RANDOM_INIT() is used. libgfortran is not compiled with > -fcoarray=3Dlib (or -fcoarray=3Dshared), so the coarray implementation(s= ) > must deal with RANDOM_INIT(). > > > Or as a compromise, would you mind changing the patch so that the > > error message is emitted only in the problematic cases? You presented > > one problematic case out of the four possible combinations of > > RANDOM_INIT() arguments. With only four possible combinations to > > enumerate, I hope this suggestion isn't burdensome. > Consider, > > read(*,*) repeatable, image_distinct > call random_init(repeatable, image_distinct) > > for -fcoarray=3Dnone or -fcoarray=3Dsingle, the image_distinct > argument is irrevelant. This is simply translated to > > _gfortran_random_init(repeatable, image_distinct) > > For -fcoarray=3Dlib (and by extension OpenCoarray), a simple 1 line > patch on top of my patch would generate > > _gfortran_caf_random_init(repeatable, image_distinct) > > where is it assumed the function is coarray aware. Similarly, if > -fcoarray=3Dshared, then a 1 line patch would generate > > _gfortran_cas_random_init(repeatable, image_distinct) > > where is it assumed the function is coarray aware. > > There are 4 cases: > (1) repeatable=3D.true., image_distinct=3D.true. > (2) repeatable=3D.true., image_distinct=3D.false. > (3) repeatable=3D.false., image_distinct=3D.true. > (4) repeatable=3D.false., image_distinct=3D.false. > > IIRC, cases (1)-(3) don't require communication. case (4) does. > That is, case (4) requires the same set of random seeds to be > used on all images. > > > Regarding "someone who cares about coarray Fortran," finding people to > > work on such an effort is quite challenging. > > Finding people willing to work on gfortran is as challenging if > not more so. A year ago, I posted in c.l.f a list of 20+ PRs > with patches that I had created. I don't do git. It would take > someone with git-fu little time to take my patches and apply > them to a source tree. Testing was done by me, but I would > encourage git-fu aware individuals to bootstrap and test the patches. > Then commit the patch. Harald has stepped up and grabbed a few. > TO BE CLEAR, I AM NOT RANTING AT THE PEOPLE WHO HAVE CONTRIBUTED > AND MAINTAINED GFORTRAN FOR YEARS. gfortran needs new blood, or > it is destined for the bit bucket. > > > I believe Andre > > Verheschild has some limited availability so I'm cc'ing him and will > > discuss it with him if he's interested. If you know others who might > > be interested, please let us know. > > Don't know any new people who are interested in gfortran. > =2D- Andre Vehreschild * Email: vehre ad gmx dot de --MP_/gMgKsDA6135KjQsCMgQwAuI Content-Type: text/x-patch Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename=pr98301.patch diff --git a/gcc/fortran/trans-decl.c b/gcc/fortran/trans-decl.c index c99336cb19d..de0e8fb0314 100644 =2D-- a/gcc/fortran/trans-decl.c +++ b/gcc/fortran/trans-decl.c @@ -170,6 +170,7 @@ tree gfor_fndecl_co_min; tree gfor_fndecl_co_reduce; tree gfor_fndecl_co_sum; tree gfor_fndecl_caf_is_present; +tree gfor_fndecl_caf_random_init; /* Math functions. Many other math functions are handled in @@ -234,7 +235,6 @@ tree gfor_fndecl_zgemm; /* RANDOM_INIT function. */ tree gfor_fndecl_random_init; /* libgfortran, 1 image only. */ -tree gfor_fndecl_caf_random_init; /* OpenCoarray call. */ tree gfor_fndecl_cas_random_init; /* Shared memory coarray. */ static void @@ -3517,23 +3517,17 @@ gfc_build_intrinsic_function_decls (void) void_type_node, 3, gfc_logical4_type_node, gfc_logical4_type_node, gfc_int4_type_node); + // gfor_fndecl_caf_rand_init is defined in the lib-coarray section below= . + /* FIXME: This is a temporary workaround until someone that uses coarray Fortran and random_init() can implement the OpenCoarray and/or the shared memory routines. Both require communication between images, so these routines cannot live in libgfortran. */ #if 1 - gfor_fndecl_caf_random_init =3D gfc_build_library_function_decl ( - get_identifier (PREFIX("random_init_foobar")), - void_type_node, 2, gfc_logical4_type_node, gfc_logical4_type_node); - gfor_fndecl_cas_random_init =3D gfc_build_library_function_decl ( get_identifier (PREFIX("random_init_foobar")), void_type_node, 2, gfc_logical4_type_node, gfc_logical4_type_node); #else - gfor_fndecl_caf_random_init =3D gfc_build_library_function_decl ( - get_identifier (PREFIX("caf_random_init")), - void_type_node, 2, gfc_logical4_type_node, gfc_logical4_type_node); - gfor_fndecl_cas_random_init =3D gfc_build_library_function_decl ( get_identifier (PREFIX("cas_random_init")), void_type_node, 2, gfc_logical4_type_node, gfc_logical4_type_node); @@ -4104,6 +4098,10 @@ gfc_build_builtin_function_decls (void) get_identifier (PREFIX("caf_is_present")), ". r . r ", integer_type_node, 3, pvoid_type_node, integer_type_node, pvoid_type_node); + + gfor_fndecl_caf_random_init =3D gfc_build_library_function_decl ( + get_identifier (PREFIX("caf_random_init")), + void_type_node, 2, logical_type_node, logical_type_node); } gfc_build_intrinsic_function_decls (); diff --git a/gcc/fortran/trans-intrinsic.c b/gcc/fortran/trans-intrinsic.c index 900c6198d9e..8319e94b893 100644 =2D-- a/gcc/fortran/trans-intrinsic.c +++ b/gcc/fortran/trans-intrinsic.c @@ -3828,27 +3828,27 @@ conv_intrinsic_random_init (gfc_code *code) stmtblock_t block; gfc_se se; tree arg1, arg2, tmp; - tree logical4_type_node =3D gfc_get_logical_type (4); + /* On none coarray =3D=3D lib compiles use LOGICAL(4) else regular LOGI= CAL. */ + tree used_bool_type_node =3D flag_coarray =3D=3D GFC_FCOARRAY_LIB + ? logical_type_node + : gfc_get_logical_type (4); /* Make the function call. */ gfc_init_block (&block); gfc_init_se (&se, NULL); - /* Convert REPEATABLE to a LOGICAL(4) entity. */ + /* Convert REPEATABLE to the desired LOGICAL entity. */ gfc_conv_expr (&se, code->ext.actual->expr); gfc_add_block_to_block (&block, &se.pre); - arg1 =3D fold_convert (logical4_type_node, gfc_evaluate_now (se.expr, &= block)); + arg1 =3D fold_convert (used_bool_type_node, gfc_evaluate_now (se.expr, = &block)); gfc_add_block_to_block (&block, &se.post); - /* Convert IMAGE_DISTINCT to a LOGICAL(4) entity. */ + /* Convert IMAGE_DISTINCT to the desired LOGICAL entity. */ gfc_conv_expr (&se, code->ext.actual->next->expr); gfc_add_block_to_block (&block, &se.pre); - arg2 =3D fold_convert (logical4_type_node, gfc_evaluate_now (se.expr, &= block)); + arg2 =3D fold_convert (used_bool_type_node, gfc_evaluate_now (se.expr, = &block)); gfc_add_block_to_block (&block, &se.post); - /* Create the hidden argument. For non-coarray codes and -fcoarray=3Ds= ingle, - simply set this to 0. For -fcoarray=3Dlib, generate a call to - THIS_IMAGE() without arguments. */ if (flag_coarray =3D=3D GFC_FCOARRAY_LIB) { tmp =3D build_call_expr_loc (input_location, gfor_fndecl_caf_random= _init, diff --git a/libgfortran/caf/libcaf.h b/libgfortran/caf/libcaf.h index 5abb753f6fd..c66d0379042 100644 =2D-- a/libgfortran/caf/libcaf.h +++ b/libgfortran/caf/libcaf.h @@ -261,4 +261,6 @@ void _gfortran_caf_stopped_images (gfc_descriptor_t *, int _gfortran_caf_is_present (caf_token_t, int, caf_reference_t *); +void _gfortran_caf_random_init (bool, bool); + #endif /* LIBCAF_H */ diff --git a/libgfortran/caf/single.c b/libgfortran/caf/single.c index a291c4452c9..fc8e3b3b94a 100644 =2D-- a/libgfortran/caf/single.c +++ b/libgfortran/caf/single.c @@ -3135,3 +3135,13 @@ _gfortran_caf_is_present (caf_token_t token, } return memptr !=3D NULL; } + +/* Reference the libraries implementation. */ +extern void _gfortran_random_init (int32_t, int32_t, int32_t); + +void _gfortran_caf_random_init (bool repeatable, bool image_distinct) +{ + /* In a single image implementation always forward to the gfortran + routine. */ + _gfortran_random_init (repeatable, image_distinct, 1); +} diff --git a/libgfortran/gfortran.map b/libgfortran/gfortran.map index b594b59849a..626804c37dd 100644 =2D-- a/libgfortran/gfortran.map +++ b/libgfortran/gfortran.map @@ -1634,3 +1634,8 @@ GFORTRAN_11 { global: _gfortran_random_init_foobar; } GFORTRAN_10.2; + +GFORTRAN_12 { + global: + _gfortran_caf_random_init; +} GFORTRAN_11; diff --git a/libgfortran/intrinsics/random_init.f90 b/libgfortran/intrinsi= cs/random_init.f90 index bbb45937087..233a1ca073a 100644 =2D-- a/libgfortran/intrinsics/random_init.f90 +++ b/libgfortran/intrinsics/random_init.f90 @@ -100,7 +100,7 @@ impure subroutine _gfortran_random_init(repeatable, im= age_distinct, image_num) end subroutine _gfortran_random_init ! ! This is a temporary stub implementation until random_init is -! implemented for -fcoarray=3Dshared and -fcoarray=3Dlib. +! implemented for -fcoarray=3Dshared. ! subroutine _gfortran_random_init_foobar(repeatable, image_distinct) --MP_/gMgKsDA6135KjQsCMgQwAuI--