From owner-sc22wg5+sc22wg5-dom9=www.open-std.org@open-std.org  Mon Mar 18 08:04:08 2024
Return-Path: <owner-sc22wg5+sc22wg5-dom9=www.open-std.org@open-std.org>
X-Original-To: sc22wg5-dom9
Delivered-To: sc22wg5-dom9@www.open-std.org
Received: by www.open-std.org (Postfix, from userid 521)
	id 1AE59356D8A; Mon, 18 Mar 2024 08:04:08 +0100 (CET)
Delivered-To: sc22wg5@open-std.org
Received: from nag-j.co.jp (bvdeuz19.secure.ne.jp [180.222.80.19])
	by www.open-std.org (Postfix) with SMTP id 1D5373568AA
	for <sc22wg5@open-std.org>; Mon, 18 Mar 2024 08:04:04 +0100 (CET)
Received: (qmail 24400 invoked from network); 18 Mar 2024 16:04:02 +0900
Received: from unknown (HELO Maru10) (218.42.159.105)
  by 0 with SMTP; 18 Mar 2024 16:04:02 +0900
From: "Malcolm Cohen" <malcolm@nag-j.co.jp>
To: "'WG5'" <sc22wg5@open-std.org>
References: <DM6PR12MB3130DA4A03A92CC08EF2F8F5CB282@DM6PR12MB3130.namprd12.prod.outlook.com>
In-Reply-To: <DM6PR12MB3130DA4A03A92CC08EF2F8F5CB282@DM6PR12MB3130.namprd12.prod.outlook.com>
Subject: RE: [ukfortran] [SC22WG5.6552] bind(C) external linkage issues on MacOS
Date: Mon, 18 Mar 2024 16:04:03 +0900
Message-ID: <01e301da7902$75ab3160$61019420$@nag-j.co.jp>
MIME-Version: 1.0
Content-Type: multipart/alternative;
	boundary="----=_NextPart_000_01E4_01DA794D.E5960DB0"
X-Mailer: Microsoft Outlook 16.0
Thread-Index: AQKJXIUf4GyabNvhyABgzEFOckKtkq/fSbkg
Content-Language: ja
Sender: owner-sc22wg5@open-std.org
Precedence: bulk

This is a multipart message in MIME format.

------=_NextPart_000_01E4_01DA794D.E5960DB0
Content-Type: text/plain;
	charset="us-ascii"
Content-Transfer-Encoding: 7bit

Perhaps using something equivalent to the gcc "__attribute__((__common__))"
on the symbol might help? In C one is stuck with the gcc extension, but in
principle the Fortran compiler should be able to do this automatically.

 

Unless this is a slightly different issue, for which the above doesn't work.

 

Cheers,

-- 

..............Malcolm Cohen, NAG Oxford/Tokyo.

 

From: Jeff Hammond <jehammond@nvidia.com> 
Sent: Saturday, March 16, 2024 2:29 AM
To: WG5 <sc22wg5@open-std.org>
Subject: [ukfortran] [SC22WG5.6552] bind(C) external linkage issues on MacOS

 

This is both an FYI for those of you who use MacOS but also a possible
identification of a problem in how we specify 19.5.1.5 Linkage association.

 

Apple has removed "-commons use_dylibs" in recent versions of MacOS.  This
flag sets a non-default behavior of COMMON symbols (which include linkage
associated bind(C) symbols that are not using obsolescent features) to be
"U" (undefined) instead of "S" (uninitialized, small)
https://linux.die.net/man/1/nm.

 

This flag is required to get a bind(C) module variable that points to a C
global variable to work properly, as is potentially required by MPI.  There
are many reports of failures online with both GCC and Intel compilers (I can
only verify the former).

 

It has been noted that our definition of linkage association may not be
adequate to interact with C shared libraries.  I don't understand this topic
well enough to have an opinion either way.

 

Has anybody else run into this or thought about it enough to know if there
is a way to enhance our definition of linkage association so as to not
require Fortran-specific linker options and behave more like C extern in
shared libraries?

 

Thanks,

Jeff

 

jhammond@Jeff-M2 fortran % gcc -fPIC -shared extern2.c -o libxxx.so &&
gfortran -c extern.F90 && ld extern.o libxxx.so
-L/opt/homebrew/Cellar/gcc/13.2.0/lib/gcc/current/  -lgfortran -commons
use_dylibs -o extern && ./extern ; nm extern | grep MPI

MPIR_F08_MPI_IN_PLACE=0 &MPIR_F08_MPI_IN_PLACE=0x1003a4000
&MPIR_F08_MPI_IN_PLACE=4298784768

LOC(MPI_IN_PLACE)=           4298784768

LOC(buf)=           6168523360

sendbuf=0x1003a4000, sendbuf=4298784768

sendbuf is MPI_IN_PLACE? yes

recvbuf=0x16fac3260, recvbuf=6168523360

*count=1, *datatype=2, *op=3, *comm=4

         911

                 U _MPIR_F08_MPI_IN_PLACE

                 U _MPI_Allreduce

 

 

jhammond@Jeff-M2 fortran % gcc -fPIC -shared extern2.c -o libxxx.so &&
gfortran -c extern.F90 && ld extern.o libxxx.so
-L/opt/homebrew/Cellar/gcc/13.2.0/lib/gcc/current/  -lgfortran  -o extern &&
./extern ; nm extern | grep MPI

MPIR_F08_MPI_IN_PLACE=0 &MPIR_F08_MPI_IN_PLACE=0x102b1c000
&MPIR_F08_MPI_IN_PLACE=4340170752

LOC(MPI_IN_PLACE)=           4339777664

LOC(buf)=           6127137376

sendbuf=0x102abc080, sendbuf=4339777664

sendbuf is MPI_IN_PLACE? no

recvbuf=0x16d34b260, recvbuf=6127137376

*count=1, *datatype=2, *op=3, *comm=4

         911

0000000100008080 S _MPIR_F08_MPI_IN_PLACE

                 U _MPI_Allreduce

 

 

==> extern2.c <==

#include <stdio.h>

#include <stdint.h>

 

int MPIR_F08_MPI_IN_PLACE;

 

void p(void)

{

    printf("MPIR_F08_MPI_IN_PLACE=%d &MPIR_F08_MPI_IN_PLACE=%p
&MPIR_F08_MPI_IN_PLACE=%zu\n",

            MPIR_F08_MPI_IN_PLACE,   &MPIR_F08_MPI_IN_PLACE,
(intptr_t)&MPIR_F08_MPI_IN_PLACE);

}

 

void MPI_Allreduce(void ** sendbuf, void ** recvbuf,

                   int * count, int * datatype,

                   int * op, int * comm, int * ierror)

{

    printf("sendbuf=%p, sendbuf=%zu\n", sendbuf, (intptr_t)sendbuf);

    printf("sendbuf is MPI_IN_PLACE? %s\n",

           (intptr_t)sendbuf==(intptr_t)&MPIR_F08_MPI_IN_PLACE ? "yes" :
"no");

    printf("recvbuf=%p, recvbuf=%zu\n", recvbuf, (intptr_t)recvbuf);

    printf("*count=%d, *datatype=%d, *op=%d, *comm=%d\n",

            *count, *datatype, *op, *comm);

    *ierror = 911;

}

 

==> extern.F90 <==

module mpi

    use iso_c_binding

    !type(c_ptr), bind(C,name="MPI_F_IN_PLACE") :: MPI_IN_PLACE

    integer(c_int), bind(C, name="MPIR_F08_MPI_IN_PLACE"), target ::
MPI_IN_PLACE

    interface

        subroutine p() bind(C,name="p")

        end subroutine

    end interface

    interface

        SUBROUTINE MPI_ALLREDUCE(SENDBUF, RECVBUF, COUNT, DATATYPE, OP,
COMM, IERROR) &

                   bind(C,name="MPI_Allreduce")

            use iso_c_binding

            import :: MPI_IN_PLACE

            !DEC$ ATTRIBUTES NO_ARG_CHECK :: sendbuf,recvbuf

            !GCC$ ATTRIBUTES NO_ARG_CHECK :: sendbuf,recvbuf

            !$PRAGMA IGNORE_TKR sendbuf,recvbuf

            !DIR$ IGNORE_TKR sendbuf,recvbuf

            !IBM* IGNORE_TKR sendbuf,recvbuf

            INTEGER(kind=c_int) :: SENDBUF(*), RECVBUF(*)

            INTEGER(kind=c_int) :: COUNT, DATATYPE, OP, COMM, IERROR

        END SUBROUTINE MPI_ALLREDUCE

    end interface

end module mpi

 

program main

    use mpi

    implicit none

    real :: buf(100)

    integer :: ierror

    call p

    buf = 17

    print*,'LOC(MPI_IN_PLACE)=',LOC(MPI_IN_PLACE)

    print*,'LOC(buf)=',LOC(buf)

    call MPI_ALLREDUCE(MPI_IN_PLACE,buf,1,2,3,4,ierror)

    print*,ierror

end program main


------=_NextPart_000_01E4_01DA794D.E5960DB0
Content-Type: text/html;
	charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

<html xmlns:v=3D"urn:schemas-microsoft-com:vml" =
xmlns:o=3D"urn:schemas-microsoft-com:office:office" =
xmlns:w=3D"urn:schemas-microsoft-com:office:word" =
xmlns:m=3D"http://schemas.microsoft.com/office/2004/12/omml" =
xmlns=3D"http://www.w3.org/TR/REC-html40"><head><meta =
http-equiv=3DContent-Type content=3D"text/html; =
charset=3Dus-ascii"><meta name=3DGenerator content=3D"Microsoft Word 15 =
(filtered medium)"><style><!--
/* Font Definitions */
@font-face
	{font-family:"Cambria Math";
	panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
	{font-family:"Yu Gothic";
	panose-1:2 11 4 0 0 0 0 0 0 0;}
@font-face
	{font-family:Calibri;
	panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
	{font-family:"Yu Gothic";
	panose-1:2 11 4 0 0 0 0 0 0 0;}
@font-face
	{font-family:Aptos;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
	{margin:0cm;
	font-size:11.0pt;
	font-family:"Aptos",sans-serif;
	mso-ligatures:standardcontextual;}
a:link, span.MsoHyperlink
	{mso-style-priority:99;
	color:#467886;
	text-decoration:underline;}
span.19
	{mso-style-type:personal-reply;
	font-family:"Calibri",sans-serif;
	color:windowtext;}
.MsoChpDefault
	{mso-style-type:export-only;
	font-size:10.0pt;
	mso-ligatures:none;}
@page WordSection1
	{size:612.0pt 792.0pt;
	margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
	{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext=3D"edit" spidmax=3D"1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext=3D"edit">
<o:idmap v:ext=3D"edit" data=3D"1" />
</o:shapelayout></xml><![endif]--></head><body lang=3DEN-GB =
link=3D"#467886" vlink=3D"#96607D" style=3D'word-wrap:break-word'><div =
class=3DWordSection1><p class=3DMsoNormal><span =
style=3D'font-family:"Calibri",sans-serif'>Perhaps using something =
equivalent to the gcc &#8220;__attribute__((__common__))&#8221; on the =
symbol might help? In C one is stuck with the gcc extension, but in =
principle the Fortran compiler should be able to do this =
automatically.<o:p></o:p></span></p><p class=3DMsoNormal><span =
style=3D'font-family:"Calibri",sans-serif'><o:p>&nbsp;</o:p></span></p><p=
 class=3DMsoNormal><span =
style=3D'font-family:"Calibri",sans-serif'>Unless this is a slightly =
different issue, for which the above doesn&#8217;t =
work&#8230;<o:p></o:p></span></p><p class=3DMsoNormal><span =
style=3D'font-family:"Calibri",sans-serif'><o:p>&nbsp;</o:p></span></p><p=
 class=3DMsoNormal><span =
style=3D'font-family:"Calibri",sans-serif'>Cheers,<o:p></o:p></span></p><=
div><p class=3DMsoNormal =
style=3D'text-align:justify;text-justify:inter-ideograph'><span =
lang=3DEN-US =
style=3D'font-size:10.5pt;font-family:"Calibri",sans-serif;mso-ligatures:=
none'>-- </span><span =
style=3D'font-size:10.5pt;font-family:"Calibri",sans-serif;mso-ligatures:=
none'><o:p></o:p></span></p><p class=3DMsoNormal =
style=3D'text-align:justify;text-justify:inter-ideograph'><span =
lang=3DEN-US =
style=3D'font-size:10.5pt;font-family:"Calibri",sans-serif;mso-ligatures:=
none'>..............Malcolm Cohen, NAG Oxford/Tokyo.</span><span =
style=3D'font-size:10.5pt;font-family:"Calibri",sans-serif;mso-ligatures:=
none'><o:p></o:p></span></p></div><p class=3DMsoNormal><span =
style=3D'font-family:"Calibri",sans-serif'><o:p>&nbsp;</o:p></span></p><d=
iv><div style=3D'border:none;border-top:solid #E1E1E1 =
1.0pt;padding:3.0pt 0cm 0cm 0cm'><p class=3DMsoNormal><b><span =
style=3D'font-family:"Calibri",sans-serif;mso-ligatures:none'>From:</span=
></b><span =
style=3D'font-family:"Calibri",sans-serif;mso-ligatures:none'> Jeff =
Hammond &lt;jehammond@nvidia.com&gt; <br><b>Sent:</b> Saturday, March =
16, 2024 2:29 AM<br><b>To:</b> WG5 =
&lt;sc22wg5@open-std.org&gt;<br><b>Subject:</b> [ukfortran] =
[SC22WG5.6552] bind(C) external linkage issues on =
MacOS<o:p></o:p></span></p></div></div><p =
class=3DMsoNormal><o:p>&nbsp;</o:p></p><p class=3DMsoNormal><span =
lang=3DEN-US style=3D'font-size:12.0pt'>This is both an FYI for those of =
you who use MacOS but also a possible identification of a problem in how =
we specify 19.5.1.5 Linkage association.<o:p></o:p></span></p><p =
class=3DMsoNormal><span lang=3DEN-US =
style=3D'font-size:12.0pt'><o:p>&nbsp;</o:p></span></p><p =
class=3DMsoNormal><span lang=3DEN-US style=3D'font-size:12.0pt'>Apple =
has removed &#8220;-commons use_dylibs&#8221; in recent versions of =
MacOS.&nbsp; This flag sets a non-default behavior of COMMON symbols =
(which include linkage associated bind(C) symbols that are not using =
obsolescent features) to be &#8220;U&#8221; (undefined) instead of =
&#8220;S&#8221; (uninitialized, small) <a =
href=3D"https://linux.die.net/man/1/nm">https://linux.die.net/man/1/nm</a=
>.<o:p></o:p></span></p><p class=3DMsoNormal><span lang=3DEN-US =
style=3D'font-size:12.0pt'><o:p>&nbsp;</o:p></span></p><p =
class=3DMsoNormal><span lang=3DEN-US style=3D'font-size:12.0pt'>This =
flag is required to get a bind(C) module variable that points to a C =
global variable to work properly, as is potentially required by =
MPI.&nbsp; There are many reports of failures online with both GCC and =
Intel compilers (I can only verify the former).<o:p></o:p></span></p><p =
class=3DMsoNormal><span lang=3DEN-US =
style=3D'font-size:12.0pt'><o:p>&nbsp;</o:p></span></p><p =
class=3DMsoNormal><span lang=3DEN-US style=3D'font-size:12.0pt'>It has =
been noted that our definition of linkage association may not be =
adequate to interact with C shared libraries.&nbsp; I don&#8217;t =
understand this topic well enough to have an opinion either =
way.<o:p></o:p></span></p><p class=3DMsoNormal><span lang=3DEN-US =
style=3D'font-size:12.0pt'><o:p>&nbsp;</o:p></span></p><p =
class=3DMsoNormal><span lang=3DEN-US style=3D'font-size:12.0pt'>Has =
anybody else run into this or thought about it enough to know if there =
is a way to enhance our definition of linkage association so as to not =
require Fortran-specific linker options and behave more like C extern in =
shared libraries?<o:p></o:p></span></p><p class=3DMsoNormal><span =
lang=3DEN-US style=3D'font-size:12.0pt'><o:p>&nbsp;</o:p></span></p><p =
class=3DMsoNormal><span lang=3DEN-US =
style=3D'font-size:12.0pt'>Thanks,<br><br>Jeff<o:p></o:p></span></p><p =
class=3DMsoNormal><span lang=3DEN-US =
style=3D'font-size:12.0pt'><o:p>&nbsp;</o:p></span></p><p =
class=3DMsoNormal><span lang=3DEN-US =
style=3D'font-size:12.0pt'>jhammond@Jeff-M2 fortran % gcc -fPIC -shared =
extern2.c -o libxxx.so &amp;&amp; gfortran -c extern.F90 &amp;&amp; ld =
extern.o libxxx.so =
-L/opt/homebrew/Cellar/gcc/13.2.0/lib/gcc/current/&nbsp; -lgfortran =
-<span style=3D'color:red'>commons use_dylibs </span>-o extern =
&amp;&amp; ./extern ; nm extern | grep MPI<o:p></o:p></span></p><p =
class=3DMsoNormal><span lang=3DEN-US =
style=3D'font-size:12.0pt'>MPIR_F08_MPI_IN_PLACE=3D0 =
&amp;MPIR_F08_MPI_IN_PLACE=3D0x1003a4000 =
&amp;MPIR_F08_MPI_IN_PLACE=3D4298784768<o:p></o:p></span></p><p =
class=3DMsoNormal><span lang=3DEN-US =
style=3D'font-size:12.0pt'>LOC(MPI_IN_PLACE)=3D&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 4298784768<o:p></o:p></span></p><p =
class=3DMsoNormal><span lang=3DEN-US =
style=3D'font-size:12.0pt'>LOC(buf)=3D&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp; 6168523360<o:p></o:p></span></p><p =
class=3DMsoNormal><span lang=3DEN-US =
style=3D'font-size:12.0pt'>sendbuf=3D0x1003a4000, =
sendbuf=3D4298784768<o:p></o:p></span></p><p class=3DMsoNormal><span =
lang=3DEN-US style=3D'font-size:12.0pt'>sendbuf is MPI_IN_PLACE? =
yes<o:p></o:p></span></p><p class=3DMsoNormal><span lang=3DEN-US =
style=3D'font-size:12.0pt'>recvbuf=3D0x16fac3260, =
recvbuf=3D6168523360<o:p></o:p></span></p><p class=3DMsoNormal><span =
lang=3DEN-US style=3D'font-size:12.0pt'>*count=3D1, *datatype=3D2, =
*op=3D3, *comm=3D4<o:p></o:p></span></p><p class=3DMsoNormal><span =
lang=3DEN-US =
style=3D'font-size:12.0pt'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p; 911<o:p></o:p></span></p><p class=3DMsoNormal><span lang=3DEN-US =
style=3D'font-size:12.0pt;color:red'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; U =
_MPIR_F08_MPI_IN_PLACE<o:p></o:p></span></p><p class=3DMsoNormal><span =
lang=3DEN-US =
style=3D'font-size:12.0pt'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; U =
_MPI_Allreduce<o:p></o:p></span></p><p class=3DMsoNormal><span =
lang=3DEN-US style=3D'font-size:12.0pt'><o:p>&nbsp;</o:p></span></p><p =
class=3DMsoNormal><span lang=3DEN-US =
style=3D'font-size:12.0pt'><o:p>&nbsp;</o:p></span></p><p =
class=3DMsoNormal><span lang=3DEN-US =
style=3D'font-size:12.0pt'>jhammond@Jeff-M2 fortran % gcc -fPIC -shared =
extern2.c -o libxxx.so &amp;&amp; gfortran -c extern.F90 &amp;&amp; ld =
extern.o libxxx.so =
-L/opt/homebrew/Cellar/gcc/13.2.0/lib/gcc/current/&nbsp; =
-lgfortran&nbsp; -o extern &amp;&amp; ./extern ; nm extern | grep =
MPI<o:p></o:p></span></p><p class=3DMsoNormal><span lang=3DEN-US =
style=3D'font-size:12.0pt'>MPIR_F08_MPI_IN_PLACE=3D0 =
&amp;MPIR_F08_MPI_IN_PLACE=3D0x102b1c000 =
&amp;MPIR_F08_MPI_IN_PLACE=3D4340170752<o:p></o:p></span></p><p =
class=3DMsoNormal><span lang=3DEN-US =
style=3D'font-size:12.0pt'>LOC(MPI_IN_PLACE)=3D&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 4339777664<o:p></o:p></span></p><p =
class=3DMsoNormal><span lang=3DEN-US =
style=3D'font-size:12.0pt'>LOC(buf)=3D&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp; 6127137376<o:p></o:p></span></p><p =
class=3DMsoNormal><span lang=3DEN-US =
style=3D'font-size:12.0pt'>sendbuf=3D0x102abc080, =
sendbuf=3D4339777664<o:p></o:p></span></p><p class=3DMsoNormal><span =
lang=3DEN-US style=3D'font-size:12.0pt'>sendbuf is MPI_IN_PLACE? =
no<o:p></o:p></span></p><p class=3DMsoNormal><span lang=3DEN-US =
style=3D'font-size:12.0pt'>recvbuf=3D0x16d34b260, =
recvbuf=3D6127137376<o:p></o:p></span></p><p class=3DMsoNormal><span =
lang=3DEN-US style=3D'font-size:12.0pt'>*count=3D1, *datatype=3D2, =
*op=3D3, *comm=3D4<o:p></o:p></span></p><p class=3DMsoNormal><span =
lang=3DEN-US =
style=3D'font-size:12.0pt'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p; 911<o:p></o:p></span></p><p class=3DMsoNormal><span lang=3DEN-US =
style=3D'font-size:12.0pt;color:red'>0000000100008080 S =
_MPIR_F08_MPI_IN_PLACE</span><span lang=3DEN-US =
style=3D'font-size:12.0pt'><o:p></o:p></span></p><p =
class=3DMsoNormal><span lang=3DEN-US =
style=3D'font-size:12.0pt'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; U =
_MPI_Allreduce<o:p></o:p></span></p><p class=3DMsoNormal><span =
lang=3DEN-US style=3D'font-size:12.0pt'><o:p>&nbsp;</o:p></span></p><p =
class=3DMsoNormal><span lang=3DEN-US =
style=3D'font-size:12.0pt'><o:p>&nbsp;</o:p></span></p><p =
class=3DMsoNormal><span lang=3DEN-US =
style=3D'font-size:12.0pt'>=3D=3D&gt; extern2.c =
&lt;=3D=3D<o:p></o:p></span></p><p class=3DMsoNormal><span lang=3DEN-US =
style=3D'font-size:12.0pt'>#include =
&lt;stdio.h&gt;<o:p></o:p></span></p><p class=3DMsoNormal><span =
lang=3DEN-US style=3D'font-size:12.0pt'>#include =
&lt;stdint.h&gt;<o:p></o:p></span></p><p class=3DMsoNormal><span =
lang=3DEN-US style=3D'font-size:12.0pt'><o:p>&nbsp;</o:p></span></p><p =
class=3DMsoNormal><span lang=3DEN-US style=3D'font-size:12.0pt'>int =
MPIR_F08_MPI_IN_PLACE;<o:p></o:p></span></p><p class=3DMsoNormal><span =
lang=3DEN-US style=3D'font-size:12.0pt'><o:p>&nbsp;</o:p></span></p><p =
class=3DMsoNormal><span lang=3DEN-US style=3D'font-size:12.0pt'>void =
p(void)<o:p></o:p></span></p><p class=3DMsoNormal><span lang=3DEN-US =
style=3D'font-size:12.0pt'>{<o:p></o:p></span></p><p =
class=3DMsoNormal><span lang=3DEN-US =
style=3D'font-size:12.0pt'>&nbsp;&nbsp;&nbsp; =
printf(&quot;MPIR_F08_MPI_IN_PLACE=3D%d &amp;MPIR_F08_MPI_IN_PLACE=3D%p =
&amp;MPIR_F08_MPI_IN_PLACE=3D%zu\n&quot;,<o:p></o:p></span></p><p =
class=3DMsoNormal><span lang=3DEN-US =
style=3D'font-size:12.0pt'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp; MPIR_F08_MPI_IN_PLACE,&nbsp;&nbsp; =
&amp;MPIR_F08_MPI_IN_PLACE,&nbsp;&nbsp; =
(intptr_t)&amp;MPIR_F08_MPI_IN_PLACE);<o:p></o:p></span></p><p =
class=3DMsoNormal><span lang=3DEN-US =
style=3D'font-size:12.0pt'>}<o:p></o:p></span></p><p =
class=3DMsoNormal><span lang=3DEN-US =
style=3D'font-size:12.0pt'><o:p>&nbsp;</o:p></span></p><p =
class=3DMsoNormal><span lang=3DEN-US style=3D'font-size:12.0pt'>void =
MPI_Allreduce(void ** sendbuf, void ** recvbuf,<o:p></o:p></span></p><p =
class=3DMsoNormal><span lang=3DEN-US =
style=3D'font-size:12.0pt'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int * =
count, int * datatype,<o:p></o:p></span></p><p class=3DMsoNormal><span =
lang=3DEN-US =
style=3D'font-size:12.0pt'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int * op, =
int * comm, int * ierror)<o:p></o:p></span></p><p =
class=3DMsoNormal><span lang=3DEN-US =
style=3D'font-size:12.0pt'>{<o:p></o:p></span></p><p =
class=3DMsoNormal><span lang=3DEN-US =
style=3D'font-size:12.0pt'>&nbsp;&nbsp;&nbsp; printf(&quot;sendbuf=3D%p, =
sendbuf=3D%zu\n&quot;, sendbuf, =
(intptr_t)sendbuf);<o:p></o:p></span></p><p class=3DMsoNormal><span =
lang=3DEN-US style=3D'font-size:12.0pt'>&nbsp;&nbsp;&nbsp; =
printf(&quot;sendbuf is MPI_IN_PLACE? =
%s\n&quot;,<o:p></o:p></span></p><p class=3DMsoNormal><span lang=3DEN-US =
style=3D'font-size:12.0pt'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp; =
(intptr_t)sendbuf=3D=3D(intptr_t)&amp;MPIR_F08_MPI_IN_PLACE ? =
&quot;yes&quot; : &quot;no&quot;);<o:p></o:p></span></p><p =
class=3DMsoNormal><span lang=3DEN-US =
style=3D'font-size:12.0pt'>&nbsp;&nbsp;&nbsp; printf(&quot;recvbuf=3D%p, =
recvbuf=3D%zu\n&quot;, recvbuf, =
(intptr_t)recvbuf);<o:p></o:p></span></p><p class=3DMsoNormal><span =
lang=3DEN-US style=3D'font-size:12.0pt'>&nbsp;&nbsp;&nbsp; =
printf(&quot;*count=3D%d, *datatype=3D%d, *op=3D%d, =
*comm=3D%d\n&quot;,<o:p></o:p></span></p><p class=3DMsoNormal><span =
lang=3DEN-US =
style=3D'font-size:12.0pt'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp; *count, *datatype, *op, =
*comm);<o:p></o:p></span></p><p class=3DMsoNormal><span lang=3DEN-US =
style=3D'font-size:12.0pt'>&nbsp;&nbsp;&nbsp; *ierror =3D =
911;<o:p></o:p></span></p><p class=3DMsoNormal><span lang=3DEN-US =
style=3D'font-size:12.0pt'>}<o:p></o:p></span></p><p =
class=3DMsoNormal><span lang=3DEN-US =
style=3D'font-size:12.0pt'><o:p>&nbsp;</o:p></span></p><p =
class=3DMsoNormal><span lang=3DEN-US =
style=3D'font-size:12.0pt'>=3D=3D&gt; extern.F90 =
&lt;=3D=3D<o:p></o:p></span></p><p class=3DMsoNormal><span lang=3DEN-US =
style=3D'font-size:12.0pt'>module mpi<o:p></o:p></span></p><p =
class=3DMsoNormal><span lang=3DEN-US =
style=3D'font-size:12.0pt'>&nbsp;&nbsp;&nbsp; use =
iso_c_binding<o:p></o:p></span></p><p class=3DMsoNormal><span =
lang=3DEN-US style=3D'font-size:12.0pt'>&nbsp;&nbsp;&nbsp; !type(c_ptr), =
bind(C,name=3D&quot;MPI_F_IN_PLACE&quot;) :: =
MPI_IN_PLACE<o:p></o:p></span></p><p class=3DMsoNormal><span =
lang=3DEN-US style=3D'font-size:12.0pt'>&nbsp;&nbsp;&nbsp; =
integer(c_int), bind(C, name=3D&quot;MPIR_F08_MPI_IN_PLACE&quot;), =
target :: MPI_IN_PLACE<o:p></o:p></span></p><p class=3DMsoNormal><span =
lang=3DEN-US style=3D'font-size:12.0pt'>&nbsp;&nbsp;&nbsp; =
interface<o:p></o:p></span></p><p class=3DMsoNormal><span lang=3DEN-US =
style=3D'font-size:12.0pt'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
subroutine p() bind(C,name=3D&quot;p&quot;)<o:p></o:p></span></p><p =
class=3DMsoNormal><span lang=3DEN-US =
style=3D'font-size:12.0pt'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
end subroutine<o:p></o:p></span></p><p class=3DMsoNormal><span =
lang=3DEN-US style=3D'font-size:12.0pt'>&nbsp;&nbsp;&nbsp; end =
interface<o:p></o:p></span></p><p class=3DMsoNormal><span lang=3DEN-US =
style=3D'font-size:12.0pt'>&nbsp;&nbsp;&nbsp; =
interface<o:p></o:p></span></p><p class=3DMsoNormal><span lang=3DEN-US =
style=3D'font-size:12.0pt'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
SUBROUTINE MPI_ALLREDUCE(SENDBUF, RECVBUF, COUNT, DATATYPE, OP, COMM, =
IERROR) &amp;<o:p></o:p></span></p><p class=3DMsoNormal><span =
lang=3DEN-US =
style=3D'font-size:12.0pt'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
bind(C,name=3D&quot;MPI_Allreduce&quot;)<o:p></o:p></span></p><p =
class=3DMsoNormal><span lang=3DEN-US =
style=3D'font-size:12.0pt'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp; use iso_c_binding<o:p></o:p></span></p><p =
class=3DMsoNormal><span lang=3DEN-US =
style=3D'font-size:12.0pt'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp; import :: MPI_IN_PLACE<o:p></o:p></span></p><p =
class=3DMsoNormal><span lang=3DEN-US =
style=3D'font-size:12.0pt'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp; !DEC$ ATTRIBUTES NO_ARG_CHECK :: =
sendbuf,recvbuf<o:p></o:p></span></p><p class=3DMsoNormal><span =
lang=3DEN-US =
style=3D'font-size:12.0pt'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp; !GCC$ ATTRIBUTES NO_ARG_CHECK :: =
sendbuf,recvbuf<o:p></o:p></span></p><p class=3DMsoNormal><span =
lang=3DEN-US =
style=3D'font-size:12.0pt'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp; !$PRAGMA IGNORE_TKR =
sendbuf,recvbuf<o:p></o:p></span></p><p class=3DMsoNormal><span =
lang=3DEN-US =
style=3D'font-size:12.0pt'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp; !DIR$ IGNORE_TKR =
sendbuf,recvbuf<o:p></o:p></span></p><p class=3DMsoNormal><span =
lang=3DEN-US =
style=3D'font-size:12.0pt'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp; !IBM* IGNORE_TKR =
sendbuf,recvbuf<o:p></o:p></span></p><p class=3DMsoNormal><span =
lang=3DEN-US =
style=3D'font-size:12.0pt'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp; INTEGER(kind=3Dc_int) :: SENDBUF(*), =
RECVBUF(*)<o:p></o:p></span></p><p class=3DMsoNormal><span lang=3DEN-US =
style=3D'font-size:12.0pt'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp; INTEGER(kind=3Dc_int) :: COUNT, DATATYPE, OP, COMM, =
IERROR<o:p></o:p></span></p><p class=3DMsoNormal><span lang=3DEN-US =
style=3D'font-size:12.0pt'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
END SUBROUTINE MPI_ALLREDUCE<o:p></o:p></span></p><p =
class=3DMsoNormal><span lang=3DEN-US =
style=3D'font-size:12.0pt'>&nbsp;&nbsp;&nbsp; end =
interface<o:p></o:p></span></p><p class=3DMsoNormal><span lang=3DEN-US =
style=3D'font-size:12.0pt'>end module mpi<o:p></o:p></span></p><p =
class=3DMsoNormal><span lang=3DEN-US =
style=3D'font-size:12.0pt'><o:p>&nbsp;</o:p></span></p><p =
class=3DMsoNormal><span lang=3DEN-US style=3D'font-size:12.0pt'>program =
main<o:p></o:p></span></p><p class=3DMsoNormal><span lang=3DEN-US =
style=3D'font-size:12.0pt'>&nbsp;&nbsp;&nbsp; use =
mpi<o:p></o:p></span></p><p class=3DMsoNormal><span lang=3DEN-US =
style=3D'font-size:12.0pt'>&nbsp;&nbsp;&nbsp; implicit =
none<o:p></o:p></span></p><p class=3DMsoNormal><span lang=3DEN-US =
style=3D'font-size:12.0pt'>&nbsp;&nbsp;&nbsp; real :: =
buf(100)<o:p></o:p></span></p><p class=3DMsoNormal><span lang=3DEN-US =
style=3D'font-size:12.0pt'>&nbsp;&nbsp;&nbsp; integer :: =
ierror<o:p></o:p></span></p><p class=3DMsoNormal><span lang=3DEN-US =
style=3D'font-size:12.0pt'>&nbsp;&nbsp;&nbsp; call =
p<o:p></o:p></span></p><p class=3DMsoNormal><span lang=3DEN-US =
style=3D'font-size:12.0pt'>&nbsp;&nbsp;&nbsp; buf =3D =
17<o:p></o:p></span></p><p class=3DMsoNormal><span lang=3DEN-US =
style=3D'font-size:12.0pt'>&nbsp;&nbsp;&nbsp; =
print*,'LOC(MPI_IN_PLACE)=3D',LOC(MPI_IN_PLACE)<o:p></o:p></span></p><p =
class=3DMsoNormal><span lang=3DEN-US =
style=3D'font-size:12.0pt'>&nbsp;&nbsp;&nbsp; =
print*,'LOC(buf)=3D',LOC(buf)<o:p></o:p></span></p><p =
class=3DMsoNormal><span lang=3DEN-US =
style=3D'font-size:12.0pt'>&nbsp;&nbsp;&nbsp; call =
MPI_ALLREDUCE(MPI_IN_PLACE,buf,1,2,3,4,ierror)<o:p></o:p></span></p><p =
class=3DMsoNormal><span lang=3DEN-US =
style=3D'font-size:12.0pt'>&nbsp;&nbsp;&nbsp; =
print*,ierror<o:p></o:p></span></p><p class=3DMsoNormal><span =
lang=3DEN-US style=3D'font-size:12.0pt'>end program =
main<o:p></o:p></span></p></div></body></html>
------=_NextPart_000_01E4_01DA794D.E5960DB0--

