Branch data Line data Source code
1 : : // ***************************************************************************** 2 : : /*! 3 : : \file src/Walker/Collector.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++ module interface file for collecting contributions from 9 : : Integrators 10 : : \details Charm++ module interface file for collecting contributions from 11 : : Integrators. 12 : : */ 13 : : // ***************************************************************************** 14 : : 15 : : #include "Collector.hpp" 16 : : 17 : : namespace walker { 18 : : 19 : : //! \brief Charm++ PDF merger reducer 20 : : //! \details This variable is defined here in the .C file and declared as extern 21 : : //! in Collector.h. If instead one defines it in the header (as static), 22 : : //! a new version of the variable is created any time the header file is 23 : : //! included, yielding no compilation nor linking errors. However, that leads 24 : : //! to runtime errors, since Collector::registerPDFMerger(), a Charm++ 25 : : //! "initnode" entry method, *may* fill one while contribute() may use the 26 : : //! other (unregistered) one. Result: undefined behavior, segfault, and 27 : : //! formatting the internet ... 28 : : CkReduction::reducerType PDFMerger; 29 : : 30 : : } 31 : : 32 : : using walker::Collector; 33 : : 34 : : void 35 : 5509065 : Collector::chareOrd( const std::vector< tk::real >& ord, 36 : : const std::vector< tk::UniPDF >& updf, 37 : : const std::vector< tk::BiPDF >& bpdf, 38 : : const std::vector< tk::TriPDF >& tpdf ) 39 : : // ***************************************************************************** 40 : : // Chares contribute ordinary moments and ordinary PDFs 41 : : //! \param[in] ord Vector of partial sums for the estimation of ordinary moments 42 : : //! \param[in] updf Vector of partial sums for the estimation of univariate 43 : : //! ordinary PDFs 44 : : //! \param[in] bpdf Vector of partial sums for the estimation of bivariate 45 : : //! ordinary PDFs 46 : : //! \param[in] tpdf Vector of partial sums for the estimation of trivariate 47 : : //! ordinary PDFs 48 : : //! \note This function does not have to be declared as a Charm++ entry 49 : : //! method since it is always called by chares on the same PE. 50 : : // ***************************************************************************** 51 : : { 52 : 5509065 : ++m_nord; 53 : : 54 [ + + ]: 32174248 : for (std::size_t i=0; i<m_ordinary.size(); ++i) m_ordinary[i] += ord[i]; 55 : : 56 : : // Add contribution from worker chares to partial sums on my PE 57 : : std::size_t i = 0; 58 [ + + ]: 5756289 : for (const auto& p : updf) m_ordupdf[i++].addPDF( p ); 59 : : i = 0; 60 [ + + ]: 5515077 : for (const auto& p : bpdf) m_ordbpdf[i++].addPDF( p ); 61 : : i = 0; 62 [ + + ]: 5515077 : for (const auto& p : tpdf) m_ordtpdf[i++].addPDF( p ); 63 : : 64 : : // If all chares on my PE have contributed, send partial sums to host 65 [ + + ]: 5509065 : if (m_nord == m_nchare) { 66 : : 67 : : // Create Charm++ callback function for reduction 68 : : CkCallback c1( CkReductionTarget( Distributor, estimateOrd ), m_hostproxy ); 69 : : 70 : : // Contribute partial sums to host via Charm++ reduction 71 [ + - ]: 1511598 : contribute( static_cast< int >( m_ordinary.size() * sizeof(tk::real) ), 72 : : m_ordinary.data(), CkReduction::sum_double, c1 ); 73 : : 74 : : // Zero counters for next collection operation 75 : : std::fill( begin(m_ordinary), end(m_ordinary), 0.0 ); 76 : : 77 : : // Serialize vector of PDFs to raw stream 78 [ + - ]: 1511598 : auto stream = tk::serialize( m_ordupdf, m_ordbpdf, m_ordtpdf ); 79 : : 80 : : // Create Charm++ callback function for reduction. 81 : : // Distributor::estimateOrdPDF() will be the final target of the reduction 82 : : // where the results of the reduction will appear. 83 : : CkCallback c2( CkIndex_Distributor::estimateOrdPDF(nullptr), m_hostproxy ); 84 : : 85 : : // Contribute serialized PDFs of partial sums to host via Charm++ reduction 86 [ + - ]: 1511598 : contribute( stream.first, stream.second.get(), PDFMerger, c2 ); 87 : : 88 : : // Zero counters for next collection operation 89 [ + + ]: 1758822 : for (auto& p : m_ordupdf) p.zero(); 90 [ + + ]: 1517610 : for (auto& p : m_ordbpdf) p.zero(); 91 [ + + ]: 1517610 : for (auto& p : m_ordtpdf) p.zero(); 92 : : 93 : 1511598 : m_nord = 0; 94 : : } 95 : 5509065 : } 96 : : 97 : : void 98 : 5509065 : Collector::chareCen( const std::vector< tk::real >& cen, 99 : : const std::vector< tk::UniPDF >& updf, 100 : : const std::vector< tk::BiPDF >& bpdf, 101 : : const std::vector< tk::TriPDF >& tpdf ) 102 : : // ***************************************************************************** 103 : : // Chares contribute central moments and central PDFs 104 : : //! \param[in] cen Vector of partial sums for the estimation of central moments 105 : : //! \param[in] updf Vector of partial sums for the estimation of univariate 106 : : //! central PDFs 107 : : //! \param[in] bpdf Vector of partial sums for the estimation of bivariate 108 : : //! central PDFs 109 : : //! \param[in] tpdf Vector of partial sums for the estimation of trivariate 110 : : //! central PDFs 111 : : //! \note This function does not have to be declared as a Charm++ entry 112 : : //! method since it is always called by chares on the same PE. 113 : : // ***************************************************************************** 114 : : { 115 : 5509065 : ++m_ncen; 116 : : 117 [ + + ]: 57465562 : for (std::size_t i=0; i<m_central.size(); ++i) m_central[i] += cen[i]; 118 : : 119 : : // Add contribution from worker chares to partial sums on my PE 120 : : std::size_t i = 0; 121 [ + + ]: 5514273 : for (const auto& p : updf) m_cenupdf[i++].addPDF( p ); 122 : : i = 0; 123 [ + + ]: 5629077 : for (const auto& p : bpdf) m_cenbpdf[i++].addPDF( p ); 124 : : i = 0; 125 [ + + ]: 5515077 : for (const auto& p : tpdf) m_centpdf[i++].addPDF( p ); 126 : : 127 : : // If all chares on my PE have contributed, send partial sums to host 128 [ + + ]: 5509065 : if (m_ncen == m_nchare) { 129 : : 130 : : // Create Charm++ callback function for reduction 131 : : CkCallback c1( CkReductionTarget( Distributor, estimateCen ), m_hostproxy ); 132 : : 133 : : // Contribute partial sums to host via Charm++ reduction 134 [ + - ]: 1511598 : contribute( static_cast< int >( m_central.size() * sizeof(tk::real) ), 135 : : m_central.data(), CkReduction::sum_double, c1 ); 136 : : 137 : : // Zero counters for next collection operation 138 : : std::fill( begin(m_central), end(m_central), 0.0 ); 139 : : 140 : : // Serialize vector of PDFs to raw stream 141 [ + - ]: 1511598 : auto stream = tk::serialize( m_cenupdf, m_cenbpdf, m_centpdf ); 142 : : 143 : : // Create Charm++ callback function for reduction. 144 : : // Distributor::estimateCenPDF() will be the final target of the reduction 145 : : // where the results of the reduction will appear. 146 : : CkCallback c2( CkIndex_Distributor::estimateCenPDF(nullptr), m_hostproxy ); 147 : : 148 : : // Contribute serialized PDFs of partial sums to host via Charm++ reduction 149 [ + - ]: 1511598 : contribute( stream.first, stream.second.get(), PDFMerger, c2 ); 150 : : 151 : : // Zero counters for next collection operation 152 [ + + ]: 1516806 : for (auto& p : m_cenupdf) p.zero(); 153 [ + + ]: 1631610 : for (auto& p : m_cenbpdf) p.zero(); 154 [ + + ]: 1517610 : for (auto& p : m_centpdf) p.zero(); 155 : : 156 : 1511598 : m_ncen = 0; 157 : : } 158 : 5509065 : } 159 : : 160 : : #include "NoWarning/collector.def.h"