Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C MPI_发送和MPI_接收分段错误_C - Fatal编程技术网

C MPI_发送和MPI_接收分段错误

C MPI_发送和MPI_接收分段错误,c,C,尝试在MPI进程之间传递数组指针,并将其接收到动态分配的内存。它不断地给出一个分段错误,我们认为这是由于我们在进程之间发送它的方式造成的。我们的守则如下: #include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> #include "mpi.h" #include <math.h> int main(int argc, char* arg

尝试在MPI进程之间传递数组指针,并将其接收到动态分配的内存。它不断地给出一个分段错误,我们认为这是由于我们在进程之间发送它的方式造成的。我们的守则如下:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "mpi.h"
#include <math.h>

int main(int argc, char* argv[])
{
    int my_rank, i, j, p;
    MPI_Request     request, request2;
    MPI_Status      mpi_status;

MPI_Init(&argc, &argv);

MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
MPI_Comm_size(MPI_COMM_WORLD, &p);
MPI_Barrier(MPI_COMM_WORLD);

    if (my_rank == 0) 
    {
            int size = 5;
            int **slice;
             slice = (int **)malloc(sizeof(int*)* size);
             slice[0] = (int *)malloc(sizeof(int)* size*size);

             for(i = 0; i< size;i++)
             {
                    slice[i] = (*slice + size*i);
            }

            for (i = 0; i < size; i++)
            {
                    for (j = 0; j < size; j++)
                    {
                            slice[i][j] = i*j;
                    }
            }
           for (i = 0; i < size; i++)
            {
                    for (j = 0; j < size; j++) 
                    {
                            printf("slice[%d][%d]: %d\n", i, j, slice[i][j]);
                    }
            }

            MPI_Send(&slice, size * size, MPI_INT, 1, 1, MPI_COMM_WORLD);

    } else {
            int local_size=5;
            int **local_slice;
            local_slice = (int **)malloc(sizeof(int*)* local_size);
            local_slice[0] = (int *)malloc(sizeof(int)* local_size*local_size);

             for(i = 0; i< local_size;i++)
             {
                    local_slice[i] = (*local_slice + local_size*i);
            }

            MPI_Recv(&local_slice, local_size * local_size, MPI_INT, 0, 1, MPI_COMM_WORLD, &mpi_status);

           for (i = 0; i < local_size; i++)
            {
                    for (j = 0; j < local_size; j++) 
                    {
                            printf("local_slice[%d][%d]: %d\n", i, j, local_slice[i][j]); 
                    }
            }

    }

    MPI_Finalize();
    return 0;
}
#包括
#包括
#包括
#包括
#包括“mpi.h”
#包括
int main(int argc,char*argv[])
{
int我的_秩,i,j,p;
MPI_请求请求,请求2;
MPI_状态MPI_状态;
MPI_Init(&argc,&argv);
MPI通信等级(MPI通信世界和我的通信等级);
MPI通信大小(MPI通信世界和p);
MPI_屏障(MPI_通信世界);
如果(我的排名==0)
{
int size=5;
int**切片;
切片=(int**)malloc(sizeof(int*)*size);
切片[0]=(int*)malloc(sizeof(int)*size*size);
对于(i=0;i

有人能解释一下如何在MPI进程之间正确传递这种类型的数组吗?

看起来您需要将第一个参数更改为
MPI\u Send
,从
&slice
更改为
slice[0]
,并对
MPI\u Recv
执行同样的操作