我有一个程序,比如g09.x,它可以在共享内存处理器上启用并行执行。
现在我有8个核心,我用mpi将它分成两组。 对于每个组,我希望它们分别使用4个核心执行g09.x.
有没有人对如何做到这一点有经验或想法?
MPI_Group正在构建如下,但区域/ *执行共享内存程序* /仍然留空!
#include "mpi.h"
#include <stdio.h>
int main (int argc, char *argv[])
{
int rank, group_rank, numtasks, group_size, rc,
group1[4]={0,1,2,3},
group2[4]={4,5,6,7};
MPI_Group orig_group, new_group;
MPI_Comm group_comm;
rc = MPI_Init(&argc, &argv);
if (rc !=0){
printf("MPI_aborted\n");
MPI_Abort(MPI_COMM_WORLD, rc);
}
MPI_Comm_size(MPI_COMM_WORLD, &numtasks);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
/* Extract the original group handle */
MPI_Comm_group(MPI_COMM_WORLD, &orig_group);
/* Divide tasks into two distinct groups based upon rank */
if (rank < 4){
MPI_Group_incl(orig_group, 4, group1, &new_group);
}
else {
MPI_Group_incl(orig_group, 4, group2, &new_group);
}
/* Create new communicator */
MPI_Comm_create(MPI_COMM_WORLD, new_group, &group_comm);
MPI_Group_size(new_group, &group_size);
MPI_Group_rank(new_group, &group_rank);
printf("rank=%d, group_rank=%d, numtasks=%d, group_size=%d\n", rank, group_rank, numtasks, group_size);
/* Do Something */
/* Execute Shared Memory Program */
MPI_Finalize();
return 0;
}