Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/coreComponents/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ Also provides commonly used components for such as logging, formatting, memory a
#
set( common_headers
${CMAKE_BINARY_DIR}/include/common/GeosxConfig.hpp
format/table/TableLayout.hpp
format/table/TableFormatter.hpp
format/table/TableData.hpp
format/table/TableFormatter.hpp
format/table/TableLayout.hpp
format/table/TableMpiComponents.hpp
format/EnumStrings.hpp
format/LogPart.hpp
format/Format.hpp
Expand Down Expand Up @@ -71,9 +72,10 @@ endif( )
# Specify all sources
#
set( common_sources
format/table/TableLayout.cpp
format/table/TableFormatter.cpp
format/table/TableData.cpp
format/table/TableFormatter.cpp
format/table/TableLayout.cpp
format/table/TableMpiComponents.cpp
format/LogPart.cpp
format/StringUtilities.cpp
logger/GeosExceptions.cpp
Expand Down
142 changes: 142 additions & 0 deletions src/coreComponents/common/MpiWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,148 @@ template<> MPI_Datatype getMpiPairType< double, double >()

} /* namespace internal */

template<>
void MpiWrapper::gatherString< std::function< void(string_view) > >
( string const & rankStr, std::function< void(string_view) > && func )
{
integer const ranksCount = MpiWrapper::commSize();
integer const currRank = MpiWrapper::commRank();
// all other ranks than rank 0 render their output in a string and comunicate its size
std::vector< integer > ranksStrsSizes = std::vector( ranksCount, 0 );

integer const rankStrSize = rankStr.size();
MpiWrapper::gather( &rankStrSize, 1, ranksStrsSizes.data(), 1, 0 );

// we compute the memory layout of the ranks strings
std::vector< integer > ranksStrsOffsets = std::vector( ranksCount, 0 );
integer ranksStrsTotalSize = 0;
for( integer rankId = 0; rankId < ranksCount; ++rankId )
{
ranksStrsOffsets[rankId] = ranksStrsTotalSize;
ranksStrsTotalSize += ranksStrsSizes[rankId];
}

// finally, we can send all text data to rank 0, then we output it in the output stream.
string ranksStrs = string( ranksStrsTotalSize, '\0' );
MpiWrapper::gatherv( rankStr.data(), rankStrSize,
ranksStrs.data(), ranksStrsSizes.data(), ranksStrsOffsets.data(),
0, MPI_COMM_GEOS );
if( currRank == 0 )
{
for( integer rankId = 0; rankId < ranksCount; ++rankId )
{
if( ranksStrsSizes[rankId] > 0 )
{
func( string_view( ranksStrs.data() + ranksStrsOffsets[rankId], ranksStrsSizes[rankId] ) );
}
}
}
}

// template<>
// void MpiWrapper::gatherStringSet< stdVector >( stdVector< string > const & strSet,
// stdVector< string > & result,
// MPI_Comm MPI_PARAM( comm ))
// {
// int rank = MpiWrapper::commRank();
// int size = MpiWrapper::commSize();

// string localAllStrings;
// stdVector< int > localStrSizes;
// localAllStrings.reserve( strSet.size() * 32 );

// for( auto const & str : strSet )
// {
// localAllStrings += str;
// localStrSizes.push_back( static_cast< int >(str.size()));
// }

// //1 - We gather the metadata across all ranks
// struct MetaData
// {
// int count;
// int size;
// };
// MetaData localMeta = { static_cast< int >(strSet.size()), static_cast< int >(localAllStrings.size()) };

// stdVector< MetaData > allMeta;
// if( rank == 0 )
// {
// allMeta.resize( size );
// }

// int localMetaArr[2] = { localMeta.count, localMeta.size };
// stdVector< int > allMetaArr;

// if( rank == 0 )
// allMetaArr.resize( size * 2 );

// MpiWrapper::gather( localMetaArr, 2, allMetaArr.data(), 2, 0, comm );

// //2 - Prepare displacement arrays for rank 0
// stdVector< int > allStrSizes;
// string allStrings;
// stdVector< int > counts_counts( size );
// stdVector< int > displs_counts( size );
// stdVector< int > counts_chars( size );
// stdVector< int > displs_chars( size );

// int totalStrCount = 0;

// if( rank == 0 )
// {
// int currentCountOffset = 0;
// int currentCharOffset = 0;

// for( int currRank = 0; currRank < size; ++currRank )
// {
// int c_count = allMetaArr[2*currRank];
// int c_size = allMetaArr[2*currRank + 1];

// counts_counts[currRank] = c_count;
// displs_counts[currRank] = currentCountOffset;

// counts_chars[currRank] = c_size;
// displs_chars[currRank] = currentCharOffset;

// currentCountOffset += c_count;
// currentCharOffset += c_size;
// }

// totalStrCount = currentCountOffset;

// allStrSizes.resize( totalStrCount );
// allStrings.resize( currentCharOffset );
// }

// // 3. Gatherv des tailles de chaînes
// MpiWrapper::gatherv( localStrSizes.data(), localMeta.count,
// allStrSizes.data(), counts_counts.data(), displs_counts.data(),
// 0, comm );

// // 4. Gatherv du contenu (chars)
// MpiWrapper::gatherv( localAllStrings.c_str(), localMeta.size,
// allStrings.data(), counts_chars.data(), displs_chars.data(),
// 0, comm );

// // 5. Reconstruction
// if( rank == 0 )
// {
// const char * dataPtr = allStrings.c_str();
// int currentOffset = 0;
// for( int i = 0; i < totalStrCount; ++i )
// {
// int len = allStrSizes[i];

// std::string const temp( dataPtr + currentOffset, len );

// result.emplace( result.end(), temp );
// currentOffset += len;
// }
// }

// }

} /* namespace geos */

#if defined(__clang__)
Expand Down
5 changes: 5 additions & 0 deletions src/coreComponents/common/MpiWrapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include "common/DataTypes.hpp"
#include "common/Span.hpp"
#include "common/StdContainerWrappers.hpp"
#include "common/TypesHelpers.hpp"

#include <numeric>
Expand Down Expand Up @@ -331,6 +332,10 @@ struct MpiWrapper
*/
static int nodeCommSize();

template< typename FUNC >
static void gatherString( string const & str,
FUNC && func );

/**
* @brief Strongly typed wrapper around MPI_Allgather.
* @tparam T_SEND The pointer type for \p sendbuf
Expand Down
52 changes: 41 additions & 11 deletions src/coreComponents/common/format/table/TableData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/

#include "TableData.hpp"
#include "common/DataTypes.hpp"
#include "common/logger/Logger.hpp"

namespace geos
Expand Down Expand Up @@ -89,16 +90,6 @@ void TableData::clear()
getErrorsList().clear();
}

stdVector< stdVector< TableData::CellData > > const & TableData::getTableDataRows() const
{
return m_rows;
}

stdVector< stdVector< TableData::CellData > > & TableData::getTableDataRows()
{
return m_rows;
}

void TableData2D::collectTableValues( arrayView1d< real64 const > dim0AxisCoordinates,
arrayView1d< real64 const > dim1AxisCoordinates,
arrayView1d< real64 const > values,
Expand Down Expand Up @@ -176,7 +167,7 @@ TableData2D::TableDataHolder TableData2D::buildTableData( string_view targetUnit
std::set< real64 >::const_iterator columnIt = m_columnValues.begin();
for( auto const & [columnValue, cellValue] : rowMap )
{
// if a column value(s) is/are missing, insert empty entry(ies)
// if s1 column value(s) is/are missing, insert empty entry(ies)
while( columnValue > *( columnIt++ ) && columnIt != m_columnValues.end() )
{
currentRowValues.push_back( {CellType::Value, ""} );
Expand All @@ -190,4 +181,43 @@ TableData2D::TableDataHolder TableData2D::buildTableData( string_view targetUnit

return tableData1D;
}

bool tabledatasorting::positiveNumberStringComp( string_view s1, string_view s2 )
{
auto split = [](string_view s, string & intPart, string & decPart)
{
size_t dotPos = s.find('.');
if(dotPos == string::npos)
{
intPart = s;
decPart = "";
}
else
{
intPart = s.substr(0, dotPos);
decPart = s.substr(dotPos + 1);
}
};

string s1Int, s1Dec, s2Int, s2Dec;
split(s1, s1Int, s1Dec);
split(s2, s2Int, s2Dec);

if(s1Int.length() != s2Int.length())
return s1Int.length() < s2Int.length();

if(s1Int != s2Int)
return s1Int < s2Int;

size_t minLen = std::min(s1Dec.length(), s2Dec.length());
for(size_t i = 0; i < minLen; ++i)
{
if(s1Dec[i] != s2Dec[i])
return s1Dec[i] < s2Dec[i];
}


return false;
}

}
33 changes: 19 additions & 14 deletions src/coreComponents/common/format/table/TableData.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,16 +111,6 @@ class TableData
void clearErrors()
{ m_errors->clear(); }

/**
* @return The const rows of the table
*/
stdVector< stdVector< CellData > > const & getTableDataRows() const;

/**
* @return The rows of the table
*/
stdVector< stdVector< CellData > > & getTableDataRows();

/**
* @brief Get all error messages
* @return The vector of error messages
Expand All @@ -133,16 +123,19 @@ class TableData
DataRows const & getCellsData() const
{ return m_rows; }

/**
* @return The const table data rows
*/
DataRows & getCellsData()
{ return m_rows; }

/**
* @brief Comparison operator for data rows
* @param comparingTable The tableData values to compare
* @return The comparison result
*/
inline bool operator==( TableData const & comparingTable ) const
{

return getCellsData() == comparingTable.getCellsData();
}
{ return getCellsData() == comparingTable.getCellsData(); }

/**
* @brief Get all error messages
Expand Down Expand Up @@ -309,5 +302,17 @@ void TableData2D::addCell( real64 const rowValue, real64 const columnValue, T co
m_data.get_inserted( rowValue ).get_inserted( columnValue ) = GEOS_FMT( "{}", value );
}

// Custom Comp function;
namespace tabledatasorting
{
/**
* @brief Compare two number string by in ascending numerical order.
* @param a The string to compare
* @param b The string to compare
* @return True if a is greater than b
*/
bool positiveNumberStringComp( string_view a, string_view b );
}

}
#endif /* GEOS_COMMON_FORMAT_TABLE_TABLEDATA_HPP */
Loading
Loading