Commit 104dde27 authored by Axel Kohlmeyer's avatar Axel Kohlmeyer
Browse files

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

parent bfdfd36c
Loading
Loading
Loading
Loading
+8 −4
Original line number Diff line number Diff line
@@ -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;
      }
    }
                
+8 −3
Original line number Diff line number Diff line
@@ -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)
+3 −2
Original line number Diff line number Diff line
#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);
+10 −6
Original line number Diff line number Diff line
@@ -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;
+6 −5
Original line number Diff line number Diff line
@@ -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 */
Loading