avoid 32-bit integer overflow when allocating memory for neighbor list copy
This commit is contained in:
@ -391,9 +391,10 @@ void IntelBuffers<flt_t, acc_t>::_grow_nbor_list(NeighList * /*list*/,
|
||||
free_nbor_list();
|
||||
_list_alloc_atoms = 1.10 * nlocal;
|
||||
int nt = MAX(nthreads, _off_threads);
|
||||
int list_alloc_size = (_list_alloc_atoms + nt * 2 + pack_width - 1) *
|
||||
get_max_nbors();
|
||||
lmp->memory->create(_list_alloc, list_alloc_size, "_list_alloc");
|
||||
|
||||
bigint list_alloc_size =
|
||||
(bigint)(_list_alloc_atoms + nt * 2 + pack_width - 1) * (bigint)get_max_nbors();
|
||||
_list_alloc = (int *) lmp->memory->smalloc(list_alloc_size * sizeof(int), "_list_alloc");
|
||||
#ifdef _LMP_INTEL_OFFLOAD
|
||||
if (offload_end > 0) {
|
||||
int * list_alloc =_list_alloc;
|
||||
@ -706,7 +707,7 @@ double IntelBuffers<flt_t, acc_t>::memory_usage(const int nthreads)
|
||||
if (_off_f) tmem += fstride*_off_threads * sizeof(vec3_acc_t);
|
||||
#endif
|
||||
|
||||
tmem += (_list_alloc_atoms + _off_threads) * get_max_nbors() * sizeof(int);
|
||||
tmem += (bigint)(_list_alloc_atoms + _off_threads) * (bigint)get_max_nbors() * sizeof(int);
|
||||
tmem += _ntypes * _ntypes * sizeof(int);
|
||||
|
||||
tmem += _buf_local_size + (_n_list_ptrs - 1) * _buf_local_size * 2;
|
||||
|
||||
@ -63,8 +63,7 @@ void *Memory::smalloc(bigint nbytes, const char *name)
|
||||
void *ptr = malloc(nbytes);
|
||||
#endif
|
||||
if (ptr == nullptr)
|
||||
error->one(FLERR,"Failed to allocate {} bytes for array {}",
|
||||
nbytes,name);
|
||||
error->one(FLERR,"Failed to allocate {} bytes for array {}", nbytes,name);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user