Moni
Moni

Reputation: 39

MPI_MAXLOC for an array of double values

What is the data structure used to store the return value of MPI_MAXLOC in MPI_Reduce() function for an array of double values

Upvotes: 0

Views: 421

Answers (1)

Gilles Gouaillardet
Gilles Gouaillardet

Reputation: 8395

in C, the MPI type you must use is MPI_DOUBLE_INT, and there is no predefined C structure for that (e.g you have to create it manually) like this

struct { 
    double val; 
    int   rank; 
}; 

fwiw, the predefined MPI_DOUBLE_INT datatype is defined like this

type[0] = MPI_DOUBLE
type[1] = MPI_INT 
disp[0] = 0 
disp[1] = sizeof(double) 
block[0] = 1 
block[1] = 1 
MPI_TYPE_CREATE_STRUCT(2, block, disp, type, MPI_DOUBLE_INT) 

note that in Fortran, you have to use MPI_2DOUBLE_PRECISION (and yes, the index is a double precision in Fortran !)

this is explained in http://mpi-forum.org/docs/mpi-3.1/mpi31-report/node114.htm#Node114 and there is even an example with double for both C and Fortran

Upvotes: 2

Related Questions