Skip to content
Snippets Groups Projects
Commit 7cf0b9e7 authored by Norihiro Watanabe's avatar Norihiro Watanabe
Browse files

extend LogogCustomCout to support level dependent output

parent 4e609ea7
No related branches found
No related tags found
No related merge requests found
......@@ -24,23 +24,43 @@ class LogogCustomCout : public logog::Target
{
public:
#ifdef USE_MPI
LogogCustomCout(MPI_Comm mpi_comm)
{
MPI_Comm_rank(mpi_comm, &_mpi_rank);
}
/**
* Constructor when MPI is involved
*
* @param all_rank_output_level Minimum level to output messages from all MPI processes
* @param mpi_comm MPI communicator
*/
LogogCustomCout(LOGOG_LEVEL_TYPE all_rank_output_level = LOGOG_LEVEL_INFO, MPI_Comm mpi_comm = MPI_COMM_WORLD)
: _all_rank_output_level(all_rank_output_level), _is_rank0 (getRank(mpi_comm)==0)
{}
#endif
virtual int Output( const LOGOG_STRING &data )
virtual int Receive( const logog::Topic &topic )
{
#ifdef USE_MPI
if (_mpi_rank == 0)
if (topic.Level() > _all_rank_output_level && !_is_rank0)
return 0;
#endif
return logog::Target::Receive(topic);
}
virtual int Output( const LOGOG_STRING &data )
{
LOGOG_COUT << (const LOGOG_CHAR *)data;
return 0;
}
private:
#ifdef USE_MPI
int _mpi_rank;
int getRank(MPI_Comm mpi_comm) const
{
int rank = 0;
MPI_Comm_rank(mpi_comm, &rank);
return rank;
}
const LOGOG_LEVEL_TYPE _all_rank_output_level;
const bool _is_rank0;
#endif
};
......
......@@ -45,10 +45,8 @@ int main(int argc, char* argv[])
{
#ifdef USE_MPI
MPI_Init(&argc, &argv);
BaseLib::LogogCustomCout out(MPI_COMM_WORLD);
#else
BaseLib::LogogCustomCout out;
#endif
BaseLib::LogogCustomCout out;
BaseLib::TemplateLogogFormatterSuppressedGCC<TOPIC_LEVEL_FLAG | TOPIC_FILE_NAME_FLAG | TOPIC_LINE_NUMBER_FLAG> custom_format;
out.SetFormatter(custom_format);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment