我目前正在通过一些基本的公共和政治生活方案实例,来更新我的记忆(将Pacheco的书记作为指南),但我却陷入一个我不理解的问题。 为了证明归属感,我撰写了以下方案:
#include <stdio.h>
#include <mpi.h>
int main(int argc, char *argv[]) {
int rank, size;
int key;
int *value;
void* extra_arg; /* unused */
/* Broadcast value for sync */
int x;
MPI_Init(&argc,&argv);
MPI_Comm_rank(MPI_COMM_WORLD,&rank);
MPI_Comm_size(MPI_COMM_WORLD,&size);
MPI_Keyval_create(MPI_DUP_FN, MPI_NULL_DELETE_FN,
&key, extra_arg);
if (rank==0) {
*value = 42;
MPI_Attr_put(MPI_COMM_WORLD, key, value);
x=17;
MPI_Bcast(&x,1,MPI_INT,0,MPI_COMM_WORLD);
} else {
MPI_Bcast(&x,1,MPI_INT,0,MPI_COMM_WORLD);
int* newval;
int flag;
MPI_Attr_get(MPI_COMM_WORLD,key,&newval,&flag);
printf("Value = %d
", *newval);
}
MPI_Finalize();
return 0;
}
(该广播仅能防止MPI_Attr_get在播音之前出现)
This, if I m doing it properly, should result in all processes but rank 0 printing "Value = 42 ". What I get, however, if I do "mpirun -np 2 ./a.out", is
[exp:27936] *** Process received signal ***
[exp:27936] Signal: Segmentation fault (11)
[exp:27936] Signal code: Invalid permissions (2)
[exp:27936] Failing at address: 0xb763aff4
[exp:27936] [ 0] [0xf57fe40c]
[exp:27936] [ 1] ./a.out(main+0x74) [0x80488e8]
[exp:27936] [ 2] /lib/libc.so.6(__libc_start_main+0xdc) [0xb74fbe9c]
[exp:27936] [ 3] ./a.out [0x80487c1]
[exp:27936] *** End of error message ***
--------------------------------------------------------------------------
mpirun noticed that process rank 0 with PID 27936 on node exp exited on signal 11 (Segmentation fault).--------------------------------------------------------------------------
我不理解的是,为什么有人eg! 同样错误的发生是,我宣布“新世纪”为主人或内部的顶端,而且只是在消费物价指数_时。 Attr_get is conducted: commenting this out and practice other with newval isvy.
想法?