Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
can anybody tell what am I doing wrong due to which I am getting this error.The error that I am getting is Fatal Error: fatal error in MPI_Scatter: Invalid buffer pointer, error stack:MPI_Scatter(760):MPI_Scatter(sbuf=0x0085f7ac , scount , MPI_INT , rbuf =0x0000000 , rcount =1, MPI_INT , root= 0 , MPI_COMM_WORLD) failed


C++
#include<stdio.h>
#include<mpi.h>

void transpose(int ** p, int row, int col)
{
    int ** tempVar;
    tempVar = (int *)malloc(sizeof(int *)* row);
    int i = 0;
    for (; i < row; i++)
    {
        tempVar[i] = (int *)malloc(sizeof (int *)* col);
        int j = 0;
        while (j < col)
        {
            tempVar[i][j] = p[j][i];
            j++;
        }
    }
    p = tempVar;
}
void main(int argc, char * argv[])
{
    int rank, size;
    MPI_Init(argc, argv);
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
    MPI_Comm_size(MPI_COMM_WORLD, &size);
    int d[] = { 1000, 1000, 1000, 1000, 1000, 1000 };
    int vt[6] = { 1000, 1000, 1000, 1000, 1000, 1000 };
    int ** p;
    p = (int *)malloc(sizeof(int *)* 6);
    int i = 0;
    int row = 6;
    int col = 6;
    while (i < 6)
    {
        p[i] = (int *)malloc(sizeof(int *)* 6);
        /*int j = 0;
        if (rank == 0)
        {
            while (j < 6)
            {
                scanf("%d", p[i][j]);
                j++;
            }
        }*/
        i++;    
    }
    p[0][0] = 0; p[0][1] =2 ; p[0][2] =3 ; p[0][3] =1 ; p[0][4] =1000 ; p[0][5] =1000 ;
    p[1][0] = 2; p[1][1] = 0; p[1][2] = 1000; p[1][3] = 1000; p[1][4] = 5; p[1][5] = 1000;
    p[2][0] = 3; p[2][1] = 1000; p[2][2] = 0; p[2][3] = 1000; p[2][4] = 1000; p[2][5] = 1;

    p[3][0] = 1; p[3][1] = 1000; p[3][2] = 1000; p[3][3] = 0; p[3][4] = 4; p[3][5] = 3;

    p[4][0] = 1000; p[4][1] = 5; p[4][2] = 1000; p[4][3] = 4; p[4][4] = 0; p[4][5] = 2;

    p[5][0] = 1000; p[5][1] = 1000; p[5][2] = 1; p[5][3] = 3; p[5][4] = 2; p[5][5] = 0;
    int smallest;   
    if (rank == 0)
    {
        //transpose(&p , row , col);
        smallest = 0;
        vt[smallest] = smallest;
        //MPI_Bcast();
    }
    int  vt1, d1;
    vt1 = d1 = 0;

    int roww[6];
    MPI_Scatter(vt, 6, MPI_INT, vt1, 1, MPI_INT, 0, MPI_COMM_WORLD);
    MPI_Scatter(d, 6, MPI_INT, d1, 1, MPI_INT, 0, MPI_COMM_WORLD);
    MPI_Scatter(p, row *row, MPI_INT,roww, 6, MPI_INT, 0, MPI_COMM_WORLD);
    i = 0;
    while (i < (row*row)/size)
    {
        MPI_Bcast(smallest, 1, MPI_INT, 0, MPI_COMM_WORLD);
        if (vt1 != rank)
        {
            if (roww[smallest] != 1000)
            {   
                if (d1 > roww[smallest])
                    d1 = roww[smallest];
            }
        }

        MPI_Gather(d1, 1, MPI_INT, d, row, MPI_INT, 0, MPI_COMM_WORLD);
        if (rank == 0)
        {
            smallest = d[0];
            int k = 1;
            int index = 0;
            while (k < 6)
            {
                if (d[k] < smallest)
                {
                    smallest = d[k];
                    index = k;
                }
                k++;
            }
            vt[k] = index;

        }
        MPI_Scatter(vt, 6, MPI_INT, vt1, (row) / size, MPI_INT, 0, MPI_COMM_WORLD);
        MPI_Scatter(d, 6, MPI_INT, d1, (row) / size, MPI_INT, 0, MPI_COMM_WORLD);

    }
    MPI_Finalize();
}
Posted
Updated 4-Feb-15 21:27pm
v2

1 solution

In this line
MPI_Scatter(p, row *row, MPI_INT,roww, 6, MPI_INT, 0, MPI_COMM_WORLD);

you are passing p which is of type int ** while the functions expects an int * parameter.

Instead of allocating a two dimensioal array you should allocate an int array with size row * row and access the items accordingly.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900