Method MPI.Op_create()


Method Op_create

Op Op_create(function(object, object:void) ufun, int commute)

Description

Creates a user-defined MPI operation.

Parameter ufun

The function that implements the MPI.Op to be created.

Parameter commute

Set to 1 if the operation commutes.

Example

void my_add_fun(object invec, object outvec) { for (int i = 0; i < sizeof(outvec); i++) { outvec[i] += invec[i]; }

int main() { MPI.Op myadd; MPI.IntArray ia = MPI.IntArray(10), results;

MPI.Init();

myadd = MPI.Op_create(my_add_fun, 1);

for (int i = 0; i < sizeof(ia); i++) ia[i] = random(1000);

if (!MPI.world->rank) results = MPI.IntArray(sizeof(ia)); MPI.world->Reduce(ia, results, 0); if (!MPI.world->rank) for (int i; i < sizeof(results); i++) write("%02d: %d\n", i, results[i]);

MPI.Finalize(); return 0; }

Note

User-defined MPI operations may not call any MPI operations themselves.

See also

MPI.Comm->Reduce(), MPI_Op_create(3)