Funktionsübersicht
Hilfesystem für den Message Passing Interface Standard MPI
Beispiel
/* Wählt die Prozesse 1, 2, 4 und 5 aus und bildet aus ihnen einen
* neuen Kommunikator /*
#include "mpi.h"
#include <stdio.h>
#define MAX 4
int main(int argc, char *argv[]) {
int comm_me, newcomm_me, numprocs, n;
MPI_Comm newcomm;
MPI_Group group, newgroup;
int ranks[MAX];
if (MPI_Init(&argc, &argv)!=MPI_SUCCESS) {
fprintf( stderr,"MPI_Init failed.\n");
}
MPI_Comm_rank(MPI_COMM_WORLD, &comm_me);
MPI_Comm_size(MPI_COMM_WORLD, &numprocs);
if (numprocs<6) {
fprintf(stderr,"Program needs at least 6 processes.\n");
MPI_Finalize();
return -1;
}
MPI_Comm_group(MPI_COMM_WORLD, &group);
ranks[0]=1;
ranks[1]=2;
ranks[2]=4;
ranks[3]=5;
n=MAX;
MPI_Group_incl(group, n, ranks, &newgroup);
MPI_Comm_create(MPI_COMM_WORLD, newgroup, &newcomm);
if (newcomm!=MPI_COMM_NULL) {
MPI_Comm_rank(newcomm, &newcomm_me);
fprintf(stderr,"Proc %d: in newcomm %d\n", comm_me,
newcomm_me);
MPI_Barrier(newcomm);
MPI_Comm_free(&newcomm);
}
MPI_Group_free(&newgroup);
MPI_Finalize();
}