【发布时间】:2016-01-24 06:44:49
【问题描述】:
我想写一段代码: P0 处理器从键盘获取一个数组,并将该数组发送到 P1 处理器。 P1 处理器将所有值打印到屏幕上。例如:
[P0]: Enter the size of array: 1
[P0]: Enter the elements of array: 3
[P1]: The array is: 3
[P0]: Enter the size of array: 3
[P0]: Enter the elements of array: 5 7 5
[P1]: The array is: 5 7 5
.
.
.
这是我的第一部作品。我认为错误太多。但我是新人。想学习如何编码。
#include <stdio.h>
#include <mpi.h>
#define n 100
int main(int argc, char *argv[]){
int my_rank, size_cm;
int value, i;
int dizi[n];
double senddata[n];
double recvdata[n];
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
MPI_Comm_size(MPI_COMM_WORLD, &size_cm);
value=0;
if(my_rank == 0){
printf("[%d]: Enter the size of array: ",&my_rank);
scanf("%d",value);
printf("[%d]: Enter the elements of array",&my_rank);
for(i=0; i<n; i++){
scanf("%d", &dizi[n]);
senddata[0] = dizi[];
MPI_Send(senddata, 1, MPI_INT, 1, 0, MPI_COMM_WORLD);
}
}
if(my_rank == 1){
MPI_Recv(recvdata, 1, MPI_INT, 0, 0, MPI_COMM_WORLD,
printf("[%d]: The array is: %d ",&my_rank, dizi[n]);
}
MPI_Finalize();
return 0;
}
【问题讨论】:
-
你要什么?从你发布的一切看起来它工作正常。请编辑您的帖子。
-
我已尝试正确缩进您的代码,
}在if(my_rank == 1)之前丢失。MPI_Recv缺少一个参数
标签: c parallel-processing mpi communication