Parallel processing 使用OpenMPI进行并行编程:程序未运行
所以我对并行编程的范例是相当陌生的。我试图通过索引矩阵从根进程(秩=0)发送到从进程(秩=1)。因此,我使用以下命令来运行它:Parallel processing 使用OpenMPI进行并行编程:程序未运行,parallel-processing,openmpi,Parallel Processing,Openmpi,所以我对并行编程的范例是相当陌生的。我试图通过索引矩阵从根进程(秩=0)发送到从进程(秩=1)。因此,我使用以下命令来运行它: 奥林匹克运动会第九届奥林匹克运动会.c-o第九届奥林匹克运动会 mpirun-np 2./q_9 程序编译成功,但无论如何都不会运行。我感觉MPI_Send()和MPI_Recv()例程没有正确同步。任何形式的帮助都会大有帮助。代码如下: #include <stdio.h> #include <stdlib.h> #include "mpi
- 奥林匹克运动会第九届奥林匹克运动会.c-o第九届奥林匹克运动会
- mpirun-np 2./q_9
#include <stdio.h>
#include <stdlib.h>
#include "mpi.h"
int main(int argc, char *argv[])
{
int curr_rank;
int num_process;
int i;
int j;
int in_matrix[4][4];
int out_matrix[4][4];
int num_rows = 4;
int num_cols = 4;
int displacement_array[4];
int block_length[4];
MPI_Datatype new_index_t;
MPI_Status status;
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &num_process);
MPI_Comm_rank(MPI_COMM_WORLD, &curr_rank);
if(num_process == 2){
if(curr_rank == 0){ /*Root process populates the matrix*/
/*Initialize matrix*/
for(i = 0 ; i < num_rows ; i++){
for(j = 0 ; j < num_cols ; j++){
in_matrix[i][j] = i + j;
}
}
}
for(i = 0 ; i < num_rows ; i++){
displacement_array[i] = (num_rows * i) + num_rows;
block_length[i] = (num_rows - i);
}
MPI_Type_indexed(num_rows, block_length, displacement_array, MPI_INT, &new_index_t);
MPI_Type_commit(&new_index_t);
if(curr_rank == 0){
MPI_Send(in_matrix, 1, new_index_t, 1, 0, MPI_COMM_WORLD);
}
else{
for(i = 0 ; i < num_rows ; i++){
for(j = 0 ; j < num_cols ; j++){
out_matrix[i][j] = 0;
}
}
MPI_Recv(out_matrix, 1, new_index_t, 0, 0, MPI_COMM_WORLD, &status);
/*Indexed output matrix*/
for(i = 0 ; i < num_rows ; i++){
for(j = 0 ; j < num_cols ; j++){
printf("%d ", out_matrix[i][j]);
}
printf("\n");
}
}
}
MPI_Finalize();
}
#包括
#包括
#包括“mpi.h”
int main(int argc,char*argv[])
{
国际货币等级;
int-num_过程;
int i;
int j;
int in_矩阵[4][4];
int out_矩阵[4][4];
int num_rows=4;
int num_cols=4;
int置换_数组[4];
int block_长度[4];
MPI_数据类型新索引;
MPI_状态;
MPI_Init(&argc,&argv);
MPI_通信大小(MPI_通信世界和num_进程);
MPI通信等级(MPI通信世界和当前等级);
if(num_进程==2){
如果(curr_rank==0){/*根进程填充矩阵*/
/*初始化矩阵*/
对于(i=0;i
编辑:
我在另一个系统上运行它,收到一条消息:
由于进程秩0且PID 10449打开,mpirun已退出
节点abhijeet-mohanty-2不正确退出。出现这种情况的原因有三:
由mpirun发送的信号终止(如本文所述)。在我的机器上运行良好。你认为MPI的安装方式会产生问题吗?如果有帮助的话,我正在Ubuntu 14.04上运行它。你错过了程序结束时对
MPI\u Finalize
的调用,否则对我来说很好。@hristoilev添加了MPI\u Finalize()但是没有用。