Skip to Content.
Sympa Menu

charm - [charm] catching exceptions

charm AT lists.cs.illinois.edu

Subject: Charm++ parallel programming system

List archive

[charm] catching exceptions


Chronological Thread 
  • From: Jozsef Bakosi <jbakosi AT lanl.gov>
  • To: charm <charm AT lists.cs.illinois.edu>
  • Subject: [charm] catching exceptions
  • Date: Wed, 16 May 2018 07:09:15 -0600
  • Authentication-results: illinois.edu; spf=pass smtp.mailfrom=jbakosi AT lanl.gov; dmarc=pass header.from=lanl.gov

Hi folks,

When exceptions are thrown from chare arrays or groups, how/where one is
supposed to catch them?

Ideally, I would like to catch exceptions at the outermost layer, e.g.,
outside
of some driver, from where everything else is instantiated and called, but
that
way not every exception is caught.

I attach an example with the simplearrayhello test augmented and commented
highlighting the problem/question.

In addition, I also set signal handlers to throw exceptions (and produce nice
stack traces) when, e.g., segfaults happen and redirect them to the same code
that handles exceptions and produce stack traces, but when exceptions are not
caught that is useless.

Alternatively, is it possible to override Charm++'s exception handling, that
sometimes produces outputs like the following:

------------- Processor 0 Exiting: Called CmiAbort ------------
Reason: Unhandled C++ exception in user code.

[0] Stack Traceback:
[0:0] [0x592cfe]
[0:1] [0x58f9f8]
[0:2] [0x41b908]
[0:3] [0x41b8e9]
[0:4] +0x22763 [0x7ffff736d763]
[0:5] +0x25516 [0x7ffff7370516]
[0:6] +0x254af [0x7ffff73704af]
[0:7] [0x414829]
[0:8] [0x413091]
[0:9] [0x434f30]
[0:10] [0x46f99a]
[0:11] [0x440c2d]
[0:12] [0x437491]
[0:13] [0x436e11]
[0:14] [0x596417]
[0:15] [0x596744]
[0:16] [0x59646a]
[0:17] [0x5929d1]
[0:18] [0x592283]
[0:19] [0x417c95]
[0:20] __libc_start_main+0xe7 [0x7ffff621aa87]
[0:21] [0x411f1a]
--------------------------------------------------------------------------
MPI_ABORT was invoked on rank 0 in communicator MPI COMMUNICATOR 3 DUP FROM 0
with errorcode 1.

NOTE: invoking MPI_ABORT causes Open MPI to kill all MPI processes.
You may or may not see output from other processes, depending on
exactly when Open MPI kills them.
--------------------------------------------------------------------------

Thanks,
Jozsef

#include <iostream>
#include <stdio.h>
#include "hello.decl.h"

/*readonly*/ CProxy_Main mainProxy;
/*readonly*/ int nElements;

/* readonly */ float values[3][3];

/*mainchare*/
class Main : public CBase_Main
{
public:
  Main(CkArgMsg* m)
  {
    //Process command-line arguments
    nElements=5;
    if(m->argc >1 ) nElements=atoi(m->argv[1]);
    delete m;

    try {

      //Start the computation
      CkPrintf("Running Hello on %d processors for %d elements\n",
               CkNumPes(),nElements);
      mainProxy = thisProxy;

      CProxy_Hello arr = CProxy_Hello::ckNew(nElements);

      for (int i = 0; i < 3; ++i)
        for (int j = 0; j < 3; ++j)
          values[i][j] = 3*i + j;

      arr[0].SayHi(17);

      // will be caught by the catch below
      throw "excpetion";

    } catch (...) { std::cout << "\n\ncaught it!\n\n"; }

  };

  void done(void)
  {
    CkPrintf("All done\n");
    CkExit();
  };
};

/*array [1D]*/
class Hello : public CBase_Hello 
{
public:
  Hello()
  {
    CkPrintf("[%d] Hello %d created\n", CkMyPe(), thisIndex);
  }

  Hello(CkMigrateMessage *m) {}
  
  void SayHi(int hiNo)
  {
    for (int i = 0; i < 3; ++i)
      for (int j = 0; j < 3; ++j)
	CkAssert(values[i][j] == 3*i + j);

      // will only be caught by Charm++
      throw "excpetion";

    CkPrintf("[%d] Hi[%d] from element %d\n", CkMyPe(), hiNo, thisIndex);
    if (thisIndex < nElements-1)
      //Pass the hello on:
      thisProxy[thisIndex+1].SayHi(hiNo+1);
    else 
      //We've been around once-- we're done.
      mainProxy.done();
  }
};

#include "hello.def.h"



Archive powered by MHonArc 2.6.19.

Top of Page