c++ - MPI_gatherv returns wrong receivecounts for mpi_doubles -



c++ - MPI_gatherv returns wrong receivecounts for mpi_doubles -

i trying collect double values via mpi_gatherv. have array double values , different lenghts each rank. master should collect them , print them all.

here code sample:

#include "mpi.h" #include <iostream> #include <cmath> /* * * * silly demo * */ int main(){ int rank, wsize; // setup communication: mpi_init(null, null); mpi_comm_rank(mpi_comm_world,&rank); mpi_comm_size (mpi_comm_world, &wsize); if(rank ==0){ // master: int tasks = rank +1; double res[tasks]; for(int i=0; < tasks; i++){ // job: res[i] = std::sqrt(tasks+i); //std::cout << res[i] << " "; } double recvbuffer[wsize*wsize]; int rd[wsize]; int rc[wsize]; mpi_gatherv(res, tasks, mpi_double, recvbuffer, rc, rd, mpi_double, 0, mpi_comm_world); // results should collected std::cout << "results: " << std::endl; for(int i=0; i<wsize; i++){ std::cout << << ") rc:" << rc[i] << " rd:" << rd[i] << std::endl; } }else{ // worker: int tasks = rank +1; double res[tasks]; for(int i=0; < tasks; i++){ // job: res[i] = std::sqrt(rank+i); //std::cout << res[i] << " "; } mpi_gatherv(res, tasks, mpi_double, null, null, null, mpi_double, 0, mpi_comm_world); // send sleep while(1){}; } mpi_abort(mpi_comm_world, mpi_success); mpi_finalize(); homecoming 0; }

i compile

mpic++ -std=gnu++0x -o smallmpi smallmpi.cpp

and run

mpirun -n 2 ./smallmpi

i never right values rc! segmentation faults like:

your application terminated exit string: segmentation fault (signal 11) typically refers problem application.

sometimes code works, result not correct:

results: 0) rc:1000556 rd:0 1) rc:32767 rd:0 application called mpi_abort(mpi_comm_world, 0) - process 0

i expect 0) rc = 1 , 1) rc=2 2 processes. values in recvbuffer not expect. problem utilize c mpi calls within c++? guess addresses because values random.

thank much help , time.

c++ mpi

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -