/* Author: Lisandro Dalcin */ /* Contact: dalcinl@gmail.com */ /* -------------------------------------------------------------------------- */ #include #define MPICH_IGNORE_CXX_SEEK 1 #define OMPI_IGNORE_CXX_SEEK 1 #include #ifdef __FreeBSD__ #include #endif static int PyMPI_Main(int, char **); #if PY_MAJOR_VERSION >= 3 static int Py3_Main(int, char **); #endif /* -------------------------------------------------------------------------- */ int main(int argc, char **argv) { #ifdef __FreeBSD__ fp_except_t m; m = fpgetmask(); fpsetmask(m & ~FP_X_OFL); #endif return PyMPI_Main(argc, argv); } static int PyMPI_Main(int argc, char **argv) { int sts=0, flag=1, finalize=0; /* MPI initalization */ (void)MPI_Initialized(&flag); if (!flag) { #if defined(MPI_VERSION) && (MPI_VERSION > 1) int required = MPI_THREAD_MULTIPLE; int provided = MPI_THREAD_SINGLE; (void)MPI_Init_thread(&argc, &argv, required, &provided); #else (void)MPI_Init(&argc, &argv); #endif finalize = 1; } /* Python main */ #if PY_MAJOR_VERSION >= 3 sts = Py3_Main(argc, argv); #else sts = Py_Main(argc, argv); #endif /* MPI finalization */ (void)MPI_Finalized(&flag); if (!flag) { if (sts != 0) (void)MPI_Abort(MPI_COMM_WORLD, sts); if (finalize) (void)MPI_Finalize(); } return sts; } /* -------------------------------------------------------------------------- */ #if PY_MAJOR_VERSION >= 3 #include static wchar_t **mk_wargs(int, char **); static wchar_t **cp_wargs(int, wchar_t **); static void rm_wargs(wchar_t **, int); static int Py3_Main(int argc, char **argv) { int sts = 0; wchar_t **wargv = mk_wargs(argc, argv); wchar_t **wargv2 = cp_wargs(argc, wargv); if (wargv && wargv2) sts = Py_Main(argc, wargv); else sts = 1; rm_wargs(wargv2, 1); rm_wargs(wargv, 0); return sts; } #if PY_VERSION_HEX < 0x03050000 #define Py_DecodeLocale _Py_char2wchar #endif #if PY_VERSION_HEX < 0x03040000 #define PyMem_RawMalloc PyMem_Malloc #define PyMem_RawFree PyMem_Free #endif static wchar_t ** mk_wargs(int argc, char **argv) { int i; char *saved_locale = NULL; wchar_t **args = NULL; args = (wchar_t **)PyMem_RawMalloc((size_t)(argc+1)*sizeof(wchar_t *)); if (!args) goto oom; saved_locale = strdup(setlocale(LC_ALL, NULL)); if (!saved_locale) goto oom; setlocale(LC_ALL, ""); for (i=0; i= 3) */ /* -------------------------------------------------------------------------- */ /* Local variables: c-basic-offset: 2 indent-tabs-mode: nil End: */