Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

move atexit and _initialized=true to after MPI_Init

  • Loading branch information...
commit 74bc4fd53ba8113d0d930c008f55fa64aa98ffe0 1 parent 828ddf2
@seiya authored
Showing with 16 additions and 16 deletions.
  1. +16 −16 ext/mpi/mpi.c
View
32 ext/mpi/mpi.c
@@ -144,6 +144,14 @@ check_error(int error)
rb_define_const(klass, #name, Data_Wrap_Struct(klass, 0, -1, v)); \
}
+static void
+_finalize()
+{
+ if(_initialized && !_finalized) {
+ _finalized = true;
+ check_error(MPI_Finalize());
+ }
+}
static VALUE
rb_m_init(int argc, VALUE *argv, VALUE self)
{
@@ -153,11 +161,6 @@ rb_m_init(int argc, VALUE *argv, VALUE self)
VALUE progname;
int i;
- if (_initialized)
- return self;
- else
- _initialized = true;
-
rb_scan_args(argc, argv, "01", &argary);
if (NIL_P(argary)) {
@@ -180,7 +183,14 @@ rb_m_init(int argc, VALUE *argv, VALUE self)
}
cargc++;
- MPI_Init(&cargc, &cargv);
+ check_error(MPI_Init(&cargc, &cargv));
+ if (_initialized)
+ return self;
+ else
+ _initialized = true;
+ atexit(_finalize);
+
+
// define MPI::Comm::WORLD
struct _Comm *comm;
@@ -211,14 +221,6 @@ rb_m_init(int argc, VALUE *argv, VALUE self)
return self;
}
-static void
-_finalize()
-{
- if(_initialized && !_finalized) {
- _finalized = true;
- check_error(MPI_Finalize());
- }
-}
static VALUE
rb_m_finalize(VALUE self)
{
@@ -550,8 +552,6 @@ void Init_mpi()
rb_require("narray");
- atexit(_finalize);
-
// MPI
mMPI = rb_define_module("MPI");
rb_define_module_function(mMPI, "Init", rb_m_init, -1);
Please sign in to comment.
Something went wrong with that request. Please try again.