GEOS
TableMpiComponents.hpp
Go to the documentation of this file.
1 /*
2  * ------------------------------------------------------------------------------------------------------------
3  * SPDX-License-Identifier: LGPL-2.1-only
4  *
5  * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC
6  * Copyright (c) 2018-2024 TotalEnergies
7  * Copyright (c) 2018-2024 The Board of Trustees of the Leland Stanford Junior University
8  * Copyright (c) 2023-2024 Chevron
9  * Copyright (c) 2019- GEOS/GEOSX Contributors
10  * All rights reserved
11  *
12  * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details.
13  * ------------------------------------------------------------------------------------------------------------
14  */
15 
21 #ifndef GEOS_COMMON_FORMAT_TABLE_TABLEMPICOMPONENTS_HPP
22 #define GEOS_COMMON_FORMAT_TABLE_TABLEMPICOMPONENTS_HPP
23 
24 #include "TableFormatter.hpp"
25 
26 namespace geos
27 {
28 
34 {
38  string m_rankTitle;
39 };
40 
46 {
47 public:
58 
64  TableTextMpiFormatter( TableLayout const & tableLayout,
65  TableMpiLayout mpiLayout = TableMpiLayout() );
66 
76  template< typename DATASOURCE >
77  void toStream( std::ostream & outputStream, DATASOURCE const & tableData ) const;
78 
85  void setSortingFunc( SortingFunc && func )
86  { m_sortingFunctor = std::move( func ); }
87 
88 
89 private:
90 
91  // hiding toString() methods as they are not implemented with MPI support.
92  using Base::toString;
93 
94  struct Status
95  {
96  bool const m_isMasterRank;
97  bool const m_isContributing;
98  bool m_hasContent;
99  string m_sepLine;
100  };
101 
102  TableMpiLayout m_mpiLayout;
103 
106  std::optional< SortingFunc > m_sortingFunctor;
107 
114  void stretchColumnsByRanks( stdVector< size_t > & columnsWidth,
115  Status const & status ) const;
116 
121  TableData gatherTableDataRank0( TableData const & localTableData ) const;
122 
123 
131  void gatherAndOutputTableDataInRankOrder( std::ostream & tableOutput,
132  CellLayoutRows const & dataCellsLayout,
133  PreparedTableLayout const & tableLayout,
134  TableTextMpiFormatter::Status & status ) const;
135 };
136 
137 }
138 
139 #endif /* GEOS_COMMON_FORMAT_TABLE_TABLEMPICOMPONENTS_HPP */
stdVector< CellLayoutRow > CellLayoutRows
Represent a table section (title + header or values) layout: view on the data and its layout settings...
Class for setup the table layout.
Definition: TableLayout.hpp:34
Class to format data in a formatted text format (for log output typically, expecting fixed character ...
TableTextFormatter()
Construct a default Table Formatter without layout specification (to only insert data in it,...
string toString() const
class to format data in a formatted text format, allowing contributions from multiple MPI ranks.
void toStream(std::ostream &outputStream, DATASOURCE const &tableData) const
Convert a data source to a table string.
std::function< bool(stdVector< TableData::CellData >, stdVector< TableData::CellData >) > SortingFunc
Callable comparison function object used for std::sort for a TableData.
void setSortingFunc(SortingFunc &&func)
Set the row sorting function.
TableTextMpiFormatter(TableLayout const &tableLayout, TableMpiLayout mpiLayout=TableMpiLayout())
Construct a new TableTextMpiOutput from a tableLayout.
TableTextMpiFormatter(TableMpiLayout mpiLayout=TableMpiLayout())
Construct a default Table Formatter without layout specification (to only insert data in it,...
internal::StdVectorWrapper< T, Allocator, USE_STD_CONTAINER_BOUNDS_CHECKING > stdVector
Layout information specific to MPI distributed tables, completing those in TableLayout.
string m_rankTitle
Title for each rank's section visible in the separating line.
bool m_separatorBetweenRanks
Enable a separating line between ranks in the table output.