MPIC中的对讲机

MPIC中的对讲机,c,mpi,C,Mpi,我只想在两个组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; MP

我只想在两个组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;
  }
#包括
#包括
#包括
#包括
#包括“mpi.h”
int main(){
MPI_通信a、b、c;
MPI_A、C、B组;
MPI_通信com1、com2;
整数大小,子集=3,秩;
MPI_Init(NULL,NULL);
a=MPI_通信世界;
MPI通信大小(a和大小);
MPI通信秩(a和秩);
MPI通信组(a和a);
MPI通信组(a和B);
MPI通信创建(a、B和B);
MPI\u组大小(B和子组);
MPI组排名(B和子公司);
printf(“//%d\n”,MPI\u内部通信创建(a、0、b、1、20和c));
无MPI组(A);
无MPI组(&B);
MPI_通信免费(&a);
MPI_通信免费(&b);
MPI_通信免费(&c);
MPI_Finalize();
printf(“END\n”);
返回0;
}

这段代码运行良好,但我仍然想知道,是否可以通过(d)通信在(a)和(b)通信者之间绑定

#包括
#包括
#包括
#包括
#包括“mpi.h”
int main(){
MPI通信a、b、c1、c2、d;
MPI_A、C、B组;
MPI_通信com1、com2;
int*flg;
整型大小,子版=3,等级,颜色;
MPI_Init(0,0);
a=MPI_通信世界;
MPI通信大小(a和大小);
MPI通信秩(a和秩);
颜色=排名%2;
MPI_Comm_split(MPI_Comm_WORLD、color、rank和a);
MPI_Intercom_创建(a、0、MPI_COMM_WORLD、单色、20和c1);
MPI_通信分割(MPI_通信世界、颜色、等级和b);
MPI_Intercom_创建(b、0、MPI_COMM_WORLD、单色、20和c2);
//创建MPI(a、0、b、1、20和d);
MPI通信测试接口(a、flg);
printf(“此命令%d\n”,*flg);
MPI_通信免费(&a);
MPI_通信免费(&b);
//MPI_通信免费(&c);
MPI_Finalize();
printf(“END\n”);
返回0;
}

b
在未初始化的情况下使用,您的代码甚至不会编译。为什么不干脆
MPI\u Comm\u split()
来生成内部通讯器
a
b
?(请阅读此处您不需要
MPI_Group
)因为我必须创建一个函数,该函数可以对进程进行大量拆分或集群,我想最好使用这种方法创建MPI_内部通信(b,0,a,0,20,c);将其更改为MPI_Intercom_create(b、0、a、0、20和c);首先,您应该使用可编译且没有未初始化变量的代码编辑问题。请毫不犹豫地解释你认为最好这样做的理由。20只是一对沟通者之间的标签,还有,我怎样才能重新编辑我的代码?你到底想实现什么?你可以简单地用你所有的(预期的)交流者(包括内部和外部)做一个草图,然后上传一张照片。
#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;
}