1

I just recently learned that MPI_Send cannot send too long data at a time, so I decided to divide the data into pieces and send them in a for loop. Below is a test case. The problem here is that if I use a small amount of data and divide it into pieces, the program will run; However, when the data is long, no matter how many pieces I divide it into, the program just won't run. When I run it, I just heard my computer makes big noise. So I wonder what is the cause and how can i make MPI_Send to send a large data set to other processors. Thank you!

    #include<iostream>
    #include<mpi.h>
    #include<vector>
    using namespace std;

   //This set of N and N+Parts won't work 
    #define N 1024*1024*5
    #define N_PARTS 1000


   //This works 
    #define N 1024*5
    #define N_PARTS 10

    #define MASTER 0


    int main(int argc, char** argv)
    {
            int np, pid;
            vector<int> arr;
            for(int i=0; i<N; ++i) arr.push_back(i);

            int LENGTH = N/N_PARTS;
            int N_RES = N%N_PARTS;
    //      cout << LENGTH << endl;
    //      cout << N_RES << endl;          
            MPI_Init(&argc, &argv);
            MPI_Comm_size(MPI_COMM_WORLD, &np);
            MPI_Comm_rank(MPI_COMM_WORLD, &pid);

            for(int i=0; i< N_PARTS-1; ++i){
                    MPI_Send(&arr[0]+i*LENGTH,LENGTH,MPI_INT,MASTER,0,MPI_COMM_WORLD);
            }
            MPI_Send(&arr[0]+LENGTH*(N_PARTS-1),N_RES,MPI_INT,MASTER,0,MPI_COMM_WORLD);
            MPI_Finalize();
    }
6
  • What does this mean? "I just heard my computer makes big noise" Commented Oct 31, 2015 at 2:42
  • Where is the call to MPI_Recv? Commented Oct 31, 2015 at 2:43
  • I didn't write MPI_Recv(). Isn't it OK to just send without receiving? Commented Oct 31, 2015 at 2:44
  • 1
    Of course it's not OK. Commented Oct 31, 2015 at 2:45
  • I mean the program will just stuck there and never ends. but the computer makes big noise meaning there are a lot of executions inside. Commented Oct 31, 2015 at 2:45

1 Answer 1

1

MPI_Send - MPI_Recv is point-point interaction. If you send data from one processor then you should receive data on another processor. Therefore your code must looks like this:

if (pid == MASTER) {
    for (int i = 1; i < np; i++) {
        MPI_Send(&arr[0] + i*LENGTH, LENGTH, MPI_INT, i, 0, MPI_COMM_WORLD);
    }
} else {
    arr.resize(LENGTH);
    MPI_Recv(&arr[0], LENGTH, MPI_INT, MASTER, 0, MPI_COMM_WORLD, &status);
}

Also you can read this tutorial about MPI_Send and MPI_Recv.

UPD: Also I think that you should not init your data on each processor. You can init data on processor with number 0 and send this data to all other processors:

if (pid == MASTER) {
    for (int i = 0; i<N; ++i) arr.push_back(i);
}
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.