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/