Branch data Line data Source code
1 : : // ***************************************************************************** 2 : : /*! 3 : : \file src/Base/ChareStateCollector.cpp 4 : : \copyright 2012-2015 J. Bakosi, 5 : : 2016-2018 Los Alamos National Security, LLC., 6 : : 2019-2021 Triad National Security, LLC. 7 : : All rights reserved. See the LICENSE file for details. 8 : : \brief Charm++ chare state collector group 9 : : \details Charm++ chare state collectory group used for debugging. 10 : : */ 11 : : // ***************************************************************************** 12 : : 13 : : #include <vector> 14 : : #include <unordered_map> 15 : : 16 : : #include "ChareStateCollector.hpp" 17 : : #include "HashMapReducer.hpp" 18 : : 19 : : namespace tk { 20 : : 21 : : static CkReduction::reducerType stateMerger; 22 : : 23 : : } // tk:: 24 : : 25 : : using tk::ChareStateCollector; 26 : : 27 : : void 28 : 36 : ChareStateCollector::registerReducers() 29 : : // ***************************************************************************** 30 : : // Configure Charm++ reduction types 31 : : //! \details Since this is a [initnode] routine, the runtime system executes the 32 : : //! routine exactly once on every logical node early on in the Charm++ init 33 : : //! sequence. Must be static as it is called without an object. See also: 34 : : //! Section "Initializations at Program Startup" at in the Charm++ manual 35 : : //! http://charm.cs.illinois.edu/manuals/html/charm++/manual.html. 36 : : // ***************************************************************************** 37 : : { 38 : 36 : stateMerger = 39 : 36 : CkReduction::addReducer( tk::mergeHashMap< int, decltype(m_state) > ); 40 : 36 : } 41 : : 42 : : void 43 : 0 : ChareStateCollector::insert( const std::string& ch, int id, int pe, uint64_t it, 44 : : const std::string& fn ) 45 : : // ***************************************************************************** 46 : : // Insert new state entry 47 : : //! \param[in] ch Chare name 48 : : //! \param[in] id Chare thisIndex 49 : : //! \param[in] pe Chare PE happens to reside on 50 : : //! \param[in] it Iteration count 51 : : //! \param[in] fn Chare member function name 52 : : // ***************************************************************************** 53 : : { 54 : 0 : m_state.push_back( ChareState{{ ch, id, pe, it, fn, m_timer.dsec() }} ); 55 : 0 : } 56 : : 57 : : void 58 [ - - ]: 0 : ChareStateCollector::collect( bool error, CkCallback cb ) 59 : : // ***************************************************************************** 60 : : // Collect chare state 61 : : //! \param[in] error If true we are called due to an error, if false, user is 62 : : //! just curious 63 : : //! \param[in] cb Callback to use for the reduction 64 : : // ***************************************************************************** 65 : : { 66 : : // Will aggregate states across all PEs categorized by PEs 67 [ - - ][ - - ]: 0 : std::unordered_map< int, std::vector< ChareState > > s{{ CkMyPe(), m_state }}; 68 : : 69 : : // If we are called due to an error, encode a -1 chare id from which the 70 : : // receiving side will know about the error. 71 [ - - ][ - - ]: 0 : if (error) s[-1]; 72 : : 73 : : // Aggregate states collected by this PE across all PEs 74 [ - - ]: 0 : auto stream = tk::serialize( s ); 75 [ - - ]: 0 : contribute( stream.first, stream.second.get(), stateMerger, cb ); 76 : 0 : } 77 : : 78 : : #include "NoWarning/charestatecollector.def.h"