<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<!--[if !mso]><style>v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style><![endif]--><style><!--
/* Font Definitions */
@font-face
        {font-family:Helvetica;
        panose-1:0 0 0 0 0 0 0 0 0 0;}
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        font-size:12.0pt;
        font-family:"Calibri",sans-serif;}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
p.p1, li.p1, div.p1
        {mso-style-name:p1;
        margin:0in;
        font-size:8.5pt;
        font-family:Helvetica;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:12.0pt;
        font-family:"Calibri",sans-serif;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style>
</head>
<body lang="EN-US" link="#0563C1" vlink="#954F72" style="word-wrap:break-word">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt">Hi All,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">In porting an MPI application written mainly in Fortran and a little c to using mpi_f08 rather than mpi, I’ve hit an issue.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">Namely, how would I write example 19.11 in the MPI 4 standard if the app uses type(MPI_Type) rather than integer?<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">Note I’m working with an application, so the MPI_Type structure is opaque, or at least I thought we’re supposed to treat it as opaque.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">Here’s the example:<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="p1">Example 19.11 The example below illustrates how the Fortran MPI function<o:p></o:p></p>
<p class="p1">MPI_TYPE_COMMIT can be implemented by wrapping the C MPI function<o:p></o:p></p>
<p class="p1">MPI_Type_commit with a C wrapper to do handle conversions. In this example a Fortran-C<o:p></o:p></p>
<p class="p1">interface is assumed where a Fortran function is all upper case when referred to from C and<o:p></o:p></p>
<p class="p1">arguments are passed by addresses.<o:p></o:p></p>
<p class="p1">! FORTRAN PROCEDURE<o:p></o:p></p>
<p class="p1">SUBROUTINE MPI_TYPE_COMMIT(DATATYPE, IERR)<o:p></o:p></p>
<p class="p1">INTEGER :: DATATYPE, IERR<o:p></o:p></p>
<p class="p1">CALL MPI_X_TYPE_COMMIT(DATATYPE, IERR)<o:p></o:p></p>
<p class="p1">RETURN<o:p></o:p></p>
<p class="p1">END<o:p></o:p></p>
<p class="p1">/* C wrapper */<o:p></o:p></p>
<p class="p1">void MPI_X_TYPE_COMMIT(MPI_Fint *f_handle, MPI_Fint *ierr)<o:p></o:p></p>
<p class="p1">{<o:p></o:p></p>
<p class="p1">MPI_Datatype datatype;<o:p></o:p></p>
<p class="p1">datatype = MPI_Type_f2c(*f_handle);<o:p></o:p></p>
<p class="p1">*ierr = (MPI_Fint)MPI_Type_commit(&datatype);<o:p></o:p></p>
<p class="p1">*f_handle = MPI_Type_c2f(datatype);<o:p></o:p></p>
<p class="p1">return;<o:p></o:p></p>
<p class="p1">}<o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">Now I suspect that most of the time if one has some old ‘c’ code assuming a pointer to a 4 byte fortran integer argument for the datatype is just going to work, but I’d rather not just try to be lucky.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">Anyway, there are fortran gurus on this project and they’d be sure to want a better solution.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">Thanks for any help/ideas,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">Howard<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Arial",sans-serif;color:#0B1A8D"><br>
—</span><span style="font-size:11.0pt"><o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Arial",sans-serif;color:#0B1A8D"><o:p> </o:p></span></p>
<table class="MsoNormalTable" border="0" cellspacing="0" cellpadding="0" width="375" style="width:281.25pt;border-collapse:collapse">
<tbody>
<tr style="height:104.45pt">
<td width="78" valign="top" style="width:58.4pt;padding:0in 5.4pt 0in 5.4pt;height:104.45pt">
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Arial",sans-serif"><img width="55" height="55" style="width:.5729in;height:.5729in" id="Picture_x0020_5" src="cid:image001.png@01D798F3.0B910FD0" alt="signature_61897647"><o:p></o:p></span></p>
</td>
<td width="297" valign="top" style="width:223.1pt;padding:0in 5.4pt 0in 5.4pt;height:104.45pt">
<p class="MsoNormal"><b><span style="font-family:"Arial",sans-serif;color:#0B1A8C">Howard Pritchard<o:p></o:p></span></b></p>
<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:"Arial",sans-serif;color:#545961">Research Scientist<o:p></o:p></span></b></p>
<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:"Arial",sans-serif;color:#545961">HPC-ENV<o:p></o:p></span></b></p>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Arial",sans-serif"><o:p> </o:p></span></p>
<p class="MsoNormal"><b><span style="font-size:9.0pt;font-family:"Arial",sans-serif;color:#0B1A8C">Los Alamos National Laboratory<o:p></o:p></span></b></p>
<p class="MsoNormal"><b><span style="font-size:9.0pt;font-family:"Arial",sans-serif;color:#0B1A8C">howardp@lanl.gov<o:p></o:p></span></b></p>
<p class="MsoNormal"><b><span style="font-size:9.0pt;font-family:"Arial",sans-serif;color:#0B1A8C"><o:p> </o:p></span></b></p>
<p class="MsoNormal"><a href="https://www.instagram.com/losalamosnatlab/"><b><span style="font-size:9.0pt;font-family:"Arial",sans-serif;color:#0B1A8C;text-decoration:none"><img border="0" width="27" height="27" style="width:.2812in;height:.2812in" id="Picture_x0020_4" src="cid:image002.png@01D798F3.0B910FD0" alt="signature_577235141"></span></b></a><a href="https://twitter.com/LosAlamosNatLab"><b><span style="font-size:9.0pt;font-family:"Arial",sans-serif;color:#0B1A8C;text-decoration:none"><img border="0" width="27" height="27" style="width:.2812in;height:.2812in" id="Picture_x0020_3" src="cid:image003.png@01D798F3.0B910FD0" alt="signature_692833302"></span></b></a><a href="https://www.linkedin.com/company/los-alamos-national-laboratory/"><b><span style="font-size:9.0pt;font-family:"Arial",sans-serif;color:#0B1A8C;text-decoration:none"><img border="0" width="27" height="27" style="width:.2812in;height:.2812in" id="Picture_x0020_2" src="cid:image004.png@01D798F3.0B910FD0" alt="signature_2019430084"></span></b></a><a href="https://www.facebook.com/LosAlamosNationalLab/"><b><span style="font-size:9.0pt;font-family:"Arial",sans-serif;color:#0B1A8C;text-decoration:none"><img border="0" width="27" height="27" style="width:.2812in;height:.2812in" id="Picture_x0020_1" src="cid:image005.png@01D798F3.0B910FD0" alt="signature_231667440"></span></b></a><b><span style="font-size:9.0pt;font-family:"Arial",sans-serif;color:#0B1A8C"><o:p></o:p></span></b></p>
</td>
</tr>
</tbody>
</table>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Arial",sans-serif"><o:p> </o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</body>
</html>