<div dir="ltr"><p style="color:rgb(0,0,0);font-family:Verdana,Arial,'Bitstream Vera Sans',Helvetica,sans-serif;font-size:13px">To strictly obey MPI standard, we should declare MPI_2INT's type attribute as<br></p>
<pre class="" style="background-color:rgb(247,247,247);border:1px solid rgb(215,215,215);border-top-left-radius:0.3em;border-top-right-radius:0.3em;border-bottom-right-radius:0.3em;border-bottom-left-radius:0.3em;margin-right:1.75em;margin-left:1.75em;padding:0.25em;overflow:auto;color:rgb(0,0,0);font-size:13px">
typedef int mpich_array_mpi_2int[2];  
static const MPI_Datatype mpich_mpi_2int   MPICH_ATTR_TYPE_TAG_LAYOUT_COMPATIBLE (mpich_array_mpi_2int) = MPI_2INT;
</pre><p style="color:rgb(0,0,0);font-family:Verdana,Arial,'Bitstream Vera Sans',Helvetica,sans-serif;font-size:13px">Then, users should write code as follows:<br></p><pre class="" style="background-color:rgb(247,247,247);border:1px solid rgb(215,215,215);border-top-left-radius:0.3em;border-top-right-radius:0.3em;border-bottom-right-radius:0.3em;border-bottom-left-radius:0.3em;margin-right:1.75em;margin-left:1.75em;padding:0.25em;overflow:auto;color:rgb(0,0,0);font-size:13px">
typedef int int2[2];
int2 in, out;
...
MPI_Reduce(&in, &out, 1, MPI_2INT, MPI_MAXLOC, ...);
</pre><p style="color:rgb(0,0,0);font-family:Verdana,Arial,'Bitstream Vera Sans',Helvetica,sans-serif;font-size:13px">It is inconvenient. After testing the code, I found the compiler warning disappears. But if we change the code into<br>
</p><pre class="" style="background-color:rgb(247,247,247);border:1px solid rgb(215,215,215);border-top-left-radius:0.3em;border-top-right-radius:0.3em;border-bottom-right-radius:0.3em;border-bottom-left-radius:0.3em;margin-right:1.75em;margin-left:1.75em;padding:0.25em;overflow:auto;color:rgb(0,0,0);font-size:13px">
int in[2], out[2]
MPI_Reduce(in, out, 2, MPI_2INT, MPI_MAXLOC, ...);

OR

struct {int value; int loc; } in, out;
MPI_Reduce(&in, &out, 1, MPI_2INT, MPI_MAXLOC, ...);
</pre><p style="color:rgb(0,0,0);font-family:Verdana,Arial,'Bitstream Vera Sans',Helvetica,sans-serif;font-size:13px">The warning happens again. In reality, struct {int value; int loc; } should have the same layout as int<a class="" title="No changeset 2 in the repository" style="color:rgb(153,153,136)">[2]</a>. In this sense, the current MPI_2INT handling in MPICH is fine. The warning reflects the compiler's weakness rather than a fault in MPICH code. </p>
</div><div class="gmail_extra"><br clear="all"><div><div dir="ltr">--Junchao Zhang</div></div>
<br><br><div class="gmail_quote">On Mon, Dec 23, 2013 at 10:55 AM, Markus Geimer <span dir="ltr"><<a href="mailto:m.geimer@fz-juelich.de" target="_blank">m.geimer@fz-juelich.de</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi,<br>
<div class="im"><br>
>   I guess the warning has nothing to do with padding.<br>
<br>
</div>Agreed. The warning is due to the type_tag attributes defined in<br>
MPICH's 'mpi.h' header file.<br>
<div class="im"><br>
> For MPI_Reduce(in, out, 1, MPI_2INT, ...), the compiler tries to<br>
> match int, i.e., typeof(*in), with MPI_2INT.  Whatever the layout of<br>
> MPI_2INT is defined (e.g., struct {int i1; int i2} or int[2]), the<br>
> compiler fails at matching. If you want to use MPI_2INT, then in, out<br>
> should be defined as of type struct {int v1;  int v2}.<br>
<br>
</div>Well, according to the C99 standard "Each non-bit-field member of a<br>
structure or union object is aligned in an *implementation-defined*<br>
manner appropriate to its type." (§6.7.2.1) It is therefore not<br>
guaranteed that the two ints in the struct are contiguous -- which<br>
means that, strictly speaking, int[2] is the only portable choice.<br>
(Although I'm not aware of any compiler that would insert padding<br>
between the two ints, i.e., in practice the struct should be fine,<br>
too.)<br>
<div class="im"><br>
>   I agree that MPI_Reduce(in, out, 1, MPI_2INT, ...) is absolutely<br>
> right.  I think the only reason for the warning is that the compiler is<br>
> not smart enough.<br>
<br>
</div>Compilers could always be smarter ;-) It would be great if you could<br>
come up with a datatype that is -- from the compiler's perspective --<br>
compatible with both struct {int i1; int i2} and int[2]. Otherwise,<br>
I suggest to remove the type check for MPI_2INT as the warning is<br>
misleading.<br>
<br>
Thanks,<br>
Markus<br>
<div class="im HOEnZb"><br>
<br>
> On Sun, Dec 22, 2013 at 3:56 AM, Markus Geimer <<a href="mailto:m.geimer@fz-juelich.de">m.geimer@fz-juelich.de</a><br>
</div><div class="HOEnZb"><div class="h5">> <mailto:<a href="mailto:m.geimer@fz-juelich.de">m.geimer@fz-juelich.de</a>>> wrote:<br>
><br>
>     Dear MPICH developers,<br>
><br>
>     When compiling the attached example with MPICH 3.1rc2 using Clang 3.3,<br>
>     I get the following compiler warnings:<br>
><br>
>     -------------------- snip --------------------<br>
>     mpi2int.c:17:20: warning: argument type 'int *' doesn't match specified<br>
>     'MPI' type tag [-Wtype-safety]<br>
>         MPI_Reduce(in, out, 1, MPI_2INT, MPI_MAXLOC, 0, MPI_COMM_WORLD);<br>
>                        ^~~     ~~~~~~~~<br>
>     mpi2int.c:17:16: warning: argument type 'int *' doesn't match specified<br>
>     'MPI' type tag [-Wtype-safety]<br>
>         MPI_Reduce(in, out, 1, MPI_2INT, MPI_MAXLOC, 0, MPI_COMM_WORLD);<br>
>                    ^~          ~~~~~~~~<br>
>     2 warnings generated.<br>
>     -------------------- snip --------------------<br>
><br>
>     According to the MPI standard, however, MPI_2INT is a datatype as if<br>
>     defined by<br>
><br>
>             MPI_Type_contiguous(2, MPI_INT, MPI_2INT)<br>
><br>
>     i.e., 'int[2]' should be a perfect match. This is not necessarily true<br>
>     for the type used for comparison,<br>
><br>
>             struct mpich_struct_mpi_2int { int i1; int i2; };<br>
><br>
>     which will only be contiguous if the compiler does not add any padding.<br>
><br>
>     Is there any chance this gets fixed for the final 3.1 release? Or did<br>
>     I miss something?<br>
><br>
>     Thanks,<br>
>     Markus<br>
><br>
<br>
--<br>
Dr. Markus Geimer<br>
Juelich Supercomputing Centre<br>
Institute for Advanced Simulation<br>
Forschungszentrum Juelich GmbH<br>
52425 Juelich, Germany<br>
<br>
Phone:  +49-2461-61-1773<br>
Fax:    +49-2461-61-6656<br>
E-mail: <a href="mailto:m.geimer@fz-juelich.de">m.geimer@fz-juelich.de</a><br>
WWW:    <a href="http://www.fz-juelich.de/jsc/" target="_blank">http://www.fz-juelich.de/jsc/</a><br>
<br>
<br>
------------------------------------------------------------------------------------------------<br>
------------------------------------------------------------------------------------------------<br>
Forschungszentrum Juelich GmbH<br>
52425 Juelich<br>
Sitz der Gesellschaft: Juelich<br>
Eingetragen im Handelsregister des Amtsgerichts Dueren Nr. HR B 3498<br>
Vorsitzender des Aufsichtsrats: MinDir Dr. Karl Eugen Huthmacher<br>
Geschaeftsfuehrung: Prof. Dr. Achim Bachem (Vorsitzender),<br>
Karsten Beneke (stellv. Vorsitzender), Prof. Dr.-Ing. Harald Bolt,<br>
Prof. Dr. Sebastian M. Schmidt<br>
------------------------------------------------------------------------------------------------<br>
------------------------------------------------------------------------------------------------<br>
<br>
_______________________________________________<br>
discuss mailing list     <a href="mailto:discuss@mpich.org">discuss@mpich.org</a><br>
To manage subscription options or unsubscribe:<br>
<a href="https://lists.mpich.org/mailman/listinfo/discuss" target="_blank">https://lists.mpich.org/mailman/listinfo/discuss</a><br>
</div></div></blockquote></div><br></div>