Unverified Commit a537ffab authored by Axel Kohlmeyer's avatar Axel Kohlmeyer
Browse files

correct illegal and uninitialized data access issue

parent 2fea8f88
Loading
Loading
Loading
Loading
+7 −5
Original line number Original line Diff line number Diff line
@@ -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 = new double[nsize];
    list[0] = energy;
    list[0] = energy;
    list[1] = comm->nprocs;
    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;
}
}


/* ----------------------------------------------------------------------
/* ----------------------------------------------------------------------
+7 −5
Original line number Original line Diff line number Diff line
@@ -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 = new double[nsize];
    list[0] = energy;
    list[0] = energy;
    list[1] = comm->nprocs;
    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;
}
}


/* ----------------------------------------------------------------------
/* ----------------------------------------------------------------------