diff --git a/lib/atc/ATC_Method.cpp b/lib/atc/ATC_Method.cpp index b1f3fa2545..5d61a7bed8 100644 --- a/lib/atc/ATC_Method.cpp +++ b/lib/atc/ATC_Method.cpp @@ -2015,8 +2015,8 @@ pecified LammpsInterface::instance()->int_allmax(&send_size,&max_size); if (comm_rank == 0) { - int intbuf[max_size]; - double buf[max_size]; + int *intbuf = new int[max_size]; + double *buf = new double[max_size]; for (int iproc = 1; iproc < nprocs; iproc++) { LammpsInterface::instance()->int_recv(intbuf,max_size,iproc); LammpsInterface::instance()->recv(buf,max_size,iproc); @@ -2024,15 +2024,19 @@ pecified out << intbuf[i] << " " << buf[i] << "\n"; } } + delete[] intbuf; + delete[] buf; } else { - int intbuf[send_size]; - double buf[send_size]; + int *intbuf = new int[send_size]; + double *buf = new double[send_size]; for (int i = 0; i < send_size; i++) { intbuf[i] = id2tag[i]; buf[i] = atomicVolumeMatrix(i,i); } LammpsInterface::instance()->int_send(intbuf,send_size); LammpsInterface::instance()->send(buf,send_size); + delete[] intbuf; + delete[] buf; } } diff --git a/lib/atc/FE_Engine.cpp b/lib/atc/FE_Engine.cpp index d8d6e3e440..0e94dfa031 100644 --- a/lib/atc/FE_Engine.cpp +++ b/lib/atc/FE_Engine.cpp @@ -352,8 +352,9 @@ namespace ATC{ // each segment of the piecewise funcion is length-normalized separately else if (strcmp(arg[argIdx],"position-number-density")==0) { argIdx++; - double y[nx],w[nx]; - int n[nx]; + double *y = new double[nx]; + double *w = new double[nx]; + int *n = new int[nx]; int nn = 0; while (argIdx < narg) { if (! is_numeric(arg[argIdx])) break; @@ -369,7 +370,7 @@ namespace ATC{ double w0 = w[i-1]; double dw = w[i]-w0; double lx = 0; - double l[dn]; + double *l = new double[dn]; for (int j = 0; j < dn; ++j) { double x = (j+0.5)/dn; double dl = w0+x*dw; @@ -380,7 +381,11 @@ namespace ATC{ for (int j = 0; j < dn; ++j) { dx(k++) = scale*l[j]; } + delete[] l; } + delete[] y; + delete[] w; + delete[] n; } // construct relative values from a density function // evaluate for a domain (0,1) diff --git a/lib/atc/Function.cpp b/lib/atc/Function.cpp index 0bd759695c..dfc42d5148 100644 --- a/lib/atc/Function.cpp +++ b/lib/atc/Function.cpp @@ -1,3 +1,4 @@ +#include #include "Function.h" #include "ATC_Error.h" #include "LammpsInterface.h" @@ -58,7 +59,7 @@ namespace ATC { { string type = args[0]; int narg = nargs -1; - double dargs[narg]; + double *dargs = alloca(sizeof(double) * narg); for (int i = 0; i < narg; ++i) dargs[i] = atof(args[i+1]); return function(type, narg, dargs); @@ -192,7 +193,7 @@ XT_Function_Mgr * XT_Function_Mgr::myInstance_ = NULL; { string type = args[0]; int narg = nargs -1; - double dargs[narg]; + double *dargs = alloca(sizeof(double) * narg); for (int i = 0; i < narg; ++i) dargs[i] = atof(args[i+1]); return function(type, narg, dargs); diff --git a/lib/atc/LammpsInterface.cpp b/lib/atc/LammpsInterface.cpp index d584d159ea..2238d930f4 100644 --- a/lib/atc/LammpsInterface.cpp +++ b/lib/atc/LammpsInterface.cpp @@ -131,15 +131,15 @@ void LammpsInterface::sparse_allsum(SparseMatrix &toShare) const if (error != MPI_SUCCESS) throw ATC_Error("error in sparse_allsum_numrows "+to_string(error)); // adjust row sendcounts because recRowsCRS is off by one - int rowCounts[nProcs]; - int sizeCounts[nProcs]; + int *rowCounts = new int[nProcs]; + int *sizeCounts = new int[nProcs]; // set up total size of receive buffers for Allgatherv calls int totalRowsCRS = 0; int totalSize = 0; // set up array of displacements for Allgatherv calls - int rowOffsets[nProcs]; + int *rowOffsets = new int[nProcs]; rowOffsets[0] = 0; - int sizeOffsets[nProcs]; + int *sizeOffsets = new int[nProcs]; sizeOffsets[0] = 0; for (int i = 0; i < nProcs; i++) { // find the total number of entries to share in the mpi calls below @@ -156,8 +156,8 @@ void LammpsInterface::sparse_allsum(SparseMatrix &toShare) const // get actual rows INDEX *rec_ia = new INDEX[totalRowsCRS]; if (toShare.size() == 0) { - double dummy[0]; - error = MPI_Allgatherv(dummy, 0, MPI_INT, + double dummy; + error = MPI_Allgatherv(&dummy, 0, MPI_INT, rec_ia, rowCounts, rowOffsets, MPI_INT, lammps_->world); } else @@ -211,6 +211,10 @@ void LammpsInterface::sparse_allsum(SparseMatrix &toShare) const toShare += tempMat; } } + delete[] rowCounts; + delete[] sizeCounts; + delete[] rowOffsets; + delete[] sizeOffsets; delete[] recInfo; delete[] rec_ia; diff --git a/lib/atc/LammpsInterface.h b/lib/atc/LammpsInterface.h index ff2b4ba9b2..2c78269522 100644 --- a/lib/atc/LammpsInterface.h +++ b/lib/atc/LammpsInterface.h @@ -315,7 +315,7 @@ class LammpsInterface { } else { int commSize = comm_size(); - double recv[commSize]; + double *recv = new double[commSize]; MPI_Wrappers::gather(lammps_->world,data,recv); if (rank_zero()) { full_msg << " ATC:" << tag; @@ -324,6 +324,7 @@ class LammpsInterface { } full_msg << "\n"; } + delete[] recv; } if (rank_zero()) { std::string mesg = full_msg.str(); @@ -577,13 +578,13 @@ class LammpsInterface { void destroy_2d_int_array(int **i) const; int ** grow_2d_int_array(int **array, int n1, int n2, const char *name) const; template - T * grow_array(T *&array, int n, const char *name) const {return lammps_->memory->grow(array,n,name);}; + T * grow_array(T *&array, int n, const char *name) const {return lammps_->memory->grow(array,n,name);} template - void destroy_array(T * array) {lammps_->memory->destroy(array);}; + void destroy_array(T * array) {lammps_->memory->destroy(array);} template - T ** grow_array(T **&array, int n1, int n2, const char *name) const {return lammps_->memory->grow(array,n1,n2,name);}; + T ** grow_array(T **&array, int n1, int n2, const char *name) const {return lammps_->memory->grow(array,n1,n2,name);} template - void destroy_array(T ** array) const {lammps_->memory->destroy(array);}; + void destroy_array(T ** array) const {lammps_->memory->destroy(array);} /*@}*/ /** \name Methods that interface with Update class */ diff --git a/lib/atc/MPI_Wrappers.cpp b/lib/atc/MPI_Wrappers.cpp index 9468644c53..b8a8ab77b7 100644 --- a/lib/atc/MPI_Wrappers.cpp +++ b/lib/atc/MPI_Wrappers.cpp @@ -94,7 +94,8 @@ namespace MPI_Wrappers { { int myRank; MPI_Comm_rank(MPI_COMM_WORLD, &myRank); - DOUBLE_RANK in[count],out[count]; + DOUBLE_RANK *in = new DOUBLE_RANK[count]; + DOUBLE_RANK *out = new DOUBLE_RANK[count]; for (int i = 0; i < count; i++) { in[i].val = send_buf[i]; in[i].rank = myRank; @@ -105,6 +106,8 @@ namespace MPI_Wrappers { for (int i = 0; i < count; i++) { rec_buf[i] = out[i].val; } + delete[] in; + delete[] out; return out[0].rank; } @@ -154,14 +157,16 @@ namespace MPI_Wrappers { { int error; int numprocs = size(comm); - int sizes[numprocs]; - int displacements[numprocs]; + int *sizes = new int[numprocs]; + int *displacements = new int[numprocs]; for (int i = 0; i < numprocs; ++i) { sizes[i] = 1; displacements[i] = i; } error = MPI_Scatterv(send_buf, sizes, displacements, MPI_INT, rec_buf, count, MPI_INT, 0, comm); if (error != MPI_SUCCESS) throw ATC_Error("error in int_scatter "+to_string(error)); + delete[] sizes; + delete[] displacements; } void allgatherv(MPI_Comm comm, double *send_buf, int send_count, diff --git a/lib/atc/Makefile.mpi b/lib/atc/Makefile.mpi index ec941efdcb..c1ce0500ea 100644 --- a/lib/atc/Makefile.mpi +++ b/lib/atc/Makefile.mpi @@ -52,4 +52,4 @@ fastdep.exe: ../../src/DEPEND/fastdep.c clean: -rm -f *.o *~ .depend $(LIB) fastdep.exe -sinclude $(DEPENDS) +sinclude .depend diff --git a/lib/atc/Makefile.mpic++ b/lib/atc/Makefile.mpic++ deleted file mode 120000 index 1f5f55d2ad..0000000000 --- a/lib/atc/Makefile.mpic++ +++ /dev/null @@ -1 +0,0 @@ -Makefile.mpi \ No newline at end of file diff --git a/lib/atc/PrescribedDataManager.h b/lib/atc/PrescribedDataManager.h index 05f553ab2d..738c34d593 100644 --- a/lib/atc/PrescribedDataManager.h +++ b/lib/atc/PrescribedDataManager.h @@ -154,7 +154,7 @@ namespace ATC { std::set fluxes; //list of nodes to insert. //1 for nodes to insert, 0 for nodes not to insert. - int toInsert[nNodes_]; + int *toInsert = new int[nNodes_]; for (int i = 0; i < nNodes_; ++i) toInsert[i] = 0; const std::map < std::pair , Array < XT_Function * > > & sources = faceSources_.find(thisField)->second; @@ -178,6 +178,7 @@ namespace ATC { for (int node = 0; node < nNodes_; ++node) { if (toInsert[node]) fluxes.insert(node); } + delete[] toInsert; return fluxes; } @@ -189,7 +190,7 @@ namespace ATC { { //list of nodes to insert. //1 for nodes to insert, 0 for nodes not to insert. - int toInsert[nNodes_]; + int *toInsert = new int[nNodes_]; for (int i = 0; i < nNodes_; ++i) toInsert[i] = 0; const std::map < std::pair , Array < XT_Function * > > & sources = faceSources_.find(thisField)->second; @@ -213,6 +214,7 @@ namespace ATC { for (int node = 0; node < nNodes_; ++node) { if (toInsert[node]) fluxes.insert(node); } + delete[] toInsert; } /** */ @@ -223,7 +225,7 @@ namespace ATC { std::set fluxes; //list of nodes to insert. //1 for nodes to insert, 0 for nodes not to insert. - int toInsert[nNodes_]; + int *toInsert = new int[nNodes_]; for (int i = 0; i < nNodes_; ++i) toInsert[i] = 0; const Array2D < XT_Function *> & sources = elementSources_.find(thisField)->second; @@ -244,6 +246,7 @@ namespace ATC { for (int node = 0; node < nNodes_; ++node) { if (toInsert[node]) fluxes.insert(node); } + delete[] toInsert; return fluxes; } @@ -255,7 +258,7 @@ namespace ATC { { //list of nodes to insert. //1 for nodes to insert, 0 for nodes not to insert. - int toInsert[nNodes_]; + int *toInsert = new int[nNodes_]; for (int i = 0; i < nNodes_; ++i) toInsert[i] = 0; const Array2D < XT_Function *> & sources = elementSources_.find(thisField)->second; @@ -276,6 +279,7 @@ namespace ATC { for (int node = 0; node < nNodes_; ++node) { if (toInsert[node]) fluxes.insert(node); } + delete[] toInsert; } /** */