c++ - mpi MPI_Send() works for small data set but not large data set -


i learned mpi_send cannot send long data @ time, decided divide data pieces , send them in loop. below test case. problem here if use small amount of data , divide pieces, program run; however, when data long, no matter how many pieces divide into, program won't run. when run it, heard computer makes big noise. wonder cause , how can make mpi_send send large data set other processors. thank you!

    #include<iostream>     #include<mpi.h>     #include<vector>     using namespace std;     //this set of n , 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();     } 

mpi_send - mpi_recv point-point interaction. if send data 1 processor should receive data on processor. therefore code must looks this:

if (pid == master) {     (int = 1; < 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 can read this tutorial mpi_send , mpi_recv.

upd: think should not init data on each processor. can init data on processor number 0 , send data other processors:

if (pid == master) {     (int = 0; i<n; ++i) arr.push_back(i); } 

Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -