[mpich-discuss] Cannot catch std::bac_alloc?

Zhen Wang toddwz at gmail.com
Wed Apr 3 08:42:24 CDT 2019


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).
mpich is built from source. The commands are as follows:

*Build*
g++ -I<mpich-3.3-opt/include> -L<mpich-3.3-opt/lib> -lmpi memory.cpp

*Run*
<mpich-3.3-opt/bin/mpiexec> -n 2 a.out

*Output*
0
0
1
1

===================================================================================
=   BAD TERMINATION OF ONE OF YOUR APPLICATION PROCESSES
=   PID 16067 RUNNING AT <machine name>
=   EXIT CODE: 9
=   CLEANING UP REMAINING PROCESSES
=   YOU CAN IGNORE THE BELOW CLEANUP MESSAGES
===================================================================================
YOUR APPLICATION TERMINATED WITH THE EXIT STRING: Killed (signal 9)
This typically refers to a problem with your application.
Please see the FAQ page for debugging suggestions

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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mpich.org/pipermail/discuss/attachments/20190403/f858e2cf/attachment.html>
-------------- next part --------------
#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;
}


More information about the discuss mailing list