Merge pull request #1556 from lammps/bug-maxexchange

more robust version of atom exchange size
This commit is contained in:
Axel Kohlmeyer
2019-07-30 17:09:18 -04:00
committed by GitHub
21 changed files with 186 additions and 89 deletions

View File

@ -30,8 +30,7 @@ using namespace LAMMPS_NS;
#define BUFFACTOR 1.5
#define BUFFACTOR 1.5
#define BUFMIN 1000
#define BUFEXTRA 1000
#define BUFMIN 1024
#define EPSILON 1.0e-6
#define DELTA_PROCS 16
@ -78,17 +77,9 @@ CommTiled::~CommTiled()
void CommTiled::init_buffers()
{
// bufextra = max size of one exchanged atom
// = allowed overflow of sendbuf in exchange()
// atomvec, fix reset these 2 maxexchange values if needed
// only necessary if their size > BUFEXTRA
maxexchange = maxexchange_atom + maxexchange_fix;
bufextra = maxexchange + BUFEXTRA;
maxsend = BUFMIN;
memory->create(buf_send,maxsend+bufextra,"comm:buf_send");
maxrecv = BUFMIN;
buf_send = buf_recv = NULL;
maxsend = maxrecv = BUFMIN;
grow_send(maxsend,2);
memory->create(buf_recv,maxrecv,"comm:buf_recv");
maxoverlap = 0;
@ -106,6 +97,10 @@ void CommTiled::init()
{
Comm::init();
int bufextra_old = bufextra;
init_exchange();
if (bufextra > bufextra_old) grow_send(maxsend+bufextra,2);
// temporary restrictions
if (triclinic)
@ -646,15 +641,14 @@ void CommTiled::exchange()
atom->nghost = 0;
atom->avec->clear_bonus();
// insure send buf is large enough for single atom
// bufextra = max size of one atom = allowed overflow of sendbuf
// fixes can change per-atom size requirement on-the-fly
// insure send buf has extra space for a single atom
// only need to reset if a fix can dynamically add to size of single atom
int bufextra_old = bufextra;
maxexchange = maxexchange_atom + maxexchange_fix;
bufextra = maxexchange + BUFEXTRA;
if (bufextra > bufextra_old)
memory->grow(buf_send,maxsend+bufextra,"comm:buf_send");
if (maxexchange_fix_dynamic) {
int bufextra_old = bufextra;
init_exchange();
if (bufextra > bufextra_old) grow_send(maxsend+bufextra,2);
}
// domain properties used in exchange method and methods it calls
// subbox bounds for orthogonal or triclinic
@ -1812,18 +1806,23 @@ int CommTiled::coord2proc(double *x, int &igx, int &igy, int &igz)
/* ----------------------------------------------------------------------
realloc the size of the send buffer as needed with BUFFACTOR and bufextra
if flag = 1, realloc
if flag = 0, don't need to realloc with copy, just free/malloc
flag = 0, don't need to realloc with copy, just free/malloc w/ BUFFACTOR
flag = 1, realloc with BUFFACTOR
flag = 2, free/malloc w/out BUFFACTOR
------------------------------------------------------------------------- */
void CommTiled::grow_send(int n, int flag)
{
maxsend = static_cast<int> (BUFFACTOR * n);
if (flag)
memory->grow(buf_send,maxsend+bufextra,"comm:buf_send");
else {
if (flag == 0) {
maxsend = static_cast<int> (BUFFACTOR * n);
memory->destroy(buf_send);
memory->create(buf_send,maxsend+bufextra,"comm:buf_send");
} else if (flag == 1) {
maxsend = static_cast<int> (BUFFACTOR * n);
memory->grow(buf_send,maxsend+bufextra,"comm:buf_send");
} else {
memory->destroy(buf_send);
memory->grow(buf_send,maxsend+bufextra,"comm:buf_send");
}
}