correct illegal and uninitialized data access issue

This commit is contained in:
Axel Kohlmeyer
2020-08-18 14:19:57 -04:00
parent 2fea8f888a
commit a537ffabf9
2 changed files with 14 additions and 10 deletions

View File

@ -306,10 +306,12 @@ double FixTempCSLD::compute_scalar()
void FixTempCSLD::write_restart(FILE *fp) void FixTempCSLD::write_restart(FILE *fp)
{ {
int nsize = (98+2+3)*comm->nprocs+2; // pRNG state per proc + nprocs + energy int nsize = (98+2+3)*comm->nprocs+2; // pRNG state per proc + nprocs + energy
double *list; double *list = nullptr;
if (comm->me == 0) list = new double[nsize]; if (comm->me == 0) {
list[0] = energy; list = new double[nsize];
list[1] = comm->nprocs; list[0] = energy;
list[1] = comm->nprocs;
}
double state[103]; double state[103];
random->get_state(state); random->get_state(state);
MPI_Gather(state,103,MPI_DOUBLE,list+2,103*comm->nprocs,MPI_DOUBLE,0,world); MPI_Gather(state,103,MPI_DOUBLE,list+2,103*comm->nprocs,MPI_DOUBLE,0,world);
@ -318,8 +320,8 @@ void FixTempCSLD::write_restart(FILE *fp)
int size = nsize * sizeof(double); int size = nsize * sizeof(double);
fwrite(&size,sizeof(int),1,fp); fwrite(&size,sizeof(int),1,fp);
fwrite(list,sizeof(double),nsize,fp); fwrite(list,sizeof(double),nsize,fp);
delete[] list;
} }
if (comm->me == 0) delete[] list;
} }
/* ---------------------------------------------------------------------- /* ----------------------------------------------------------------------

View File

@ -339,10 +339,12 @@ double FixTempCSVR::compute_scalar()
void FixTempCSVR::write_restart(FILE *fp) void FixTempCSVR::write_restart(FILE *fp)
{ {
int nsize = (98+2+3)*comm->nprocs+2; // pRNG state per proc + nprocs + energy int nsize = (98+2+3)*comm->nprocs+2; // pRNG state per proc + nprocs + energy
double *list; double *list = nullptr;
if (comm->me == 0) list = new double[nsize]; if (comm->me == 0) {
list[0] = energy; list = new double[nsize];
list[1] = comm->nprocs; list[0] = energy;
list[1] = comm->nprocs;
}
double state[103]; double state[103];
random->get_state(state); random->get_state(state);
MPI_Gather(state,103,MPI_DOUBLE,list+2,103*comm->nprocs,MPI_DOUBLE,0,world); MPI_Gather(state,103,MPI_DOUBLE,list+2,103*comm->nprocs,MPI_DOUBLE,0,world);
@ -351,8 +353,8 @@ void FixTempCSVR::write_restart(FILE *fp)
int size = nsize * sizeof(double); int size = nsize * sizeof(double);
fwrite(&size,sizeof(int),1,fp); fwrite(&size,sizeof(int),1,fp);
fwrite(list,sizeof(double),nsize,fp); fwrite(list,sizeof(double),nsize,fp);
delete[] list;
} }
if (comm->me == 0) delete[] list;
} }
/* ---------------------------------------------------------------------- /* ----------------------------------------------------------------------