Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void Vector_sum(double x[], double y[], double z[], int n)
- {
- int elemsPerProc = n / comm_sz;
- int extraElems = n % comm_sz;
- //create recv buffers
- double* recvbuffx = (double *) malloc(sizeof(double) * (elemsPerProc + extraElems));
- double* recvbuffy = (double *) malloc(sizeof(double) * (elemsPerProc + extraElems));
- //create sendcounts array
- int sendcounts[] = malloc(sizeof(int) * comm_sz);
- int mallocCtr = 0;
- for(mallocCtr; mallocCtr < comm_sz; mallocCtr++)
- {
- //add extra elems to main process
- if(mallocCtr == 0)
- {
- sendcounts[mallocCtr] = elemsPerProc + extraElems;
- }
- else
- {
- sendcounts[mallocCtr] = elemsPerProc;
- }
- }
- //root scatters elements
- if(myid == 0)
- {
- MPI_Scatterv{x, sendcounts, sendcounts, MPI_Double, recvbuffx, elemsPerProc + extraElems,
- MPI_Double, 0, MPI_COMM_WORLD};
- MPI_Scatterv{y, sendcounts, sendcounts, MPI_Double, recvbuffy, elemsPerProc + extraElems,
- MPI_Double, 0, MPI_COMM_WORLD};
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement