From 5e6f2ee04597d48204df6c5cdff8991f336710eb Mon Sep 17 00:00:00 2001 From: Matthias Hochsteger Date: Tue, 14 May 2024 21:56:50 +0200 Subject: [PATCH 1/9] Fix mesh generation from GUI when building with MPI --- libsrc/interface/nginterface.cpp | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/libsrc/interface/nginterface.cpp b/libsrc/interface/nginterface.cpp index 4fb229d9..5181be4c 100644 --- a/libsrc/interface/nginterface.cpp +++ b/libsrc/interface/nginterface.cpp @@ -27,17 +27,7 @@ namespace netgen static std::thread meshingthread; void RunParallel ( void * (*fun)(void *), void * in) { - bool parthread = netgen::mparam.parthread; - -#ifdef PARALLEL - int provided; - netgen::NG_MPI_Query_thread(&provided); - if (provided < 3) - if (netgen::ntasks > 1) parthread = false; - // cout << "runparallel = " << parthread << endl; -#endif - - if (parthread) + if (netgen::mparam.parthread) { meshingthread = std::thread(fun, in); meshingthread.detach(); From a80ae826c6ea77665b77ad934038044db255e179 Mon Sep 17 00:00:00 2001 From: Matthias Hochsteger Date: Tue, 14 May 2024 22:02:08 +0200 Subject: [PATCH 2/9] Remove MyMPI helper class --- libsrc/core/mpi_wrapper.hpp | 46 ------------------------------------- 1 file changed, 46 deletions(-) diff --git a/libsrc/core/mpi_wrapper.hpp b/libsrc/core/mpi_wrapper.hpp index 53f3ae43..ba5420c6 100644 --- a/libsrc/core/mpi_wrapper.hpp +++ b/libsrc/core/mpi_wrapper.hpp @@ -429,45 +429,6 @@ namespace ngcore }; // class NgMPI_Comm - - - - - - class MyMPI - { - bool initialized_by_me; - public: - MyMPI(int argc, char ** argv) - { - int is_init = -1; - NG_MPI_Initialized(&is_init); - if (!is_init) - { - NG_MPI_Init (&argc, &argv); - initialized_by_me = true; - } - else - initialized_by_me = false; - - NgMPI_Comm comm(NG_MPI_COMM_WORLD); - NGSOStream::SetGlobalActive (comm.Rank() == 0); - - if (comm.Size() > 1) - TaskManager::SetNumThreads (1); - } - - ~MyMPI() - { - if (initialized_by_me) - NG_MPI_Finalize (); - } - }; - - - - - #else // PARALLEL class NG_MPI_Comm { int nr; @@ -566,13 +527,6 @@ namespace ngcore inline void MyMPI_WaitAll (FlatArray requests) { ; } inline int MyMPI_WaitAny (FlatArray requests) { return 0; } - class MyMPI - { - public: - MyMPI(int argc, char ** argv) { ; } - }; - - #endif // PARALLEL } // namespace ngcore From a018931437fca311c8614278afe69e8803f4eff1 Mon Sep 17 00:00:00 2001 From: Matthias Hochsteger Date: Tue, 14 May 2024 22:17:42 +0200 Subject: [PATCH 3/9] Utility function to check if MPI was loaded --- libsrc/core/ng_mpi.hpp | 1 + libsrc/core/ng_mpi_wrapper.cpp | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/libsrc/core/ng_mpi.hpp b/libsrc/core/ng_mpi.hpp index 17f29a34..f29bb664 100644 --- a/libsrc/core/ng_mpi.hpp +++ b/libsrc/core/ng_mpi.hpp @@ -24,6 +24,7 @@ namespace py = pybind11; namespace ngcore { +NGCORE_API bool MPI_Loaded(); NGCORE_API void InitMPI( std::optional mpi_lib_path = std::nullopt); diff --git a/libsrc/core/ng_mpi_wrapper.cpp b/libsrc/core/ng_mpi_wrapper.cpp index 8b193562..ac9d3894 100644 --- a/libsrc/core/ng_mpi_wrapper.cpp +++ b/libsrc/core/ng_mpi_wrapper.cpp @@ -28,6 +28,10 @@ struct MPIFinalizer { } } mpi_finalizer; +bool MPI_Loaded() { + return ng_mpi_lib != nullptr; +} + void InitMPI(std::optional mpi_lib_path) { if (ng_mpi_lib) return; From fece35b830358f520cac9fe9ce5b49b26ed26f51 Mon Sep 17 00:00:00 2001 From: Matthias Hochsteger Date: Wed, 15 May 2024 19:30:40 +0200 Subject: [PATCH 4/9] euler_angles and scale argument in webgui Draw --- python/webgui.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/python/webgui.py b/python/webgui.py index 494c545b..d47db04b 100644 --- a/python/webgui.py +++ b/python/webgui.py @@ -321,6 +321,11 @@ class WebGLScene(base): if "gui_settings" not in d: d["gui_settings"] = self.kwargs["settings"] + if "euler_angles" in kwargs: + camera = d["gui_settings"].get("camera", {}) + camera["euler_angles"] = kwargs["euler_angles"] + d["gui_settings"]['camera'] = camera + d["objects"] = [] for obj in kwargs["objects"]: if isinstance(obj, dict): @@ -367,6 +372,7 @@ def _get_draw_default_args(): nodal_p1=False, settings={}, fullscreen=False, + scale=1.0, width=_default_width, height=_default_height, ) From f2ea9cde4cc893e6d74914427e73920d15e089f4 Mon Sep 17 00:00:00 2001 From: Matthias Hochsteger Date: Thu, 16 May 2024 09:18:07 +0200 Subject: [PATCH 5/9] Fix MPI code in paje trace --- libsrc/core/paje_trace.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/libsrc/core/paje_trace.cpp b/libsrc/core/paje_trace.cpp index f3f9e944..f97611a1 100644 --- a/libsrc/core/paje_trace.cpp +++ b/libsrc/core/paje_trace.cpp @@ -7,6 +7,7 @@ #include "archive.hpp" // for Demangle #include "paje_trace.hpp" +#include "ng_mpi.hpp" #include "profiler.hpp" #include "mpi_wrapper.hpp" @@ -71,9 +72,12 @@ namespace ngcore // sync start time when running in parallel #ifdef PARALLEL - NgMPI_Comm comm(NG_MPI_COMM_WORLD); - for([[maybe_unused]] auto i : Range(5)) - comm.Barrier(); + if(MPI_Loaded()) + { + NgMPI_Comm comm(NG_MPI_COMM_WORLD); + for([[maybe_unused]] auto i : Range(5)) + comm.Barrier(); + } #endif // PARALLEL start_time = GetTimeCounter(); From 184a6ba4c5f76feb3cdf2e0f16289069c9d13fcf Mon Sep 17 00:00:00 2001 From: Matthias Hochsteger Date: Thu, 16 May 2024 09:35:58 +0200 Subject: [PATCH 6/9] Fix MPI code in paje trace --- libsrc/core/paje_trace.cpp | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/libsrc/core/paje_trace.cpp b/libsrc/core/paje_trace.cpp index f97611a1..c8f37383 100644 --- a/libsrc/core/paje_trace.cpp +++ b/libsrc/core/paje_trace.cpp @@ -117,8 +117,11 @@ namespace ngcore for(auto i : IntRange(n_memory_events_at_start, memory_events.size())) memory_events[i].time -= start_time; - NgMPI_Comm comm(NG_MPI_COMM_WORLD); - + NgMPI_Comm comm; + #ifdef PARALLEL + if(MPI_Loaded()) + comm = NgMPI_Comm(NG_MPI_COMM_WORLD); + #endif if(comm.Size()==1) { Write(tracefile_name); @@ -491,14 +494,15 @@ namespace ngcore std::vector thread_aliases; std::vector container_nodes; -#ifdef PARALLEL - // Hostnames - NgMPI_Comm comm(NG_MPI_COMM_WORLD); - // auto rank = comm.Rank(); - auto nranks = comm.Size(); - if(nranks>1) + NgMPI_Comm comm; + #ifdef PARALLEL + if(MPI_Loaded()) + comm = NgMPI_Comm(NG_MPI_COMM_WORLD); + #endif + if(comm.Size()>1) { - nthreads = nranks; + auto comm = NgMPI_Comm(NG_MPI_COMM_WORLD); + nthreads = comm.Size(); thread_aliases.reserve(nthreads); std::array ahostname; @@ -509,7 +513,7 @@ namespace ngcore std::map host_map; std::string name; - for(auto i : IntRange(0, nranks)) + for(auto i : IntRange(0, comm.Size())) { if(i!=MPI_PAJE_WRITER) comm.Recv(name, i, 0); @@ -524,7 +528,6 @@ namespace ngcore } } else -#endif // PARALLEL { container_nodes.reserve(num_nodes); for(int i=0; i1) + if(comm.Size()>1) { - for(auto src : IntRange(0, nranks)) + for(auto src : IntRange(0, comm.Size())) { if(src==MPI_PAJE_WRITER) continue; @@ -622,7 +624,6 @@ namespace ngcore } } } -#endif // PARALLEL for(auto id : timer_ids) timer_aliases[id] = paje.DefineEntityValue( state_type_timer, timer_names[id], -1 ); @@ -747,7 +748,7 @@ namespace ngcore } #ifdef PARALLEL - if(nranks>1) + if(comm.Size()>1) { for(auto & event : timer_events) { @@ -763,7 +764,7 @@ namespace ngcore Array is_start; Array thread_id; - for(auto src : IntRange(0, nranks)) + for(auto src : IntRange(0, comm.Size())) { if(src==MPI_PAJE_WRITER) continue; From 05c01ee8846a4eaa92783a2a67f91ff527c60a67 Mon Sep 17 00:00:00 2001 From: Matthias Hochsteger Date: Thu, 16 May 2024 10:49:11 +0200 Subject: [PATCH 7/9] Fix segfault when using more than 32 colors in colormap --- libsrc/visualization/mvdraw.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/libsrc/visualization/mvdraw.cpp b/libsrc/visualization/mvdraw.cpp index 54b304dc..2a9afefd 100644 --- a/libsrc/visualization/mvdraw.cpp +++ b/libsrc/visualization/mvdraw.cpp @@ -497,7 +497,8 @@ namespace netgen { ntexcols = ncols; - GLubyte colortexture[4*32]; + ArrayMem colortexture; + colortexture.SetSize(4*ncols); const double colp[][3] = { @@ -532,8 +533,8 @@ namespace netgen // glPixelStorei (GL_UNPACK_ALIGNMENT, 1); - glTexImage1D (GL_TEXTURE_1D, 0, 4, ncols, 0, GL_RGBA, GL_UNSIGNED_BYTE, colortexture); - glTexImage2D (GL_TEXTURE_2D, 0, 4, ncols, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, colortexture); + glTexImage1D (GL_TEXTURE_1D, 0, 4, ncols, 0, GL_RGBA, GL_UNSIGNED_BYTE, colortexture.Data()); + glTexImage2D (GL_TEXTURE_2D, 0, 4, ncols, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, colortexture.Data()); glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, typ); // DECAL or MODULATE From 2072f70f7f2180923af9d5de0d09067746782cb0 Mon Sep 17 00:00:00 2001 From: Matthias Hochsteger Date: Thu, 16 May 2024 11:03:44 +0200 Subject: [PATCH 8/9] Fix building without MPI --- libsrc/core/paje_trace.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libsrc/core/paje_trace.cpp b/libsrc/core/paje_trace.cpp index c8f37383..dc218e8a 100644 --- a/libsrc/core/paje_trace.cpp +++ b/libsrc/core/paje_trace.cpp @@ -498,7 +498,6 @@ namespace ngcore #ifdef PARALLEL if(MPI_Loaded()) comm = NgMPI_Comm(NG_MPI_COMM_WORLD); - #endif if(comm.Size()>1) { auto comm = NgMPI_Comm(NG_MPI_COMM_WORLD); @@ -528,6 +527,7 @@ namespace ngcore } } else + #endif { container_nodes.reserve(num_nodes); for(int i=0; i Date: Tue, 21 May 2024 16:10:13 +0200 Subject: [PATCH 9/9] Remove output while generating fieldlines --- libsrc/meshing/fieldlines.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/libsrc/meshing/fieldlines.cpp b/libsrc/meshing/fieldlines.cpp index f77ce19a..d2ee2e21 100644 --- a/libsrc/meshing/fieldlines.cpp +++ b/libsrc/meshing/fieldlines.cpp @@ -206,13 +206,8 @@ namespace netgen int calculated = 0; - cout << endl; - - for(int i=0; i