我只想在有 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/