0

我有一个程序,比如 g09.x,它可以在共享内存处理器上启用并行执行。

现在我有 8 个内核,我使用 mpi 将其分为两组。对于每个组,我希望他们分别使用 4 个内核执行 g09.x。

有人对如何做到这一点有一些经验或想法吗?

MPI_Group 构造如下,但区域 /* Execute Shared Memory Program */ 仍然留空!

#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;
}
4

0 回答 0