On Thu, Feb 4, 2016 at 12:28 PM, Jeff Squyres (jsquyres) <jsquy...@cisco.com>
wrote:
>
> On Feb 4, 2016, at 12:02 PM, Brian Taylor <spam.brian.tay...@gmail.com>
wrote:
> >
> > I have a question about the standards compliance of OpenMPI.  Is the
following program valid according to the MPI standard?
> >
> > #include <stdio.h>
> > #include <mpi.h>
> >
> > int main(int argc, char **argv)
> > {
> >   int rank;
> >   double in[2], out[2];
> >
> >   MPI_Init(&argc, &argv);
> >   MPI_Comm_rank(MPI_COMM_WORLD, &rank);
> >
> >   in[1] = in[0] = (double) rank;
> >
> >   MPI_Reduce(in, out, 1, MPI_2DOUBLE_PRECISION, MPI_MAXLOC, 0,
MPI_COMM_WORLD);
>
> Technically, this isn't correct.
>
> The MPI_2DOUBLE_PRECISION type is for Fortran data, not C data.  And
there is no guarantee that the size and representation of C "double" is
equivalent to that of Fortran "double precision".  So while it may work in
some cases, it may not work in all cases.
>
> Sidenote: the reason that you can use MPI_2DOUBLE_PRECISION (and there's
no corresponding MPI_2DOUBLE for C datatypes) with MINLOC/MAXLOC is because
until "recently", you couldn't easily have a fortran equivalent of
>
> struct {
>     double a;
>     int b;
> };
>
> Instead, all you could do was pass in arrays that were homogeneous in
type -- e.g., a pair of doubles, or a pair of integers, or reals.  Since
half the output of MINLOC/MAXLOC is to give an (integer) array index, in C,
it makes sense to have that value actually be of type "int".  But in
Fortran, it was simple to just have a pair of homogeneous types (integer,
real, double).
>
> This is not true in modern fortran, however.  FWIW, tere's a low-priority
proposal cooking in the MPI Forum to add Fortran equivalents for the C
MPI_FLOAT_INT, MPI_DOUBLE_INT, MPI_LONG_INT, ...etc. types for
MINLOC/MAXLOC.
>
> >   if (rank == 0) printf("out = %f %f\n", out[0], out[1]);
> >
> >   MPI_Finalize();
> >
> >   return 0;
> > }
> >
> > Specifically, I am wondering if MPI_2DOUBLE_PRECISION can be used with
MPI_MAXLOC (or MPI_MINLOC) in a C program.  MPI_2DOUBLE_PRECISION is not
included in the list of datatypes for reduction functions in C in Appendix
A.1 of the MPI 3.1 standard, although it is included in the list of
reduction functions for Fortran.  What exactly does that mean?
> >
> > The program above runs with OpenMPI 1.10.2 and gives the output one
would expect for an equivalent program written in Fortran.  Can I rely on
this being portable to other MPI implementations?
> >
> > Thanks,
> > Brian
> > _______________________________________________
> > users mailing list
> > us...@open-mpi.org
> > Subscription: http://www.open-mpi.org/mailman/listinfo.cgi/users
> > Link to this post:
http://www.open-mpi.org/community/lists/users/2016/02/28448.php
>
>
> --
> Jeff Squyres
> jsquy...@cisco.com
> For corporate legal information go to:
http://www.cisco.com/web/about/doing_business/legal/cri/
>
> _______________________________________________
> users mailing list
> us...@open-mpi.org
> Subscription: http://www.open-mpi.org/mailman/listinfo.cgi/users
> Link to this post:
http://www.open-mpi.org/community/lists/users/2016/02/28449.php


Thanks for the explanation, Jeff.  I'm not surprised to hear that using a
Fortran type from C in this manner is potentially buggy and not portable.
However, assuming that the C and Fortran types are interoperable, is there
any guarantee that the call to MPI_Reduce in the program above will execute
successfully?

If OpenMPI 1.10.2 is built with Fortran support, the program above runs and
gives the expected output.  If OpenMPI 1.10.2 is built without Fortran
support, the program exits with the following error:

taylor@host $ mpirun -np 1 ./bug
[host:49234] *** An error occurred in MPI_Reduce: the reduction operation
MPI_MAXLOC is not defined on the MPI_2DBLPREC datatype
[host:49234] *** reported by process [3133079553,0]
[host:49234] *** on communicator MPI_COMM_WORLD
[host:49234] *** MPI_ERR_OP: invalid reduce operation
[host:49234] *** MPI_ERRORS_ARE_FATAL (processes in this communicator will
now abort,
[host:49234] ***    and potentially your MPI job)

It seems that the MPI_MAXLOC operator for MPI_2DOUBLE_PRECISION is not
available if OpenMPI is built without Fortran support; thus, the call to
MPI_Reduce fails.  Is this the expected behavior?  Is the MPI_MAXLOC
operator for MPI_2DOUBLE_PRECISION required to be available from C for
compliance with the MPI standard, or is its availability from C in OpenMPI
(when built with Fortran support) an implementation-dependent "extension"?

Thanks,
Brian

Reply via email to