【发布时间】:2013-07-08 02:38:36
【问题描述】:
我有一个计算代码需要传递一些数组
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 个常量的初始广播之外,我还传递了大约 300x300x300 3D 数组
以及在运行时初始化的多个固定值 3D 数组。会不会像上面这样的设计
工作 ?
2) 如何使用 MPI_Datatypes 传递 3D 数组? C 不支持 3D 数组作为 一流的语言结构
【问题讨论】: