0

I have following code:

double * myX;
double * myY;
double * myZ;
int amount;
int count;      // number of process

void SomeClass::someMethod(double *x, double *y, double *z, int amount) {

    if (myId == 0) {
        myX = x;
        myY = y;
        myZ = z;
        amount = amount;
        for(int i = 1; i < count; ++i) {
            MPI_Send(&amount, 1, MPI_INT, i, 0, MPI_COMM_WORLD);
            MPI_Send(myX, amount, MPI_DOUBLE, i, 0, MPI_COMM_WORLD);
            MPI_Send(myY, amount, MPI_DOUBLE, i, 0, MPI_COMM_WORLD);
            MPI_Send(myX, amount, MPI_DOUBLE, i, 0, MPI_COMM_WORLD);
        }
    }                                         
}

void SomeClass::anotherMethod(void) {

    if(myId != 0) {
        MPI_Recv(&amount, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
        MPI_Recv(myX, amount, MPI_DOUBLE, 0, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
        MPI_Recv(myY, amount, MPI_DOUBLE, 0, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
        MPI_Recv(myZ, amount, MPI_DOUBLE, 0, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);         
    }

    // rest of code
    MPI_Reduce(args);
}

But I have problem because I get Null buffer pointer when I run this code or Segmentation fault when I change something, for example set & before var name and then run.

MPI_init and other required function are called in other class, where I also create this class objects.

Can someone help me?

2
  • 1
    Your question would be clearer if you explained what part of your code originated the error: Which of your many MPI calls results in Null buffer pointer? What line is the Segmentation fault thrown from? Commented Jan 20, 2016 at 21:53
  • @Edward right, it was when I try get data from double array. Commented Jan 20, 2016 at 23:24

1 Answer 1

3

MPI_Recv will copy the data it receives to the buffer specified by the first parameter (myX in the case below):

MPI_Recv(myX, amount, MPI_DOUBLE, 0, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);

The problem is that you haven't created a buffer to store this.

You could do:

myX = new double[amount];

For example to create the buffer, not forgetting to free the memory again afterwards with:

delete[] myX;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.