From 6c39a43dc0c4c1da21bf2fcc856a0b62f0179554 Mon Sep 17 00:00:00 2001 From: camierjs Date: Mon, 16 Mar 2026 18:17:24 -0700 Subject: [PATCH 01/15] Whole serial run --- glvis.cpp | 60 ++++++++++++++++++++++++++++++++++++++++++++++ lib/CMakeLists.txt | 12 ++++++++++ 2 files changed, 72 insertions(+) diff --git a/glvis.cpp b/glvis.cpp index c68418b2..0ad10df2 100644 --- a/glvis.cpp +++ b/glvis.cpp @@ -47,6 +47,15 @@ using namespace std; using namespace mfem; +/////////////////////////////////////////////////////////////////////////////// +#ifdef NVTX_DBG_HPP +#undef NVTX_COLOR +#define NVTX_COLOR ::nvtx::kGold +#include NVTX_DBG_HPP +#else +#define dbg(...) +#endif + const char *string_none = "(none)"; const char *string_default = "(default)"; @@ -145,6 +154,7 @@ class Session int StartStreamSession(StreamCollection &&streams) { + dbg(); StreamReader reader(win.data_state); int ierr = reader.ReadStreams(streams); if (ierr) { return ierr; } @@ -154,6 +164,18 @@ class Session return 0; } + int StartSerialStreamSession(std::unique_ptr &&stream, + const std::string &data_type) + { + dbg("data_type: '{}'", data_type); + StreamReader reader(win.data_state); + int ierr = reader.ReadStream(*stream, data_type); + if (ierr) { dbg("❌ ERROR ❌"); return ierr; } + + input_streams.emplace_back(std::move(stream)); + StartSession(); + return 0; + } }; void GLVisServer(int portnum, bool save_stream, bool fix_elem_orient, @@ -347,6 +369,44 @@ void GLVisServer(int portnum, bool save_stream, bool fix_elem_orient, } } +/////////////////////////////////////////////////////////////////////////////// +void *GLVisLibGetWindow() +{ + static Window win; + return (void*) &win; +} + +/////////////////////////////////////////////////////////////////////////////// +int GLVisLibWindow(void *win_ptr, bool fix_elem_orient, + bool save_coloring, bool headless, + const std::string &plot_caption, + std::unique_ptr &&stream, + const std::string &data_type) +{ + dbg(); + // std::this_thread::sleep_for(std::chrono::milliseconds(500)); + + dbg("Main Window structure"); + auto *win = static_cast(win_ptr); + + std::vector current_sessions; + + dbg("Get main thread"); + GetMainThread(win->headless); + + dbg("StartStreamSession"); + Session new_session(fix_elem_orient, save_coloring, plot_caption, headless); + + new_session.StartSerialStreamSession(std::move(stream), data_type); + current_sessions.emplace_back(std::move(new_session)); + + dbg("Starting message loop in main thread"); + MainThreadLoop(); + + dbg("EXIT_SUCCESS"); + return EXIT_SUCCESS; +} + int main (int argc, char *argv[]) { #ifdef _WIN32 diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 0611ffb8..890bb162 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -10,6 +10,7 @@ # CONTRIBUTING.md for details. list(APPEND SOURCES + ../glvis.cpp egl/egl.cpp egl/egl_main.cpp gl/renderer.cpp @@ -113,4 +114,15 @@ else() if (APPLE) target_link_libraries(glvis PUBLIC "-framework Cocoa") endif() + message(STATUS "[🔵 DEFS 🔵] ${_glvis_compile_defs}") + message(STATUS "[🔵 OPTS 🔵] ${_glvis_compile_opts}") + message(STATUS "[🔵 INCS 🔵] ${_glvis_include_dirs}") + message(STATUS "[🔵 LIBS 🔵] ${_glvis_libraries}") + + get_target_property(_link_libs glvis LINK_LIBRARIES) + get_target_property(_link_dirs glvis LINK_DIRECTORIES) + get_target_property(_link_opts glvis LINK_OPTIONS) + message(STATUS "[🔵 LINK LIBS 🔵] ${_link_libs}") + message(STATUS "[🔵 LINK DIRS 🔵] ${_link_dirs}") + message(STATUS "[🔵 LINK OPTS 🔵] ${_link_opts}") endif(EMSCRIPTEN) From e5430880c6a30850e89d220e1adc30ae6ee8cbf3 Mon Sep 17 00:00:00 2001 From: camierjs Date: Tue, 17 Mar 2026 08:49:39 -0700 Subject: [PATCH 02/15] Extract session from main glvis source file --- glvis.cpp | 149 +----------------------------------------- lib/CMakeLists.txt | 3 +- lib/session.cpp | 158 +++++++++++++++++++++++++++++++++++++++++++++ lib/session.hpp | 57 ++++++++++++++++ makefile | 4 +- 5 files changed, 221 insertions(+), 150 deletions(-) create mode 100644 lib/session.cpp create mode 100644 lib/session.hpp diff --git a/glvis.cpp b/glvis.cpp index 0ad10df2..633acdb0 100644 --- a/glvis.cpp +++ b/glvis.cpp @@ -11,7 +11,7 @@ // GLVis - an OpenGL visualization server based on the MFEM library -#include +// #include #include #include #include @@ -35,6 +35,7 @@ #endif #include +#include "lib/session.hpp" #include "lib/visual.hpp" #include "lib/window.hpp" #include "lib/script_controller.hpp" @@ -47,15 +48,6 @@ using namespace std; using namespace mfem; -/////////////////////////////////////////////////////////////////////////////// -#ifdef NVTX_DBG_HPP -#undef NVTX_COLOR -#define NVTX_COLOR ::nvtx::kGold -#include NVTX_DBG_HPP -#else -#define dbg(...) -#endif - const char *string_none = "(none)"; const char *string_default = "(default)"; @@ -78,105 +70,6 @@ thread_local GeometryRefiner GLVisGeometryRefiner; void PrintSampleUsage(ostream &out); -class Session -{ - StreamCollection input_streams; - Window win; - std::thread handler; - -public: - Session(bool fix_elem_orient, - bool save_coloring, - string plot_caption, - bool headless) - { - win.data_state.fix_elem_orient = fix_elem_orient; - win.data_state.save_coloring = save_coloring; - win.plot_caption = plot_caption; - win.headless = headless; - } - - Session(Window other_win) - : win(std::move(other_win)) - { } - - ~Session() = default; - - Session(Session&& from) = default; - Session& operator= (Session&& from) = default; - - inline DataState& GetState() { return win.data_state; } - inline const DataState& GetState() const { return win.data_state; } - - void StartSession() - { - auto funcThread = [](Window w, StreamCollection is) - { - if (w.GLVisInitVis(std::move(is))) - { - w.GLVisStartVis(); - } - }; - handler = std::thread {funcThread, - std::move(win), std::move(input_streams)}; - handler.detach(); - } - - bool StartSavedSession(std::string stream_file) - { - unique_ptr ifs(new ifstream(stream_file)); - if (!(*ifs)) - { - cout << "Can not open stream file: " << stream_file << endl; - return false; - } - string data_type; - *ifs >> data_type >> ws; - StreamReader reader(win.data_state); - reader.ReadStream(*ifs, data_type); - input_streams.emplace_back(std::move(ifs)); - - StartSession(); - return true; - } - - int StartStreamSession(std::unique_ptr &&stream, - const std::string &data_type) - { - StreamReader reader(win.data_state); - int ierr = reader.ReadStream(*stream, data_type); - if (ierr) { return ierr; } - input_streams.emplace_back(std::move(stream)); - - StartSession(); - return 0; - } - - int StartStreamSession(StreamCollection &&streams) - { - dbg(); - StreamReader reader(win.data_state); - int ierr = reader.ReadStreams(streams); - if (ierr) { return ierr; } - input_streams = std::move(streams); - - StartSession(); - return 0; - } - - int StartSerialStreamSession(std::unique_ptr &&stream, - const std::string &data_type) - { - dbg("data_type: '{}'", data_type); - StreamReader reader(win.data_state); - int ierr = reader.ReadStream(*stream, data_type); - if (ierr) { dbg("❌ ERROR ❌"); return ierr; } - - input_streams.emplace_back(std::move(stream)); - StartSession(); - return 0; - } -}; void GLVisServer(int portnum, bool save_stream, bool fix_elem_orient, bool save_coloring, string plot_caption, bool headless = false) @@ -369,44 +262,6 @@ void GLVisServer(int portnum, bool save_stream, bool fix_elem_orient, } } -/////////////////////////////////////////////////////////////////////////////// -void *GLVisLibGetWindow() -{ - static Window win; - return (void*) &win; -} - -/////////////////////////////////////////////////////////////////////////////// -int GLVisLibWindow(void *win_ptr, bool fix_elem_orient, - bool save_coloring, bool headless, - const std::string &plot_caption, - std::unique_ptr &&stream, - const std::string &data_type) -{ - dbg(); - // std::this_thread::sleep_for(std::chrono::milliseconds(500)); - - dbg("Main Window structure"); - auto *win = static_cast(win_ptr); - - std::vector current_sessions; - - dbg("Get main thread"); - GetMainThread(win->headless); - - dbg("StartStreamSession"); - Session new_session(fix_elem_orient, save_coloring, plot_caption, headless); - - new_session.StartSerialStreamSession(std::move(stream), data_type); - current_sessions.emplace_back(std::move(new_session)); - - dbg("Starting message loop in main thread"); - MainThreadLoop(); - - dbg("EXIT_SUCCESS"); - return EXIT_SUCCESS; -} - int main (int argc, char *argv[]) { #ifdef _WIN32 diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 890bb162..adecf02b 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -10,7 +10,6 @@ # CONTRIBUTING.md for details. list(APPEND SOURCES - ../glvis.cpp egl/egl.cpp egl/egl_main.cpp gl/renderer.cpp @@ -33,6 +32,7 @@ list(APPEND SOURCES palettes_default.cpp palettes_base.cpp script_controller.cpp + session.cpp stream_reader.cpp vsdata.cpp vssolution.cpp @@ -68,6 +68,7 @@ list(APPEND HEADERS palettes.hpp palettes_base.hpp script_controller.hpp + session.hpp stream_reader.hpp visual.hpp vsdata.hpp diff --git a/lib/session.cpp b/lib/session.cpp new file mode 100644 index 00000000..0c732bc4 --- /dev/null +++ b/lib/session.cpp @@ -0,0 +1,158 @@ +// Copyright (c) 2010-2026, Lawrence Livermore National Security, LLC. Produced +// at the Lawrence Livermore National Laboratory. All Rights reserved. See files +// LICENSE and NOTICE for details. LLNL-CODE-443271. +// +// This file is part of the GLVis visualization tool and library. For more +// information and source code availability see https://glvis.org. +// +// GLVis is free software; you can redistribute it and/or modify it under the +// terms of the BSD-3 license. We welcome feedback and contributions, see file +// CONTRIBUTING.md for details. + +#include "threads.hpp" // IWYU pragma: keep for GLVisCommand +#include "aux_vis.hpp" // SetUseHiDPI + +#include "session.hpp" + +#include + +#ifdef NVTX_DBG_HPP +#undef NVTX_COLOR +#define NVTX_COLOR ::nvtx::kGold +#include NVTX_DBG_HPP +#else +#define dbg(...) +#endif + +void Session::StartSession() +{ + auto funcThread = [](Window w, StreamCollection is) + { + if (w.GLVisInitVis(std::move(is))) + { + w.GLVisStartVis(); + } + }; + handler = std::thread {funcThread, + std::move(win), std::move(input_streams)}; + handler.detach(); +} + +bool Session::StartSavedSession(std::string stream_file) +{ + std::unique_ptr ifs(new std::ifstream(stream_file)); + if (!(*ifs)) + { + std::cout << "Can not open stream file: " << stream_file << std::endl; + return false; + } + std::string data_type; + *ifs >> data_type >> std::ws; + StreamReader reader(win.data_state); + reader.ReadStream(*ifs, data_type); + input_streams.emplace_back(std::move(ifs)); + + StartSession(); + return true; +} + +int Session::StartStreamSession(std::unique_ptr &&stream, + const std::string &data_type) +{ + StreamReader reader(win.data_state); + int ierr = reader.ReadStream(*stream, data_type); + if (ierr) { return ierr; } + input_streams.emplace_back(std::move(stream)); + + StartSession(); + return 0; +} + +int Session::StartStreamSession(StreamCollection &&streams) +{ + dbg(); + StreamReader reader(win.data_state); + int ierr = reader.ReadStreams(streams); + if (ierr) { return ierr; } + input_streams = std::move(streams); + + StartSession(); + return 0; +} + +int Session::StartSerialStreamSession(std::unique_ptr &&stream, + const std::string &data_type) +{ + dbg("data_type: '{}'", data_type); + StreamReader reader(win.data_state); + int ierr = reader.ReadStream(*stream, data_type); + if (ierr) { dbg("❌ ERROR ❌"); return ierr; } + + input_streams.emplace_back(std::move(stream)); + StartSession(); + return 0; +} + +/////////////////////////////////////////////////////////////////////////////// +int GLVisLibWindow(//void *win_ptr, + bool fix_elem_orient, + bool save_coloring, bool headless, + const std::string &plot_caption, + std::unique_ptr &&stream, + const std::string &data_type) +{ + const int geom_ref_type = mfem::Quadrature1D::ClosedUniform; + const bool enable_hidpi = true; + + thread_local mfem::GeometryRefiner GLVisGeometryRefiner; + +#ifdef _WIN32 + // Call needed to avoid SDL_Init failure when not substituting main() for + // SDL_main(). + SDL_SetMainReady(); +#endif + + Window win; + dbg(); + // std::this_thread::sleep_for(std::chrono::milliseconds(500)); + + std::cout << std::endl + << " _/_/_/ _/ _/ _/ _/" << std::endl + << " _/ _/ _/ _/ _/_/_/" << std::endl + << " _/ _/_/ _/ _/ _/ _/ _/_/" << std::endl + << " _/ _/ _/ _/ _/ _/ _/_/" << std::endl + << " _/_/_/ _/_/_/_/ _/ _/ _/_/_/" << std::endl + << std::endl; + + SetUseHiDPI(enable_hidpi); + GLVisGeometryRefiner.SetType(geom_ref_type); + + dbg("Main Window structure"); + // auto *win = static_cast(win_ptr); + + std::vector current_sessions; + + dbg("Get main thread"); + GetMainThread(win.headless); + + + dbg("StartStreamSession"); + Session new_session(fix_elem_orient, save_coloring, plot_caption, headless); + + new_session.StartSerialStreamSession(std::move(stream), data_type); + current_sessions.emplace_back(std::move(new_session)); + + + dbg("Starting message loop in main thread"); + MainThreadLoop(); + + dbg("EXIT_SUCCESS"); + return EXIT_SUCCESS; +} + +/////////////////////////////////////////////////////////////////////////////// +void *GLVisLibGetWindow() +{ + static Window win; + return (void*) &win; +} \ No newline at end of file diff --git a/lib/session.hpp b/lib/session.hpp new file mode 100644 index 00000000..96771003 --- /dev/null +++ b/lib/session.hpp @@ -0,0 +1,57 @@ +// Copyright (c) 2010-2026, Lawrence Livermore National Security, LLC. Produced +// at the Lawrence Livermore National Laboratory. All Rights reserved. See files +// LICENSE and NOTICE for details. LLNL-CODE-443271. +// +// This file is part of the GLVis visualization tool and library. For more +// information and source code availability see https://glvis.org. +// +// GLVis is free software; you can redistribute it and/or modify it under the +// terms of the BSD-3 license. We welcome feedback and contributions, see file +// CONTRIBUTING.md for details. +#pragma once + +#include "stream_reader.hpp" +#include "window.hpp" + +#include + +class Session +{ + StreamCollection input_streams; + Window win; + std::thread handler; + +public: + Session(bool fix_elem_orient, + bool save_coloring, + std::string plot_caption, + bool headless) + { + win.data_state.fix_elem_orient = fix_elem_orient; + win.data_state.save_coloring = save_coloring; + win.plot_caption = plot_caption; + win.headless = headless; + } + + Session(Window other_win): win(std::move(other_win)) { } + + ~Session() = default; + + Session(Session&& from) = default; + Session& operator= (Session&& from) = default; + + inline DataState& GetState() { return win.data_state; } + inline const DataState& GetState() const { return win.data_state; } + + void StartSession(); + + bool StartSavedSession(std::string stream_file); + + int StartStreamSession(std::unique_ptr &&stream, + const std::string &data_type); + + int StartStreamSession(StreamCollection &&streams); + + int StartSerialStreamSession(std::unique_ptr &&stream, + const std::string &data_type); +}; \ No newline at end of file diff --git a/makefile b/makefile index 2fe2e491..dc16ca74 100644 --- a/makefile +++ b/makefile @@ -276,7 +276,7 @@ ALL_SOURCE_FILES = \ lib/palettes_base.cpp lib/palettes.cpp lib/palettes_default.cpp \ lib/script_controller.cpp lib/stream_reader.cpp lib/threads.cpp \ lib/vsdata.cpp lib/vssolution.cpp lib/vssolution3d.cpp \ - lib/vsvector.cpp lib/vsvector3d.cpp lib/window.cpp + lib/vsvector.cpp lib/vsvector3d.cpp lib/window.cpp lib/session.cpp OBJC_SOURCE_FILES = $(if $(NOTMAC),,lib/sdl/sdl_mac.mm) DESKTOP_ONLY_SOURCE_FILES = \ lib/gl/renderer_ff.cpp lib/gl2ps.c lib/script_controller.cpp \ @@ -300,7 +300,7 @@ HEADER_FILES = \ lib/openglvis.hpp lib/palettes_base.hpp lib/palettes.hpp \ lib/script_controller.hpp lib/stream_reader.hpp lib/threads.hpp \ lib/visual.hpp lib/vsdata.hpp lib/vssolution.hpp lib/vssolution3d.hpp \ - lib/vsvector.hpp lib/vsvector3d.hpp lib/window.hpp + lib/vsvector.hpp lib/vsvector3d.hpp lib/window.hpp lib/session.hpp DESKTOP_SOURCE_FILES = $(COMMON_SOURCE_FILES) $(DESKTOP_ONLY_SOURCE_FILES) $(LOGO_FILE_CPP) WEB_SOURCE_FILES = $(COMMON_SOURCE_FILES) $(WEB_ONLY_SOURCE_FILES) From 2b340480669313e0acffd2df1cbbe9cc45c9e8a3 Mon Sep 17 00:00:00 2001 From: camierjs Date: Tue, 17 Mar 2026 10:47:24 -0700 Subject: [PATCH 03/15] Fix thread_local GeometryRefiner --- lib/CMakeLists.txt | 11 ----------- lib/session.cpp | 4 ++-- 2 files changed, 2 insertions(+), 13 deletions(-) diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index adecf02b..fccdf5bf 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -115,15 +115,4 @@ else() if (APPLE) target_link_libraries(glvis PUBLIC "-framework Cocoa") endif() - message(STATUS "[🔵 DEFS 🔵] ${_glvis_compile_defs}") - message(STATUS "[🔵 OPTS 🔵] ${_glvis_compile_opts}") - message(STATUS "[🔵 INCS 🔵] ${_glvis_include_dirs}") - message(STATUS "[🔵 LIBS 🔵] ${_glvis_libraries}") - - get_target_property(_link_libs glvis LINK_LIBRARIES) - get_target_property(_link_dirs glvis LINK_DIRECTORIES) - get_target_property(_link_opts glvis LINK_OPTIONS) - message(STATUS "[🔵 LINK LIBS 🔵] ${_link_libs}") - message(STATUS "[🔵 LINK DIRS 🔵] ${_link_dirs}") - message(STATUS "[🔵 LINK OPTS 🔵] ${_link_opts}") endif(EMSCRIPTEN) diff --git a/lib/session.cpp b/lib/session.cpp index 0c732bc4..9987d22a 100644 --- a/lib/session.cpp +++ b/lib/session.cpp @@ -24,6 +24,8 @@ #define dbg(...) #endif +extern thread_local mfem::GeometryRefiner GLVisGeometryRefiner; + void Session::StartSession() { auto funcThread = [](Window w, StreamCollection is) @@ -104,8 +106,6 @@ int GLVisLibWindow(//void *win_ptr, const int geom_ref_type = mfem::Quadrature1D::ClosedUniform; const bool enable_hidpi = true; - thread_local mfem::GeometryRefiner GLVisGeometryRefiner; - #ifdef _WIN32 // Call needed to avoid SDL_Init failure when not substituting main() for // SDL_main(). From e3e1ee58b4f3207ce997495f8a417ced8287bf07 Mon Sep 17 00:00:00 2001 From: camierjs Date: Tue, 17 Mar 2026 14:18:56 -0700 Subject: [PATCH 04/15] Cleanup --- lib/session.cpp | 52 ++++++++++++------------------------------------- lib/session.hpp | 2 +- 2 files changed, 13 insertions(+), 41 deletions(-) diff --git a/lib/session.cpp b/lib/session.cpp index 9987d22a..97fa929a 100644 --- a/lib/session.cpp +++ b/lib/session.cpp @@ -82,39 +82,28 @@ int Session::StartStreamSession(StreamCollection &&streams) return 0; } -int Session::StartSerialStreamSession(std::unique_ptr &&stream, +int Session::StartSerialStreamSession(std::istream &stream, const std::string &data_type) { - dbg("data_type: '{}'", data_type); StreamReader reader(win.data_state); - int ierr = reader.ReadStream(*stream, data_type); + int ierr = reader.ReadStream(stream, data_type); if (ierr) { dbg("❌ ERROR ❌"); return ierr; } - - input_streams.emplace_back(std::move(stream)); StartSession(); return 0; } /////////////////////////////////////////////////////////////////////////////// -int GLVisLibWindow(//void *win_ptr, - bool fix_elem_orient, - bool save_coloring, bool headless, - const std::string &plot_caption, - std::unique_ptr &&stream, - const std::string &data_type) +int GLVisLibWindow(bool fix_elem_orient, + bool save_coloring, bool headless, + const std::string &plot_caption, + std::istream &stream, + std::string data_type) { + dbg(); const int geom_ref_type = mfem::Quadrature1D::ClosedUniform; const bool enable_hidpi = true; -#ifdef _WIN32 - // Call needed to avoid SDL_Init failure when not substituting main() for - // SDL_main(). - SDL_SetMainReady(); -#endif - Window win; - dbg(); - // std::this_thread::sleep_for(std::chrono::milliseconds(500)); std::cout << std::endl << " _/_/_/ _/ _/ _/ _/" << std::endl @@ -127,32 +116,15 @@ int GLVisLibWindow(//void *win_ptr, SetUseHiDPI(enable_hidpi); GLVisGeometryRefiner.SetType(geom_ref_type); - dbg("Main Window structure"); - // auto *win = static_cast(win_ptr); - - std::vector current_sessions; - - dbg("Get main thread"); - GetMainThread(win.headless); + GetMainThread(false); - - dbg("StartStreamSession"); Session new_session(fix_elem_orient, save_coloring, plot_caption, headless); + new_session.StartSerialStreamSession(stream, data_type); - new_session.StartSerialStreamSession(std::move(stream), data_type); + std::vector current_sessions; current_sessions.emplace_back(std::move(new_session)); + MainThreadLoop(false, false); - dbg("Starting message loop in main thread"); - MainThreadLoop(); - - dbg("EXIT_SUCCESS"); return EXIT_SUCCESS; } - -/////////////////////////////////////////////////////////////////////////////// -void *GLVisLibGetWindow() -{ - static Window win; - return (void*) &win; -} \ No newline at end of file diff --git a/lib/session.hpp b/lib/session.hpp index 96771003..23ac7cdd 100644 --- a/lib/session.hpp +++ b/lib/session.hpp @@ -52,6 +52,6 @@ class Session int StartStreamSession(StreamCollection &&streams); - int StartSerialStreamSession(std::unique_ptr &&stream, + int StartSerialStreamSession(std::istream &stream, const std::string &data_type); }; \ No newline at end of file From 0de3fbb06144a4e4327a60ffdc1e8d95dd9e1e71 Mon Sep 17 00:00:00 2001 From: camierjs Date: Tue, 17 Mar 2026 21:54:05 -0700 Subject: [PATCH 05/15] Parallel GLVisLibWindow --- lib/session.cpp | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/lib/session.cpp b/lib/session.cpp index 97fa929a..6643bdcd 100644 --- a/lib/session.cpp +++ b/lib/session.cpp @@ -95,7 +95,6 @@ int Session::StartSerialStreamSession(std::istream &stream, /////////////////////////////////////////////////////////////////////////////// int GLVisLibWindow(bool fix_elem_orient, bool save_coloring, bool headless, - const std::string &plot_caption, std::istream &stream, std::string data_type) { @@ -118,6 +117,7 @@ int GLVisLibWindow(bool fix_elem_orient, GetMainThread(false); + const std::string plot_caption {}; Session new_session(fix_elem_orient, save_coloring, plot_caption, headless); new_session.StartSerialStreamSession(stream, data_type); @@ -128,3 +128,39 @@ int GLVisLibWindow(bool fix_elem_orient, return EXIT_SUCCESS; } + +/////////////////////////////////////////////////////////////////////////////// +int GLVisLibWindow(bool fix_elem_orient, + bool save_coloring, bool headless, + StreamCollection &&streams) +{ + dbg(); + const int geom_ref_type = mfem::Quadrature1D::ClosedUniform; + const bool enable_hidpi = true; + + Window win; + + std::cout << std::endl + << " _/_/_/ _/ _/ _/ _/" << std::endl + << " _/ _/ _/ _/ _/_/_/" << std::endl + << " _/ _/_/ _/ _/ _/ _/ _/_/" << std::endl + << " _/ _/ _/ _/ _/ _/ _/_/" << std::endl + << " _/_/_/ _/_/_/_/ _/ _/ _/_/_/" << std::endl + << std::endl; + + SetUseHiDPI(enable_hidpi); + GLVisGeometryRefiner.SetType(geom_ref_type); + + GetMainThread(false); + + const std::string plot_caption {}; + Session new_session(fix_elem_orient, save_coloring, plot_caption, headless); + new_session.StartStreamSession(std::move(streams)); + + std::vector current_sessions; + current_sessions.emplace_back(std::move(new_session)); + + MainThreadLoop(false, false); + + return EXIT_SUCCESS; +} From 4a48565075d79d7ab7bb11d1dab65e778ef162d7 Mon Sep 17 00:00:00 2001 From: camierjs Date: Wed, 18 Mar 2026 12:53:55 -0700 Subject: [PATCH 06/15] Split stream session file --- lib/CMakeLists.txt | 1 + lib/session.cpp | 99 +----------------------------------------- lib/stream_session.cpp | 54 +++++++++++++++++++++++ makefile | 3 +- 4 files changed, 59 insertions(+), 98 deletions(-) create mode 100644 lib/stream_session.cpp diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index fccdf5bf..2583c134 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -34,6 +34,7 @@ list(APPEND SOURCES script_controller.cpp session.cpp stream_reader.cpp + stream_session.cpp vsdata.cpp vssolution.cpp vssolution3d.cpp diff --git a/lib/session.cpp b/lib/session.cpp index 6643bdcd..0ec4fb9c 100644 --- a/lib/session.cpp +++ b/lib/session.cpp @@ -10,21 +10,10 @@ // CONTRIBUTING.md for details. #include "threads.hpp" // IWYU pragma: keep for GLVisCommand -#include "aux_vis.hpp" // SetUseHiDPI -#include "session.hpp" - -#include +#include -#ifdef NVTX_DBG_HPP -#undef NVTX_COLOR -#define NVTX_COLOR ::nvtx::kGold -#include NVTX_DBG_HPP -#else -#define dbg(...) -#endif - -extern thread_local mfem::GeometryRefiner GLVisGeometryRefiner; +#include "session.hpp" void Session::StartSession() { @@ -72,7 +61,6 @@ int Session::StartStreamSession(std::unique_ptr &&stream, int Session::StartStreamSession(StreamCollection &&streams) { - dbg(); StreamReader reader(win.data_state); int ierr = reader.ReadStreams(streams); if (ierr) { return ierr; } @@ -81,86 +69,3 @@ int Session::StartStreamSession(StreamCollection &&streams) StartSession(); return 0; } - -int Session::StartSerialStreamSession(std::istream &stream, - const std::string &data_type) -{ - StreamReader reader(win.data_state); - int ierr = reader.ReadStream(stream, data_type); - if (ierr) { dbg("❌ ERROR ❌"); return ierr; } - StartSession(); - return 0; -} - -/////////////////////////////////////////////////////////////////////////////// -int GLVisLibWindow(bool fix_elem_orient, - bool save_coloring, bool headless, - std::istream &stream, - std::string data_type) -{ - dbg(); - const int geom_ref_type = mfem::Quadrature1D::ClosedUniform; - const bool enable_hidpi = true; - - Window win; - - std::cout << std::endl - << " _/_/_/ _/ _/ _/ _/" << std::endl - << " _/ _/ _/ _/ _/_/_/" << std::endl - << " _/ _/_/ _/ _/ _/ _/ _/_/" << std::endl - << " _/ _/ _/ _/ _/ _/ _/_/" << std::endl - << " _/_/_/ _/_/_/_/ _/ _/ _/_/_/" << std::endl - << std::endl; - - SetUseHiDPI(enable_hidpi); - GLVisGeometryRefiner.SetType(geom_ref_type); - - GetMainThread(false); - - const std::string plot_caption {}; - Session new_session(fix_elem_orient, save_coloring, plot_caption, headless); - new_session.StartSerialStreamSession(stream, data_type); - - std::vector current_sessions; - current_sessions.emplace_back(std::move(new_session)); - - MainThreadLoop(false, false); - - return EXIT_SUCCESS; -} - -/////////////////////////////////////////////////////////////////////////////// -int GLVisLibWindow(bool fix_elem_orient, - bool save_coloring, bool headless, - StreamCollection &&streams) -{ - dbg(); - const int geom_ref_type = mfem::Quadrature1D::ClosedUniform; - const bool enable_hidpi = true; - - Window win; - - std::cout << std::endl - << " _/_/_/ _/ _/ _/ _/" << std::endl - << " _/ _/ _/ _/ _/_/_/" << std::endl - << " _/ _/_/ _/ _/ _/ _/ _/_/" << std::endl - << " _/ _/ _/ _/ _/ _/ _/_/" << std::endl - << " _/_/_/ _/_/_/_/ _/ _/ _/_/_/" << std::endl - << std::endl; - - SetUseHiDPI(enable_hidpi); - GLVisGeometryRefiner.SetType(geom_ref_type); - - GetMainThread(false); - - const std::string plot_caption {}; - Session new_session(fix_elem_orient, save_coloring, plot_caption, headless); - new_session.StartStreamSession(std::move(streams)); - - std::vector current_sessions; - current_sessions.emplace_back(std::move(new_session)); - - MainThreadLoop(false, false); - - return EXIT_SUCCESS; -} diff --git a/lib/stream_session.cpp b/lib/stream_session.cpp new file mode 100644 index 00000000..abe70e98 --- /dev/null +++ b/lib/stream_session.cpp @@ -0,0 +1,54 @@ +// Copyright (c) 2010-2026, Lawrence Livermore National Security, LLC. Produced +// at the Lawrence Livermore National Laboratory. All Rights reserved. See files +// LICENSE and NOTICE for details. LLNL-CODE-443271. +// +// This file is part of the GLVis visualization tool and library. For more +// information and source code availability see https://glvis.org. +// +// GLVis is free software; you can redistribute it and/or modify it under the +// terms of the BSD-3 license. We welcome feedback and contributions, see file +// CONTRIBUTING.md for details. + +#include "threads.hpp" // IWYU pragma: keep for GLVisCommand +#include "aux_vis.hpp" // SetUseHiDPI + +#include "session.hpp" + +#include + +extern thread_local mfem::GeometryRefiner GLVisGeometryRefiner; + +int GLVisStreamSession(const bool fix_elem_orient, + const bool save_coloring, + const bool headless, + const std::string &plot_caption, + StreamCollection &&streams) +{ + const int geom_ref_type = mfem::Quadrature1D::ClosedUniform; + const bool enable_hidpi = true; + + Window win; + + std::cout << std::endl + << " _/_/_/ _/ _/ _/ _/" << std::endl + << " _/ _/ _/ _/ _/_/_/" << std::endl + << " _/ _/_/ _/ _/ _/ _/ _/_/" << std::endl + << " _/ _/ _/ _/ _/ _/ _/_/" << std::endl + << " _/_/_/ _/_/_/_/ _/ _/ _/_/_/" << std::endl + << std::endl; + + SetUseHiDPI(enable_hidpi); + GLVisGeometryRefiner.SetType(geom_ref_type); + + GetMainThread(false); + + Session new_session(fix_elem_orient, save_coloring, plot_caption, headless); + new_session.StartStreamSession(std::move(streams)); + + std::vector current_sessions; + current_sessions.emplace_back(std::move(new_session)); + + MainThreadLoop(false, false); + + return EXIT_SUCCESS; +} diff --git a/makefile b/makefile index dc16ca74..949c176e 100644 --- a/makefile +++ b/makefile @@ -276,7 +276,8 @@ ALL_SOURCE_FILES = \ lib/palettes_base.cpp lib/palettes.cpp lib/palettes_default.cpp \ lib/script_controller.cpp lib/stream_reader.cpp lib/threads.cpp \ lib/vsdata.cpp lib/vssolution.cpp lib/vssolution3d.cpp \ - lib/vsvector.cpp lib/vsvector3d.cpp lib/window.cpp lib/session.cpp + lib/vsvector.cpp lib/vsvector3d.cpp lib/window.cpp \ + lib/session.cpp lib/stream_session.cpp OBJC_SOURCE_FILES = $(if $(NOTMAC),,lib/sdl/sdl_mac.mm) DESKTOP_ONLY_SOURCE_FILES = \ lib/gl/renderer_ff.cpp lib/gl2ps.c lib/script_controller.cpp \ From 515251355f6b20d0325a350311925f127a19f7bd Mon Sep 17 00:00:00 2001 From: camierjs Date: Wed, 18 Mar 2026 13:10:12 -0700 Subject: [PATCH 07/15] Handle GLVisStreamSession serial and data type --- lib/session.cpp | 12 ++++++++++++ lib/session.hpp | 4 ++++ lib/stream_session.cpp | 10 +++++++++- 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/lib/session.cpp b/lib/session.cpp index 0ec4fb9c..cbf51eeb 100644 --- a/lib/session.cpp +++ b/lib/session.cpp @@ -69,3 +69,15 @@ int Session::StartStreamSession(StreamCollection &&streams) StartSession(); return 0; } + +int Session::StartStreamSession(std::unique_ptr &&stream, + const std::string &data_type) +{ + StreamReader reader(win.data_state); + int ierr = reader.ReadStream(*stream, data_type); + if (ierr) { return ierr; } + input_streams.emplace_back(std::move(stream)); + + StartSession(); + return 0; +} diff --git a/lib/session.hpp b/lib/session.hpp index 23ac7cdd..6819116e 100644 --- a/lib/session.hpp +++ b/lib/session.hpp @@ -50,8 +50,12 @@ class Session int StartStreamSession(std::unique_ptr &&stream, const std::string &data_type); + int StartStreamSession(std::unique_ptr &&stream, + const std::string &data_type); + int StartStreamSession(StreamCollection &&streams); int StartSerialStreamSession(std::istream &stream, const std::string &data_type); + }; \ No newline at end of file diff --git a/lib/stream_session.cpp b/lib/stream_session.cpp index abe70e98..0a2baf4d 100644 --- a/lib/stream_session.cpp +++ b/lib/stream_session.cpp @@ -22,6 +22,7 @@ int GLVisStreamSession(const bool fix_elem_orient, const bool save_coloring, const bool headless, const std::string &plot_caption, + const std::string &data_type, StreamCollection &&streams) { const int geom_ref_type = mfem::Quadrature1D::ClosedUniform; @@ -43,7 +44,14 @@ int GLVisStreamSession(const bool fix_elem_orient, GetMainThread(false); Session new_session(fix_elem_orient, save_coloring, plot_caption, headless); - new_session.StartStreamSession(std::move(streams)); + if (streams.size() == 1 && data_type == "solution") + { + new_session.StartStreamSession(std::move(streams[0]), data_type); + } + else + { + new_session.StartStreamSession(std::move(streams)); + } std::vector current_sessions; current_sessions.emplace_back(std::move(new_session)); From 2b0b7b9ade2585feb6647c1841191094dab73a01 Mon Sep 17 00:00:00 2001 From: camierjs Date: Wed, 18 Mar 2026 17:38:40 -0700 Subject: [PATCH 08/15] avoid 'typeinfo for mfem::socketstream' rtti error --- lib/threads.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/threads.cpp b/lib/threads.cpp index d6c4690d..1f30988c 100644 --- a/lib/threads.cpp +++ b/lib/threads.cpp @@ -1630,12 +1630,14 @@ void communication_thread::execute() } } - for (size_t i = 0; i < is.size(); i++) - { - socketstream *isock = dynamic_cast(is[i].get()); - if (isock) - { - isock->close(); - } - } + // avoid 'typeinfo for mfem::socketstream' rtti error + // until two stage compilation + // for (size_t i = 0; i < is.size(); i++) + // { + // socketstream *isock = dynamic_cast(is[i].get()); + // if (isock) + // { + // isock->close(); + // } + // } } From 9a7ef4ade8a6072807086dd9bb0aafc6bd809a20 Mon Sep 17 00:00:00 2001 From: camierjs Date: Mon, 23 Mar 2026 20:15:18 -0700 Subject: [PATCH 09/15] Add GLVIS_BUILD_LIB_ONLY --- CMakeLists.txt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a9f1ee7d..c1313e17 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -328,6 +328,10 @@ message(STATUS "CMAKE_INSTALL_PREFIX = ${CMAKE_INSTALL_PREFIX}") add_subdirectory(lib) add_subdirectory(share) +if (GLVIS_BUILD_LIB_ONLY) + return() +endif() + if(NOT EMSCRIPTEN) # Setup the GLVis executable @@ -392,7 +396,6 @@ if(NOT EMSCRIPTEN) execute_process(COMMAND codesign --force --sign - ${CMAKE_INSTALL_PREFIX}/GLVis.app) ]] COMPONENT RUNTIME) endif(APPLE) - endif(NOT EMSCRIPTEN) if(ENABLE_TESTS) From 815c16d01658b1acd3f63f1dd5cbb45fc0787214 Mon Sep 17 00:00:00 2001 From: camierjs Date: Thu, 25 Jun 2026 11:10:55 +0200 Subject: [PATCH 10/15] Propagate keep_attr --- lib/session.hpp | 2 ++ lib/stream_session.cpp | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/session.hpp b/lib/session.hpp index 6819116e..395e20e8 100644 --- a/lib/session.hpp +++ b/lib/session.hpp @@ -24,11 +24,13 @@ class Session public: Session(bool fix_elem_orient, bool save_coloring, + bool keep_attr, std::string plot_caption, bool headless) { win.data_state.fix_elem_orient = fix_elem_orient; win.data_state.save_coloring = save_coloring; + win.data_state.keep_attr = keep_attr; win.plot_caption = plot_caption; win.headless = headless; } diff --git a/lib/stream_session.cpp b/lib/stream_session.cpp index 0a2baf4d..04262b9c 100644 --- a/lib/stream_session.cpp +++ b/lib/stream_session.cpp @@ -27,6 +27,7 @@ int GLVisStreamSession(const bool fix_elem_orient, { const int geom_ref_type = mfem::Quadrature1D::ClosedUniform; const bool enable_hidpi = true; + const bool keep_attr = true; Window win; @@ -43,7 +44,8 @@ int GLVisStreamSession(const bool fix_elem_orient, GetMainThread(false); - Session new_session(fix_elem_orient, save_coloring, plot_caption, headless); + Session new_session(fix_elem_orient, save_coloring, keep_attr, plot_caption, + headless); if (streams.size() == 1 && data_type == "solution") { new_session.StartStreamSession(std::move(streams[0]), data_type); From 200e42d5990d2b279ff3b2ae31aaab487d1ba223 Mon Sep 17 00:00:00 2001 From: camierjs Date: Thu, 25 Jun 2026 13:50:31 +0200 Subject: [PATCH 11/15] Add keep_attr to GLVisStreamSession --- lib/stream_session.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/stream_session.cpp b/lib/stream_session.cpp index 04262b9c..543ee21b 100644 --- a/lib/stream_session.cpp +++ b/lib/stream_session.cpp @@ -20,6 +20,7 @@ extern thread_local mfem::GeometryRefiner GLVisGeometryRefiner; int GLVisStreamSession(const bool fix_elem_orient, const bool save_coloring, + const bool keep_attr, const bool headless, const std::string &plot_caption, const std::string &data_type, @@ -27,7 +28,6 @@ int GLVisStreamSession(const bool fix_elem_orient, { const int geom_ref_type = mfem::Quadrature1D::ClosedUniform; const bool enable_hidpi = true; - const bool keep_attr = true; Window win; From 21092de16f27be83829c9a85ee4e5e5d9485f75b Mon Sep 17 00:00:00 2001 From: camierjs Date: Thu, 25 Jun 2026 21:37:55 +0200 Subject: [PATCH 12/15] Add stream_session header file to be installed --- CMakeLists.txt | 4 ++++ lib/CMakeLists.txt | 1 + lib/stream_session.hpp | 23 +++++++++++++++++++++++ 3 files changed, 28 insertions(+) create mode 100644 lib/stream_session.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index c1313e17..3d41da18 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -355,6 +355,10 @@ if(NOT EMSCRIPTEN) # Install the executable install(TARGETS glvis-exe RUNTIME DESTINATION bin) + # Install the stream_session.hpp header file + set_target_properties(glvis PROPERTIES PUBLIC_HEADER stream_session.hpp) + install(TARGETS glvis PUBLIC_HEADER DESTINATION include/glvis) + # Install the gnutls helper script if (MFEM_USE_GNUTLS) install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/glvis-keygen.sh diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 2583c134..3ef5ee78 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -71,6 +71,7 @@ list(APPEND HEADERS script_controller.hpp session.hpp stream_reader.hpp + stream_session.hpp visual.hpp vsdata.hpp vssolution.hpp diff --git a/lib/stream_session.hpp b/lib/stream_session.hpp new file mode 100644 index 00000000..d7a07dce --- /dev/null +++ b/lib/stream_session.hpp @@ -0,0 +1,23 @@ +// Copyright (c) 2010-2026, Lawrence Livermore National Security, LLC. Produced +// at the Lawrence Livermore National Laboratory. All Rights reserved. See files +// LICENSE and NOTICE for details. LLNL-CODE-443271. +// +// This file is part of the GLVis visualization tool and library. For more +// information and source code availability see https://glvis.org. +// +// GLVis is free software; you can redistribute it and/or modify it under the +// terms of the BSD-3 license. We welcome feedback and contributions, see file +// CONTRIBUTING.md for details. +#pragma once + +#include +#include +#include + +int GLVisStreamSession(const bool fix_elem_orient, + const bool save_coloring, + const bool keep_attr, + const bool headless, + const std::string &plot_caption, + const std::string &data_type, + std::vector> &&streams); \ No newline at end of file From 7ba406da157cd764f623a01d68493eb2ebcc813a Mon Sep 17 00:00:00 2001 From: camierjs Date: Tue, 30 Jun 2026 11:14:27 -0700 Subject: [PATCH 13/15] Fix cmake tests baseline nominal filename. Update rebaseline to copy outputs//test.nominal..png and skip comparison when local baseline files are missing. --- tests/CMakeLists.txt | 6 +++--- tests/glvis_driver.py | 6 ++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 5c74115e..1784a64a 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -65,10 +65,10 @@ foreach(test_name IN LISTS stream_tests) COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_SOURCE_DIR}/data/baselines/local COMMAND ${CMAKE_COMMAND} -E copy - ${CMAKE_CURRENT_BINARY_DIR}/test.${test_name}.png - ${CMAKE_CURRENT_SOURCE_DIR}/data/baselines/local + ${CMAKE_CURRENT_BINARY_DIR}/outputs/${test_name}/test.nominal.${test_name}.png + ${CMAKE_CURRENT_SOURCE_DIR}/data/baselines/local/test.${test_name}.saved.png DEPENDS - ${CMAKE_CURRENT_BINARY_DIR}/test.${test_name}.png + ${CMAKE_CURRENT_BINARY_DIR}/outputs/${test_name}/test.nominal.${test_name}.png VERBATIM) add_dependencies(rebaseline _rebaseline_stream_${test_name}) diff --git a/tests/glvis_driver.py b/tests/glvis_driver.py index c29a9875..678656ac 100644 --- a/tests/glvis_driver.py +++ b/tests/glvis_driver.py @@ -34,6 +34,9 @@ def compare_images( return False # Try to open baseline image + if not os.path.isfile(baseline_file): + print("[IGNORE] No baseline exists to compare against.") + return True baseline_img = imread(baseline_file) if baseline_img is None: print("[IGNORE] No baseline exists to compare against.") @@ -153,6 +156,9 @@ def test_stream( if baseline: baseline_name = f"{baseline}/test.{test_name}.saved.png" + if not os.path.isfile(baseline_name): + print("[IGNORE] No baseline exists to compare against.") + return True test_baseline = compare_images(baseline_name, output_name) generate_image_diffs(baseline_name, output_name, absdiff_name, reldiff_name) # Generate an interactive html plot, only if the test fails From 766239b809eb96b7b790d84e7e54388b7b92dad7 Mon Sep 17 00:00:00 2001 From: camierjs Date: Tue, 30 Jun 2026 12:47:14 -0700 Subject: [PATCH 14/15] Remove un-needed IGNORE --- tests/glvis_driver.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/tests/glvis_driver.py b/tests/glvis_driver.py index 678656ac..c29a9875 100644 --- a/tests/glvis_driver.py +++ b/tests/glvis_driver.py @@ -34,9 +34,6 @@ def compare_images( return False # Try to open baseline image - if not os.path.isfile(baseline_file): - print("[IGNORE] No baseline exists to compare against.") - return True baseline_img = imread(baseline_file) if baseline_img is None: print("[IGNORE] No baseline exists to compare against.") @@ -156,9 +153,6 @@ def test_stream( if baseline: baseline_name = f"{baseline}/test.{test_name}.saved.png" - if not os.path.isfile(baseline_name): - print("[IGNORE] No baseline exists to compare against.") - return True test_baseline = compare_images(baseline_name, output_name) generate_image_diffs(baseline_name, output_name, absdiff_name, reldiff_name) # Generate an interactive html plot, only if the test fails From 83aa1356392ad6168f765364f0e70b616dbb88ae Mon Sep 17 00:00:00 2001 From: camierjs Date: Tue, 30 Jun 2026 15:31:23 -0700 Subject: [PATCH 15/15] Point tests/data at the updated macos-latest baseline for sdl3/sdl2-compat --- tests/data | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/data b/tests/data index 2930875a..1166a34e 160000 --- a/tests/data +++ b/tests/data @@ -1 +1 @@ -Subproject commit 2930875afd504d9f6b4835de65abfd43c0338f0f +Subproject commit 1166a34eb7790867ac448eb73caed19638d1da9e