c - MPI c 中的互通器

标签 c mpi

我只想在有 2 个互通器的 B 组和 C 组之间创建一个互通器。我收到无效通信器错误。我的简单代码哪里有错误?

        #include<stdio.h>
  #include<errno.h>
  #include<stdlib.h>
  #include<string.h>

  #include"mpi.h"

  int main(){
    MPI_Comm a,b,c;
    MPI_Group A,C,B;
    MPI_Comm com1,com2;

    int size ,subsize=3,rank;

    MPI_Init(NULL,NULL);


    a = MPI_COMM_WORLD;

    MPI_Comm_size( a , &size );
    MPI_Comm_rank( a , &rank );


    MPI_Comm_group( a , &A );

    MPI_Comm_group( a , &B );

    MPI_Comm_create(a,B,&b);


    MPI_Group_size(B,&subsize);
    MPI_Group_rank(B,&subsize);


    printf("/////////////////////////////%d\n", MPI_Intercomm_create(a,0,b,1,20,&c));
    MPI_Group_free(&A);
    MPI_Group_free(&B);
    MPI_Comm_free(&a);
    MPI_Comm_free(&b);
    MPI_Comm_free(&c);
    MPI_Finalize();

    printf("END\n");

    return 0;
  }

最佳答案

第二个代码工作正常,但我仍然想知道,是否可以通过(d)通信在(a)和(b)内部通信器之间进行绑定(bind)。

#include<stdio.h>
#include<errno.h>
#include<stdlib.h>
#include<string.h>

#include"mpi.h"

int main(){
  MPI_Comm a,b,c1,c2,d;
  MPI_Group A,C,B;
  MPI_Comm com1,com2;

  int *flg;
  int size ,subsize=3,rank,color;

  MPI_Init(0,0);


  a = MPI_COMM_WORLD;

  MPI_Comm_size( a , &size );
  MPI_Comm_rank( a , &rank );

  color = rank %2;

  MPI_Comm_split(MPI_COMM_WORLD,color,rank,&a);
  MPI_Intercomm_create(a,0,MPI_COMM_WORLD,1-color,20,&c1);

  MPI_Comm_split(MPI_COMM_WORLD,color,rank,&b);
  MPI_Intercomm_create(b,0,MPI_COMM_WORLD,1-color,20,&c2);

 // MPI_Intercomm_create(a,0,b,1,20,&d);

  MPI_Comm_test_inter(a,flg);
  printf(" this comm %d \n",*flg);
  MPI_Comm_free(&a);
  MPI_Comm_free(&b);
//        MPI_Comm_free(&c);

  MPI_Finalize();

  printf("END\n");

  return 0;
}

关于c - MPI c 中的互通器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53496427/

相关文章:

C++ 建议拼写错误的单词

c - MPI 点对点通信到集体通信 : MPI_Scatterv Trouble

c - 构建依赖于另一个静态库的静态库

c++ - 日志功能不当行为!!!有什么线索吗?

c - 帮助使用 c 中的指针、结构体和数组

c++ - MPI 中的简单聊天程序 C++

c - 使用并行处理 MPI 迭代 2D 数组

c++ - EXP的并行化

c++ - MPI - Bsend 用法

c++ - 英特尔 C/C++ 编译器对 Visual Studio 有哪些依赖关系?