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

less couts during advances in release mode #885

Merged
merged 2 commits into from
Sep 5, 2024
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
2 changes: 1 addition & 1 deletion src/amr/level_initializer/hybrid_level_initializer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ namespace solver

if (isRegridding)
{
std::cout << "regriding level " << levelNumber << "\n";
PHARE_LOG_LINE_STR("regriding level " + std::to_string(levelNumber));
PHARE_LOG_START(3, "hybridLevelInitializer::initialize : regriding block");
messenger.regrid(hierarchy, levelNumber, oldLevel, model, initDataTime);
PHARE_LOG_STOP(3, "hybridLevelInitializer::initialize : regriding block");
Expand Down
4 changes: 2 additions & 2 deletions src/amr/messengers/hybrid_hybrid_messenger_strategy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ namespace amr
PHARE_LOG_SCOPE(3, "HybridHybridMessengerStrategy::synchronize");

auto levelNumber = level.getLevelNumber();
std::cout << "synchronizing level " << levelNumber << "\n";
PHARE_LOG_LINE_STR("synchronizing level " + std::to_string(levelNumber));

// call coarsning schedules...
magnetoSynchronizers_.sync(levelNumber);
Expand All @@ -607,7 +607,7 @@ namespace amr
auto levelNumber = level.getLevelNumber();
auto& hybridModel = static_cast<HybridModel&>(model);

std::cout << "postSynchronize level " << levelNumber << "\n";
PHARE_LOG_LINE_STR("postSynchronize level " + std::to_string(levelNumber))

magSharedNodesRefiners_.fill(hybridModel.state.electromag.B, levelNumber, time);
elecSharedNodesRefiners_.fill(hybridModel.state.electromag.E, levelNumber, time);
Expand Down
13 changes: 7 additions & 6 deletions src/amr/multiphysics_integrator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,9 @@ namespace solver
bool const isRegridding = oldLevel != nullptr;
auto level = hierarchy->getPatchLevel(levelNumber);

std::cout << "init level " << levelNumber << " with regriding = " << isRegridding
<< "\n";

PHARE_LOG_LINE_SS("init level " << levelNumber << " with regriding = " << isRegridding);

PHARE_LOG_START(3, "initializeLevelData::allocate block");
if (allocateData)
{
Expand Down Expand Up @@ -414,7 +415,7 @@ namespace solver
int const tag_index, bool const /*initialTime*/,
bool const /*usesRichardsonExtrapolationToo*/) override
{
std::cout << "apply gradient detector on level " << levelNumber << "\n";
PHARE_LOG_LINE_STR("apply gradient detector on level " + std::to_string(levelNumber));

auto level = hierarchy->getPatchLevel(levelNumber);
for (auto& patch : *level)
Expand Down Expand Up @@ -508,9 +509,9 @@ namespace solver

auto iLevel = level->getLevelNumber();

PHARE_LOG_LINE_STR("advanceLevel " << iLevel << " with dt = " << newTime - currentTime
<< " from t = " << currentTime
<< " to t = " << newTime);
PHARE_LOG_LINE_SS("advanceLevel " << iLevel << " with dt = " << newTime - currentTime
<< " from t = " << currentTime
<< " to t = " << newTime);

auto& solver = getSolver_(iLevel);
auto& model = getModel_(iLevel);
Expand Down
2 changes: 2 additions & 0 deletions src/core/logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ constexpr static std::uint8_t LOG_LEVEL = PHARE_LOG_LEVEL;
#if !defined(NDEBUG) || defined(PHARE_FORCE_DEBUG_DO)
#define PHARE_LOG_LINE_STR(str) \
std::cout << __FILE__ << ":" << __LINE__ << " - " << str << std::endl;
#define PHARE_LOG_LINE_SS(s) PHARE_LOG_LINE_STR((std::stringstream{} << s).str());
Copy link

@coderabbitai coderabbitai bot Sep 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactor the macro parameter for consistency.

The macro PHARE_LOG_LINE_SS uses s as a parameter, which is inconsistent with the change noted in the alterations summary that suggests it should be str. This inconsistency can lead to confusion and potential errors in macro usage.

Consider renaming the parameter to match the intended usage and documentation:

-#define PHARE_LOG_LINE_SS(s) PHARE_LOG_LINE_STR((std::stringstream{} << s).str());
+#define PHARE_LOG_LINE_SS(str) PHARE_LOG_LINE_STR((std::stringstream{} << str).str());
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
#define PHARE_LOG_LINE_SS(s) PHARE_LOG_LINE_STR((std::stringstream{} << s).str());
#define PHARE_LOG_LINE_SS(str) PHARE_LOG_LINE_STR((std::stringstream{} << str).str());

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because it's a macro, it would not be advisable to use the input parameter str as it might conflict with the stringstream::str() call

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PhilipDeegan, you're absolutely right. Using str as a parameter name in the macro could indeed lead to conflicts with the stringstream::str() method. Keeping the parameter name as s is the best approach to avoid any potential issues. Thanks for the clarification!

#else
#define PHARE_LOG_LINE_STR(str)
#define PHARE_LOG_LINE_SS(str)
Copy link

@coderabbitai coderabbitai bot Sep 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure macro definitions are consistent across build configurations.

The macro PHARE_LOG_LINE_SS is defined differently based on the build configuration. It's important to ensure that the macro behaves consistently or is disabled appropriately across different configurations to prevent runtime errors and maintain code clarity.

Verify that the macro is either consistently defined or appropriately disabled across all configurations. If disabling is the choice, ensure that it does not lead to any unresolved references during compilation in release mode.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is so we do not print lines during release mode with -DNDEBUG

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PhilipDeegan, thank you for the clarification. The conditional definition of the macro makes sense to avoid unnecessary logging in release mode with -DNDEBUG. This approach is indeed appropriate for optimizing performance and reducing output clutter in production environments.

#endif
#define PHARE_LOG_LINE PHARE_LOG_LINE_STR("")

Expand Down
Loading