eliminate variable length arrays from AtC lib for C++ standard compliance

This commit is contained in:
Axel Kohlmeyer 2018-05-07 17:36:34 -04:00
parent bfdfd36c1c
commit 104dde27ed
9 changed files with 52 additions and 29 deletions

View File

@ -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;
}
}

View File

@ -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)

View File

@ -1,3 +1,4 @@
#include <alloca.h>
#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);

View File

@ -131,15 +131,15 @@ void LammpsInterface::sparse_allsum(SparseMatrix<double> &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<double> &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<double> &toShare) const
toShare += tempMat;
}
}
delete[] rowCounts;
delete[] sizeCounts;
delete[] rowOffsets;
delete[] sizeOffsets;
delete[] recInfo;
delete[] rec_ia;

View File

@ -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 <typename T>
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 <typename T>
void destroy_array(T * array) {lammps_->memory->destroy(array);};
void destroy_array(T * array) {lammps_->memory->destroy(array);}
template <typename T>
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 <typename T>
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 */

View File

@ -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,

View File

@ -52,4 +52,4 @@ fastdep.exe: ../../src/DEPEND/fastdep.c
clean:
-rm -f *.o *~ .depend $(LIB) fastdep.exe
sinclude $(DEPENDS)
sinclude .depend

View File

@ -1 +0,0 @@
Makefile.mpi

View File

@ -154,7 +154,7 @@ namespace ATC {
std::set<int> 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 <int, int>, 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 <int, int>, 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<int> 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;
}
/** */