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

[ParU] Use more C++ #515

Merged

Conversation

gruenich
Copy link
Contributor

Replace C code by C++ code.

  • Use range-based for loops.
  • Don't use own definition of NULL and ASSERT
  • Use std::min and std::max

If you are unhappy with some of the commits, I can remove them and create separate pull requests.

@mmuetzel
Copy link
Contributor

These changes look good to me.

@DrTimothyAldenDavis
Copy link
Owner

Thanks for the update. A few comments:

I can't use a bare assert(...). I always must wrap it inside a macro, for several reasons. First, when used in MATLAB, the ASSERT macro must become a call to the MATLAB mxAssert function, not a C / C++ assert. Second, I put computationaly expensive things inside my ASSERT(...) calls, and these must be disabled at all times. I enable them only by editting the code itself:

// debugging and printing macros
// -----------------------------------------------------------------------------
// force debugging off
#ifndef NDEBUG
#define NDEBUG
#endif

That is, I intentionally make it very hard to turn on debugging, since if it gets turned on by mistake by an end user, then my codes can be 1000x slower, or worse. Then when I release the code, I force debug off by editing the code back.

And then sometimes I will revise the ASSERT macro so that it does something else, with a more informative error message, while developing the code.

@DrTimothyAldenDavis
Copy link
Owner

Yes, in general, std::min and std::max would probably be better. I would guess that the compiler might handle it better, in terms of performance.

The Control->paru_max_threads should be a plain int (or perhaps int32_t) anyway. That would simplify this particular case for std::min and std::max. This isn't a performance issue in this case, though.

For the for loops -- do they affect how OpenMP handles the loop? I haven't reviewed all the changes yet, though. I haven't used that style of for loop for a #pragma omp parallel for before.

Remove ParU's own C macros MIN and MAX.
NULL is defined by C++.
The definition of NULL as void* is not allowed by C++.
Less code, easier to read, less possibilites to make mistakes.
Found by clang-tidy.
Drop variable *el, use elementList[e] directly.
Replace using "continue" by inverted if condition and
moving the remaining code in the if block.
@gruenich gruenich force-pushed the feature/use-more-cpp branch from 438bcfb to a684309 Compare November 19, 2023 21:23
@DrTimothyAldenDavis
Copy link
Owner

looks great -- thanks!

@DrTimothyAldenDavis DrTimothyAldenDavis merged commit a676c46 into DrTimothyAldenDavis:dev2 Nov 25, 2023
21 checks passed
@gruenich gruenich deleted the feature/use-more-cpp branch December 19, 2023 17:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants