Skip to content

Commit

Permalink
Merge pull request #148 from mabruzzo/omp-take2
Browse files Browse the repository at this point in the history
Modified the ``chemistry_data`` struct so that the ``omp_nthreads`` is always a field
  • Loading branch information
brittonsmith committed May 9, 2023
2 parents 19aa129 + 6bf4704 commit bc458dc
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
2 changes: 0 additions & 2 deletions src/clib/grackle_chemistry_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,7 @@ typedef struct
int exit_after_iterations_exceeded;

/* number of OpenMP threads, if supported */
# ifdef _OPENMP
int omp_nthreads;
# endif

} chemistry_data;

Expand Down
4 changes: 1 addition & 3 deletions src/clib/grackle_chemistry_data_fields.def
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,4 @@ ENTRY(max_iterations, INT, 10000)
ENTRY(exit_after_iterations_exceeded, INT, FALSE)

/* number of OpenMP threads, if supported */
# ifdef _OPENMP
ENTRY(omp_nthreads, INT, omp_get_max_threads())
# endif
ENTRY(omp_nthreads, INT, 0)
13 changes: 12 additions & 1 deletion src/clib/initialize_chemistry_data.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,18 @@ int local_initialize_chemistry_data(chemistry_data *my_chemistry,
}

//initialize OpenMP
# ifdef _OPENMP
# ifndef _OPENMP
if (my_chemistry->omp_nthreads > 1) {
fprintf(stdout,
"omp_nthreads can't be set when Grackle isn't compiled with "
"OPENMP\n");
return FAIL;
}
# else _OPENMP
if (my_chemistry->omp_nthreads < 1) {
// this is the default behavior (unless the user intervenes)
my_chemistry->omp_nthreads = omp_get_max_threads();
}
//number of threads
omp_set_num_threads( my_chemistry->omp_nthreads );

Expand Down
4 changes: 0 additions & 4 deletions src/python/tests/test_chemistry_struct_synched.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,6 @@ def test_grackle_chemistry_field_synched():

diff = ref_set.symmetric_difference(parameters)
for parameter in diff:
if (parameter == 'omp_nthreads') and (param_type == 'int'):
# because omp_nthreads is only conditionally a field, handling
# it properly is more trouble than its worth...
continue
if parameter in ref_set:
raise RuntimeError(
f"{parameter}, a {param_type} field of the chemistry_data "
Expand Down

0 comments on commit bc458dc

Please sign in to comment.