gpt4 book ai didi

c - 在 MPI 中发送/接收 3D 数组

转载 作者:太空宇宙 更新时间:2023-11-04 08:55:14 24 4
gpt4 key购买 nike

我有一个计算代码需要传递一些数组

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 数组作为 一流的语言结构

最佳答案

1) 除了您应该像第二个问题中提到的那样正确传递 3D 数组之外,我在这里没有看到任何问题。

2) How to use MPI derived data type for 3D array?

关于c - 在 MPI 中发送/接收 3D 数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17509920/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com