Hi, I have difficulty catching std::bac_alloc in an MPI environment. The code is attached. I'm uisng gcc 6.3 on SUSE Linux Enterprise Server 11 (x86_64). OpenMPI is built from source. The commands are as follows:
*Build* g++ -I<openmpi-4.0.0-opt/include> -L<openmpi-4.0.0-opt/lib> -lmpi memory.cpp *Run* <openmpi-4.0.0-opt/bin/mpiexec> -n 2 a.out *Output* 0 0 1 1 -------------------------------------------------------------------------- Primary job terminated normally, but 1 process returned a non-zero exit code. Per user-direction, the job has been aborted. -------------------------------------------------------------------------- -------------------------------------------------------------------------- mpiexec noticed that process rank 0 with PID 0 on node cdcebus114qa05 exited on signal 9 (Killed). -------------------------------------------------------------------------- If I uncomment the line //if (rank == 0), i.e., only rank 0 allocates memory, I'm able to catch bad_alloc as I expected. It seems that I am misunderstanding something. Could you please help? Thanks a lot. Best regards, Zhen
#include "mpi.h" #include <iostream> #include <vector> #include <unistd.h> int main( int argc, char *argv[] ) { MPI_Init( &argc, &argv ); int rank; MPI_Comm_rank(MPI_COMM_WORLD, &rank); //if (rank == 0) { std::vector<std::vector<double> > a(100); for (long long i = 0; i < 100; i++) { std::cout << i << std::endl; try { a[i].resize(1000000000); } catch (std::bad_alloc b) { std::cout << "out" << std::endl; continue; } usleep(1000000); } } MPI_Finalize(); return 0; }
_______________________________________________ users mailing list users@lists.open-mpi.org https://lists.open-mpi.org/mailman/listinfo/users