mirror of
https://github.com/cp2k/cp2k.git
synced 2026-07-28 22:25:32 -04:00
GRID: avoid integer overflow (#3927)
- On higher core-count systems, the adjusted expressions can overflow. - For example (16 ranks, 384 threads), the lower bound was negative. - Avoid subsequent OOB access.
This commit is contained in:
parent
aac52debd2
commit
b7bcddc135
1 changed files with 7 additions and 6 deletions
|
|
@ -379,10 +379,11 @@ static void collocate_one_grid_level(
|
|||
const int actual_group_size = imin(group_size, nthreads - dest_thread);
|
||||
// Parallelize summation by dividing grid points across group members.
|
||||
const int rank = modulo(ithread, group_size); // position within the group
|
||||
const int lb = (npts_local_total * rank) / actual_group_size;
|
||||
const int ub = (npts_local_total * (rank + 1)) / actual_group_size;
|
||||
const int64_t lb = ((int64_t)npts_local_total * rank) / actual_group_size;
|
||||
const int64_t ub =
|
||||
((int64_t)npts_local_total * (rank + 1)) / actual_group_size;
|
||||
if (src_thread < nthreads) {
|
||||
for (int i = lb; i < ub; i++) {
|
||||
for (int i = (int)lb; i < (int)ub; i++) {
|
||||
task_list->threadlocals[dest_thread][i] +=
|
||||
task_list->threadlocals[src_thread][i];
|
||||
}
|
||||
|
|
@ -391,9 +392,9 @@ static void collocate_one_grid_level(
|
|||
}
|
||||
|
||||
// Copy final result from first thread into shared grid.
|
||||
const int lb = (npts_local_total * ithread) / nthreads;
|
||||
const int ub = (npts_local_total * (ithread + 1)) / nthreads;
|
||||
for (int i = lb; i < ub; i++) {
|
||||
const int64_t lb = ((int64_t)npts_local_total * ithread) / nthreads;
|
||||
const int64_t ub = ((int64_t)npts_local_total * (ithread + 1)) / nthreads;
|
||||
for (int i = (int)lb; i < (int)ub; i++) {
|
||||
grid->host_buffer[i] = task_list->threadlocals[0][i];
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue