Line data Source code
1 : // SPDX-FileCopyrightText: 2024 Daniel Abele <daniel.abele@dlr.de> 2 : // 3 : // SPDX-License-Identifier: BSD-3-Clause 4 : 5 : #include "issm-precice/devel.hpp" 6 : #include "issm-precice/mpiinit.hpp" 7 : #include "fmt/format.h" 8 : #include <chrono> 9 : #include <thread> 10 : #include <array> 11 : #include <cstdio> 12 : 13 : namespace ipc 14 : { 15 : using namespace std::literals::chrono_literals; 16 : 17 0 : void wait_for_debugger(MPI_Comm comm, int rank) 18 : { 19 0 : if (rank < 0 || ipc::mpi_rank(comm) == rank) 20 : { 21 : //get system info, maybe not portable 22 0 : std::array<char, 256> ahostname = {0}; 23 0 : gethostname(ahostname.data(), ahostname.size()); 24 0 : auto hostname = std::string(ahostname.data()); 25 0 : auto pid = getpid(); 26 : 27 0 : fmt::println(stderr, "PID {} on {} waiting for attached debugger...", pid, hostname); 28 0 : fflush(stderr); 29 : 30 0 : volatile int i = 0; //override this variable in the debugger to continue 31 0 : while (0 == i) 32 : { 33 0 : std::this_thread::sleep_for(1s); 34 : } 35 0 : } 36 0 : } 37 : 38 : } // namespace ipc