Skip to content

Commit

Permalink
grid: Explicitly set num_threads in grid_library_init
Browse files Browse the repository at this point in the history
  • Loading branch information
oschuett committed Dec 28, 2020
1 parent 7e00210 commit 4da8f10
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/grid/common/grid_library.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ void grid_library_init() {
abort();
}

per_thread_globals =
malloc(sizeof(grid_library_globals *) * omp_get_max_threads());
const int n = omp_get_max_threads();
per_thread_globals = malloc(n * sizeof(grid_library_globals *));

// Using parallel regions to ensure memory is allocated near a thread's core.
#pragma omp parallel default(none) shared(per_thread_globals)
#pragma omp parallel default(none) shared(per_thread_globals) num_threads(n)
{
const int ithread = omp_get_thread_num();
per_thread_globals[ithread] = malloc(sizeof(grid_library_globals));
Expand Down

0 comments on commit 4da8f10

Please sign in to comment.