diff --git a/LibTrixi.jl/Project.toml b/LibTrixi.jl/Project.toml index a437c8ef..bc68f253 100644 --- a/LibTrixi.jl/Project.toml +++ b/LibTrixi.jl/Project.toml @@ -6,9 +6,11 @@ version = "0.1.0" [deps] OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed" Trixi = "a7f1ee26-1774-49b1-8366-f1abc58fbfcb" +MPI = "da04e1cc-30fd-572f-bb4f-1f8673147195" [compat] julia = "1.8" +MPI = "0.20.13" OrdinaryDiffEq = "6.53.2" Trixi = "0.5.29" diff --git a/LibTrixi.jl/src/LibTrixi.jl b/LibTrixi.jl/src/LibTrixi.jl index ade28539..434a549e 100644 --- a/LibTrixi.jl/src/LibTrixi.jl +++ b/LibTrixi.jl/src/LibTrixi.jl @@ -2,6 +2,7 @@ module LibTrixi using OrdinaryDiffEq: OrdinaryDiffEq, step!, check_error, DiscreteCallback using Trixi: Trixi, summary_callback +using MPI: MPI, run_init_hooks, set_default_error_handler_return export trixi_initialize_simulation, trixi_initialize_simulation_cfptr, @@ -38,4 +39,15 @@ function show_debug_output() end end +function __init__() + # MPI could have been initialized by an external application. + # In this situation MPI.jl's MPI.Init is not called and leaves some package-internal + # settings uninitialized. Recover those here. + MPI.run_init_hooks() + # Also make sure MPI returns errors, at least in debug mode + if show_debug_output() + MPI.set_default_error_handler_return() + end +end + end # module LibTrixi diff --git a/src/trixi.c b/src/trixi.c index 796c2e9a..3743aade 100644 --- a/src/trixi.c +++ b/src/trixi.c @@ -111,18 +111,6 @@ void trixi_initialize(const char * project_directory, const char * depot_path) { print_and_die("null pointer", LOC); } } - - // TODO: Workaround for issue with MPI.jl: A required MPI key value is not initialized - // in case MPI has already been initialized before. With libtrixi MPI could have - // been initialized by an external application. Check if MPI is initialized but - // the key value not. In this case run the init hooks manually. - // This would better be fixed using some functionality of MPI.jl - const char * call_MPI_run_init_hook = - "using MPI;\n" - "if MPI.Initialized() && MPI.JULIA_TYPE_PTR_ATTR[]==0;\n" - " MPI.run_init_hooks();\n" - "end\n"; - checked_eval_string(call_MPI_run_init_hook, LOC); }