Loading...
Searching...
No Matches
logutils.hpp
Go to the documentation of this file.
//==============================================================================
//==============================================================================
#ifndef LOGUTILS_HPP_
#define LOGUTILS_HPP_
#include <iostream>
#ifdef HAVE_OPENMP
#include <omp.h>
#endif
class LoggerHelper {
public:
LoggerHelper(int max_, int chunks, int minsize)
: per_chunk(max_/chunks), max(max_)
{
std::vector<int> sizes;
for (int i=0;i<chunks;++i)
sizes.push_back(max/chunks);
for(int i=chunks-max%chunks;i<chunks;++i)
sizes[i]++;
groups.resize(chunks);
groups[0] = 0;
for (int i=1;i<chunks;++i)
groups[i] = groups[i-1]+sizes[i-1];
groups.push_back(max);
if (max < minsize)
per_chunk=-1;
}
std::pair<int, int> group(int group)
{
return std::make_pair(groups[group],groups[group+1]);
}
void log(int it, const std::string& prefix)
{
if (per_chunk == -1)
return;
#ifdef HAVE_OPENMP
if (omp_get_num_threads() != 1)
return;
#endif
std::cout << prefix << it << '/' << max << std::endl;
}
protected:
std::vector<int> groups;
int per_chunk;
int max;
};
#endif
LoggerHelper::groups
std::vector< int > groups
Group start/end offsets.
Definition logutils.hpp:65
LoggerHelper::per_chunk
int per_chunk
Will log for each per_chunk processed.
Definition logutils.hpp:66
LoggerHelper::log
void log(int it, const std::string &prefix)
Log to the terminal.
Definition logutils.hpp:54
LoggerHelper::group
std::pair< int, int > group(int group)
Returns the start and end offsets of a chunk group.
Definition logutils.hpp:46
LoggerHelper::LoggerHelper
LoggerHelper(int max_, int chunks, int minsize)
Default constructor.
Definition logutils.hpp:27
LoggerHelper::max
int max
Total number of its.
Definition logutils.hpp:67