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

Add semantic for reading thread count from $OMP_NUM_THREADS #73

Merged
merged 3 commits into from
Mar 21, 2024

Conversation

antoine-morvan
Copy link
Contributor

@antoine-morvan antoine-morvan commented Mar 19, 2024

Hello,

I am using some scripts to automatically launch the CloudSC dwarf with various numbers of OpenMP thread. The framework however relies on $OMP_NUM_THREAD to set this value, and cannot act on the executable arguments.

This PR does 2 things:

  1. Prevent the application from crashing when the first argument is 0 or negative, by adding the semantic below. Previously it was failing on trying to start regions with 0 threads, or allocating arrays of size -1 (leading to some funny stuff with some compilers and -Ofast ...);
  2. Add semantic to the value of the first argument when zero or negative: it now reads the $OMP_NUM_THREADS variable from the environment if present or defaults to CPU count (omp_get_max_threads());

The updated readme should reflect these changes.

This should not break existing behavior, as zero or negative arguments were leading to aplication crash.

Best regards.

Zero or negative values given as first argument of the various prototypes
led to errors. This commit adds semantic to 0 or negative values by enabling
the program to read the OMP_NUM_THREAD value from the environment, or using
the number of procs availables if the variable is not defined.
Add first argument values and the associated effect on the
multithreaded behavior
@FussyDuck
Copy link

FussyDuck commented Mar 19, 2024

CLA assistant check
All committers have signed the CLA.

@reuterbal reuterbal changed the base branch from main to develop March 21, 2024 11:06
Copy link
Collaborator

@reuterbal reuterbal left a comment

Choose a reason for hiding this comment

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

Thanks, this looks like a good idea!

NB: I have retargeted the PR to develop

I haven't tested this myself, yet, but leaving a request for guarding the use of the OpenMP API, to make sure this can build without OpenMP available.

src/cloudsc_c/dwarf_cloudsc.c Outdated Show resolved Hide resolved
src/cloudsc_cuda/dwarf_cloudsc.cpp Outdated Show resolved Hide resolved
src/cloudsc_fortran/dwarf_cloudsc.F90 Outdated Show resolved Hide resolved
src/cloudsc_gpu/dwarf_cloudsc_gpu.F90 Show resolved Hide resolved
src/cloudsc_loki/dwarf_cloudsc.F90 Show resolved Hide resolved
Copy link
Collaborator

@mlange05 mlange05 left a comment

Choose a reason for hiding this comment

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

Hi @antoine-morvan many thanks for the contribution.

I also agree that this is a good idea, but that we might also need the #ifdef guards. However, I've run this and recreated the previous failure, and it all works nicely and as expected, so should be good to go once this is in place.

@antoine-morvan
Copy link
Contributor Author

Hi @antoine-morvan many thanks for the contribution.

I also agree that this is a good idea, but that we might also need the #ifdef guards. However, I've run this and recreated the previous failure, and it all works nicely and as expected, so should be good to go once this is in place.

Regarding the #ifdef in the C and CUDA implementations, the cloudsc_drivers.h files already includes #include <omp.h> without guard. The guard can be added nonetheless.

For the in Fortran files that would match what's in the timer_mod. I'll add this.

@antoine-morvan
Copy link
Contributor Author

Should be better with OpenMP-less support :)

Copy link
Collaborator

@mlange05 mlange05 left a comment

Choose a reason for hiding this comment

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

Ok, fantastic. Many thanks @antoine-morvan GTG from me.

Copy link
Collaborator

@reuterbal reuterbal left a comment

Choose a reason for hiding this comment

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

Many thanks for adding the guards! We should sort this for CUDA/C as well, but that's for a different PR.

@reuterbal reuterbal merged commit 4e8ada0 into ecmwf-ifs:develop Mar 21, 2024
18 checks passed
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.

4 participants