Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use adiosLog in CompressZFP #2955

Merged
merged 1 commit into from
Nov 23, 2021
Merged
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
15 changes: 12 additions & 3 deletions source/adios2/helper/adiosLog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ std::string errorColor = "\033[1;31m";
std::string exceptionColor = "\033[1;34m";
std::string defaultColor = "\033[0m";

void Log(const std::string &component, const std::string &source,
const std::string &activity, const std::string &message,
const LogMode mode)
{
Log(component, source, activity, message, -1, -1, 0, 0, mode);
}

void Log(const std::string &component, const std::string &source,
const std::string &activity, const std::string &message,
const int priority, const int verbosity, const LogMode mode)
Expand Down Expand Up @@ -57,11 +64,13 @@ void Log(const std::string &component, const std::string &source,
auto timeNow =
std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
std::string timeStr(std::ctime(&timeNow));

if (timeStr[timeStr.size() - 1] == '\n')
{
timeStr[timeStr.size() - 1] = '\0';
timeStr.resize(timeStr.size() - 1);
}
m << timeColor << " [" << timeStr << "]" << defaultColor;

m << timeColor << "[" << timeStr << "]";

if (mode == INFO)
{
Expand All @@ -86,7 +95,7 @@ void Log(const std::string &component, const std::string &source,
}

m << " <" << component << "> <" << source << "> <" << activity
<< "> : " << message << std::endl;
<< "> : " << message << defaultColor << std::endl;

if (mode == INFO || mode == WARNING)
{
Expand Down
16 changes: 14 additions & 2 deletions source/adios2/helper/adiosLog.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@ enum LogMode : char
INFO = 'i'
};

/**
* Print outputs, warnings, errors, and exceptions
* @param component: Engine, Transport, Operator, etc.
* @param source: class name of component
* @param activity: function name where this is called
* @param message: text message
* @param mode: INFO, WARNING, ERROR, or EXCEPTION
*/
void Log(const std::string &component, const std::string &source,
const std::string &activity, const std::string &message,
const LogMode mode);

/**
* Print outputs, warnings, errors, and exceptions
* @param component: Engine, Transport, Operator, etc.
Expand All @@ -31,7 +43,7 @@ enum LogMode : char
* @param message: text message
* @param priority: only print if(priority<=verbosity)
* @param verbosity: engine parameter for engine wide verbosity level
* @param mode: OUTPUT, WARNING, ERROR, or EXCEPTION
* @param mode: INFO, WARNING, ERROR, or EXCEPTION
*/
void Log(const std::string &component, const std::string &source,
const std::string &activity, const std::string &message,
Expand All @@ -47,7 +59,7 @@ void Log(const std::string &component, const std::string &source,
* @param commRank: current MPI rank
* @param priority: only print if(priority<=verbosity)
* @param verbosity: engine parameter for engine wide verbosity level
* @param mode: OUTPUT, WARNING, ERROR, or EXCEPTION
* @param mode: INFO, WARNING, ERROR, or EXCEPTION
*/
void Log(const std::string &component, const std::string &source,
const std::string &activity, const std::string &message,
Expand Down
94 changes: 41 additions & 53 deletions source/adios2/operator/compress/CompressZFP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,37 +90,30 @@ size_t CompressZFP::Operate(const char *dataIn, const Dims &blockStart,

Dims convertedDims = ConvertDims(blockCount, type, 3);

try
{
zfp_field *field = GetZFPField(dataIn, convertedDims, type);
zfp_stream *stream = GetZFPStream(convertedDims, type, parameters);

size_t maxSize = zfp_stream_maximum_size(stream, field);
// associate bitstream
bitstream *bitstream =
stream_open(bufferOut + bufferOutOffset, maxSize);
zfp_stream_set_bit_stream(stream, bitstream);
zfp_stream_rewind(stream);

size_t sizeOut = zfp_compress(stream, field);
zfp_field *field = GetZFPField(dataIn, convertedDims, type);
zfp_stream *stream = GetZFPStream(convertedDims, type, parameters);

if (sizeOut == 0)
{
throw std::invalid_argument("ERROR: zfp failed, compressed buffer "
"size is 0, in call to Compress");
}
size_t maxSize = zfp_stream_maximum_size(stream, field);
// associate bitstream
bitstream *bitstream = stream_open(bufferOut + bufferOutOffset, maxSize);
zfp_stream_set_bit_stream(stream, bitstream);
zfp_stream_rewind(stream);

bufferOutOffset += sizeOut;
size_t sizeOut = zfp_compress(stream, field);

zfp_field_free(field);
zfp_stream_close(stream);
stream_close(bitstream);
}
catch (std::invalid_argument &e)
if (sizeOut == 0)
{
throw std::invalid_argument(e.what() + m_VersionInfo + "\n");
helper::Log("Operator", "CompressZFP", "Operate(Compress)",
"zfp failed, compressed buffer size is 0",
helper::LogMode::EXCEPTION);
}

bufferOutOffset += sizeOut;

zfp_field_free(field);
zfp_stream_close(stream);
stream_close(bitstream);

return bufferOutOffset;
}

Expand All @@ -144,7 +137,10 @@ size_t CompressZFP::InverseOperate(const char *bufferIn, const size_t sizeIn,
}
else
{
throw std::runtime_error("unknown zfp buffer version");
helper::Log("Operator", "CompressZFP", "Operate(Compress)",
"invalid zfp buffer version" +
std::to_string(bufferVersion),
helper::LogMode::EXCEPTION);
}

return 0;
Expand Down Expand Up @@ -194,15 +190,8 @@ size_t CompressZFP::DecompressV1(const char *bufferIn, const size_t sizeIn,
zfp_field *field = nullptr;
zfp_stream *stream = nullptr;

try
{
field = GetZFPField(dataOut, convertedDims, type);
stream = GetZFPStream(convertedDims, type, parameters);
}
catch (std::invalid_argument &e)
{
throw std::invalid_argument(e.what() + m_VersionInfo + "\n");
}
field = GetZFPField(dataOut, convertedDims, type);
stream = GetZFPStream(convertedDims, type, parameters);

// associate bitstream
bitstream *bitstream = stream_open(
Expand All @@ -214,9 +203,9 @@ size_t CompressZFP::DecompressV1(const char *bufferIn, const size_t sizeIn,

if (!status)
{
throw std::runtime_error(
"ERROR: zfp failed with status " + std::to_string(status) +
", in call to CompressZfp Decompress." + m_VersionInfo + "\n");
helper::Log("Operator", "CompressZFP", "DecompressV1",
"zfp failed with status " + std::to_string(status),
helper::LogMode::EXCEPTION);
}

zfp_field_free(field);
Expand Down Expand Up @@ -256,12 +245,9 @@ zfp_type GetZfpType(DataType type)
}
else
{
throw std::invalid_argument(
"ERROR: type " + ToString(type) +
" not supported by zfp, only "
"signed int32_t, signed int64_t, float, and "
"double types are acceptable, from class "
"CompressZfp Transform\n");
helper::Log("Operator", "CompressZFP", "GetZfpType",
"invalid data type " + ToString(type),
helper::LogMode::EXCEPTION);
}

return zfpType;
Expand Down Expand Up @@ -290,18 +276,19 @@ zfp_field *GetZFPField(const char *data, const Dims &dimensions, DataType type)
}
else
{
throw std::invalid_argument(
"ERROR: zfp_field* failed for data of type " + ToString(type) +
", only 1D, 2D and 3D dimensions are supported, from "
"class CompressZfp.");
helper::Log("Operator", "CompressZFP", "GetZfpField",
"zfp does not support " +
std::to_string(dimensions.size()) + "D data",
helper::LogMode::EXCEPTION);
}

if (field == nullptr)
{
throw std::invalid_argument(
"ERROR: zfp_field_" + std::to_string(dimensions.size()) +
"d failed for data of type " + ToString(type) +
", data might be corrupted, from class CompressZfp.");
helper::Log("Operator", "CompressZFP", "GetZfpField",
"zfp failed to make field for" +
std::to_string(dimensions.size()) + "D data in " +
ToString(type),
helper::LogMode::EXCEPTION);
}

return field;
Expand Down Expand Up @@ -367,7 +354,8 @@ zfp_stream *GetZFPStream(const Dims &dimensions, DataType type,
{
oss << "(" << p.first << ", " << p.second << ").";
}
throw std::invalid_argument(oss.str());
helper::Log("Operator", "CompressZFP", "GetZfpField", oss.str(),
helper::LogMode::EXCEPTION);
}

if (hasAccuracy)
Expand Down