我有一个需要传递一些数组的计算代码
int main()
{
//...
//..Allocating many 3D,1D arrays and initializing fixed-value arrays
//..Initializing named constants here at compile time
//..initializing other constants at run time (not changed during the program runtime)
//...
for(int n=0;n<=1000;n++){
func1(); //Needs some 3D arrays to modify, some fixed-value arrays and lots of constants
func2(); //Same here
func3(); //Same here
}
//.. Data saving routines
return 0;
}
我正在考虑将它拆分成这样的 MPI 程序
//Allocate all of the arrays
MPI_Comm_rank(MPI_Comm_World,&rank);
if(rank==0){
//Initialize all of the arrays and named constants
MPI_Bcast(); //Broadcasting all the constants and fixed-value arrays needed
MPI_ISend();//Send 3D arrays needed by func1()
MPI_ISend();//Send 3D arrays needed by func2()
MPI_ISend();//Send 3D arrays needed by func3()
MPI_IRecv();//Receive modified 3D arrays from func1()
MPI_IRecv();//Receive modified 3D arrays from func2()
MPI_IRecv();//Receive modified 3D arrays from func3()
MPI_Wait(); //For all responses to come in
}
for(int n=0;n<=1000;n++){
if(rank==1){
MPI_Recv();//Receive broadcast of constants and fixed value arraysfrom master
MPI_IRecv(); //Receive 3D arrays from master
func1(); //Modify 3D arrays
MPI_ISend(); //Send modified arrays back to master
}
else if(rank==2){
//Similar code
}
else if(rank==3){
//Similar code
}
}
MPI_Finalize();
我有两个问题: 1)除了
在运行时初始化
的 30 个常量和多个固定值 3D 数组的初始广播之外,我还传递了大约 300x300x300 个 3D 数组。
像上面这样的设计会起作用吗?
2) 如何使用 MPI_Datatypes 传递 3D 数组?C 不支持将 3D 数组作为第一类语言结构