Tag: mpi

使用MPI_Allgather分发结构

我必须使用MPI_Allgather()将结构发送到所有进程。 我似乎没有任何明显的错误,但代码不起作用。 当我检查我是否在recv[]收到任何值时,它都没有显示。 如果我只使用类似的代码发送单个变量而不是结构,那么这是有效的,所以我不确定发生了什么。 该结构具有静态数组,因此内存应该是连续的,或者我应该使用MPI_Pack还是其他东西? 这是代码: #include #include #include “mpi.h” #define NUMEL 21 struct mystruct{ int sendarray[10]; int a; char array2[10]; }; typedef struct mystruct struct_t; int main (int argc, char ** argv) { MPI_Status status; int rank, size; char *recv; int i, j; MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &size); // init struct_t * fd […]

MPI_Isend和MPI_Irecv似乎导致死锁

我在MPI中使用非阻塞通信在进程之间发送各种消息。 但是,我似乎陷入了僵局。 我使用PADB( 请参阅此处 )查看消息队列并获得以下输出: 1:msg12: Operation 1 (pending_receive) status 0 (pending) 1:msg12: Rank local 4 global 4 1:msg12: Size desired 4 1:msg12: tag_wild 0 1:msg12: Tag desired 16 1:msg12: system_buffer 0 1:msg12: Buffer 0xcaad32c 1:msg12: ‘Receive: 0xcac3c80’ 1:msg12: ‘Data: 4 * MPI_FLOAT’ — 1:msg32: Operation 0 (pending_send) status 2 (complete) 1:msg32: Rank local 4 […]

MPI发送数组数组

好的,所以我试图通过MPI发送这样的结构 struct BColumns { double **B; int offset; }; 如果我只是像这样做一些BS分配数据 bSet.offset = myRank; bSet.B = (double **) calloc(2, sizeof(double *)); bSet.B[0] = (double *) calloc(1, sizeof(double)); bSet.B[1] = (double *) calloc(1, sizeof(double)); bSet.B[0][0] = 1; bSet.B[1][0] = 2; if(myRank == 0){ MPI_Send(&bSet,sizeof(struct BColumns), MPI_BYTE, 1, 1, MPI_COMM_WORLD); }else{ MPI_Recv(&recvBuf, sizeof(struct BColumns), MPI_BYTE, MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, […]

如何在MPI中传递2D数组并使用C语言创建动态标记值?

我是MPI编程的新手。 我有一个8乘10的数组,我需要用来平行地找到每一行的总和。 在等级0(过程0)中,它将使用二维arrays生成8乘10的矩阵。 然后我会使用tag号作为数组的第一个索引值(行号)。 这样,我可以使用唯一的缓冲区通过Isend发送。 但是,看起来我的Isend标签号生成方法不起作用。 您能否查看以下代码并告诉我是否正确传递2D数组和标签号。 当我运行此代码时,它会在执行runnk 1后停止并等待。 我在本例中使用了3个进程并使用命令mpirun -np 3 test请尽可能通过示例告诉我如何解决此问题。 #include “mpi.h” #include #include int main (int argc, char *argv[]) { MPI_Init(&argc, &argv); int world_rank; MPI_Comm_rank(MPI_COMM_WORLD, &world_rank); int world_size; MPI_Comm_size(MPI_COMM_WORLD, &world_size); int tag = 1; int arr[8][10]; MPI_Request request; MPI_Status status; int source = 0; int dest; printf (“\n–Current Rank: %d\n”, world_rank); […]

使用MPI_Type_create_subarray发送时可以转置数组吗?

我试图在C中使用MPI转置矩阵。每个进程都有一个方形子矩阵,我想将它发送到正确的进程(网格上的“对面”),将其转换为通信的一部分。 我正在使用MPI_Type_create_subarray ,它有一个订单参数,分别是行主要和列主要的MPI_ORDER_C或MPI_ORDER_FORTRAN 。 我认为,如果我作为其中一个发送,并作为另一个接收,那么我的矩阵将被转换为通信的一部分。 然而,这似乎并没有发生 – 它只是保持非转置。 代码的重要部分如下所示,整个代码文件都可以在这个要点中找到 。 有没有人有任何想法为什么这不起作用? 这种方法是否应该进行转置工作? 我已经想过,在阅读了MPI_ORDER_C和MPI_ORDER_FORTRAN的描述MPI_ORDER_FORTRAN ,但也许没有。 /* ———– DO TRANSPOSE ———– */ /* Find the opposite co-ordinates (as we know it’s a square) */ coords2[0] = coords[1]; coords2[1] = coords[0]; /* Get the rank for this process */ MPI_Cart_rank(cart_comm, coords2, &rank2); /* Send to these new coordinates […]

MPI_Waitall失败了

我想知道是否有人可以为我阐明MPI_Waitallfunction。 我有一个程序使用MPI_Isend和MPI_Irecv传递信息。 完成所有发送和接收后,程序中的一个进程(在本例中为进程0)将打印一条消息。 我的Isend / Irecv正在工作,但是该消息在程序中的某个随机点打印出来; 所以我试图使用MPI_Waitall等到所有请求都完成后再打印消息。 我收到以下错误消息: Fatal error in PMPI_Waitall: Invalid MPI_Request, error stack: PMPI_Waitall(311): MPI_Waitall(count=16, req_array=0x16f70d0, status_array=0x16f7260) failed PMPI_Waitall(288): The supplied request in array element 1 was invalid (kind=0) 这是一些相关的代码: MPI_Status *status; MPI_Request *request; MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &taskid); MPI_Comm_size(MPI_COMM_WORLD, &numtasks); status = (MPI_Status *) malloc(numtasks * sizeof(MPI_Status)); request = (MPI_Request *) malloc(numtasks […]

ld:对符号’log2 @@ GLIBC_2.2.5’的未定义引用

什么错了 for (level = 1; level <= log2((double)size); level++) ^ 看起来像使用log2()但有什么不对? 我实际上正在使用它与OpenMPI代码,但注释这一行修复了一些事情。 完整来源 ( http://pastie.org/7559178 )见第40行 [jiewmeng@JM Assign3]$ mpicc -o cpi cpi.c && mpirun -np 16 cpi /usr/bin/ld: /tmp/cca9x4he.o: undefined reference to symbol ‘log2@@GLIBC_2.2.5’ /usr/bin/ld: note: ‘log2@@GLIBC_2.2.5’ is defined in DSO /usr/lib/libm.so.6 so try adding it to the linker command line /usr/lib/libm.so.6: could not read […]

2D数组和malloc的MPI_Scatter

我正在尝试使用MPI库在C中编写程序,其中主进程创建一个2D数组并将其行分配给其他进程。 矩阵具有维度p*p ,其中p是处理的数量。 这是代码: #include #include #include #include int **createMatrix (int nrows, int ncols) { int **matrix; int h, i, j; if (( matrix = malloc(nrows*sizeof(int*))) == NULL) { printf(“Malloc error”); exit(1); } for (h=0; h<nrows; h++) { if (( matrix[h] = malloc( ncols * sizeof(int))) == NULL) { printf("Malloc error 2"); exit(1); } } […]

如何MPI_Gatherv在发送端的位移?

我正在尝试使用MPI_Gatherv重新组合没有深灰色行的子arrays。 图片胜过千言万语: 鬼/晕暗灰色细胞的图形概述http://img535.imageshack.us/img535/9118/ghostcells.jpg 你如何只将*sendbuf部分( MPI_Gatherv手册中的第一个参数)发送到根进程(在另一个结构中没有浪费的重写,这次没有深灰色的行)? *displacements (第4个参数)仅与根进程的*recvbuf相关。 谢谢。 更新(或更准确地说) 我还想发送“边界”(浅灰色)细胞……而不仅仅是“内部”(白色)细胞。 正如osgx正确指出的那样:在这种情况下, MPI_Gatherv就足够……一些条件数组索引会做到这一点。

MPI发送和接收问题

我对MPI发送和接收操作有疑问。 假设,我们有2个MPI线程尝试相互发送消息。 以下是三个代码片段: 首先(阻止’发送’和’接收’): … int data = …; … MPI_Send( &data, sizeof( int ), MPI_INT, (my_id == 0)?1:0, 0, MPI_COMM_WORLD ); MPI_Status status; MPI_Recv( &data, sizeof( int ), MPI_INT, (my_id == 0)?1:0, 0, MPI_COMM_WORLD, &status ); … 第二个(非阻止’发送’但阻止’接收’): … int data = …; … MPI_Request request; MPI_Isend( &data, sizeof( int ), MPI_INT, (my_id == […]