Commit b802c9f9 authored by kraus's avatar kraus
Browse files

get rid of memory leak

parent d613add4
......@@ -45,15 +45,15 @@ FieldLayout<Dim>::FieldLayout() {
// we have one more FieldLayout, indicate this
//INCIPPLSTAT(incFieldLayouts);
// we have one more FieldLayout, indicate this
//INCIPPLSTAT(incFieldLayouts);
// just initialize basic things
vnodesPerDirection_m = 0;
// just initialize basic things
vnodesPerDirection_m = 0;
// for this kind of construction, we just take it that the user is
// requesting all parallel axes
for (unsigned int dl=0; dl < Dim; ++dl) RequestedLayout[dl] = PARALLEL;
// for this kind of construction, we just take it that the user is
// requesting all parallel axes
for (unsigned int dl=0; dl < Dim; ++dl) RequestedLayout[dl] = PARALLEL;
}
......@@ -68,18 +68,18 @@ FieldLayout<Dim>::FieldLayout(const char *filename) {
// we have one more FieldLayout, indicate this
//INCIPPLSTAT(incFieldLayouts);
// we have one more FieldLayout, indicate this
//INCIPPLSTAT(incFieldLayouts);
// try to initialize ourselves, by reading the info from the file.
vnodesPerDirection_m = 0;
// try to initialize ourselves, by reading the info from the file.
vnodesPerDirection_m = 0;
// for this kind of construction, we just take it that the user is
// requesting all parallel axes
for (unsigned int dl=0; dl < Dim; ++dl) RequestedLayout[dl] = PARALLEL;
// for this kind of construction, we just take it that the user is
// requesting all parallel axes
for (unsigned int dl=0; dl < Dim; ++dl) RequestedLayout[dl] = PARALLEL;
// read in data from file
read(filename);
// read in data from file
read(filename);
}
......@@ -88,8 +88,8 @@ FieldLayout<Dim>::FieldLayout(const char *filename) {
// class destructors inform all the FieldLayoutUser's we're going away.
template<unsigned Dim>
FieldLayout<Dim>::~FieldLayout() {
if (vnodesPerDirection_m != 0)
delete [] vnodesPerDirection_m;
if (vnodesPerDirection_m != 0)
delete [] vnodesPerDirection_m;
}
......@@ -110,7 +110,7 @@ FieldLayout<Dim>::initialize(const NDIndex<Dim>& domain,
e_dim_tag *p, int vnodes) {
setup(domain, p, vnodes);
setup(domain, p, vnodes);
}
......@@ -120,10 +120,10 @@ FieldLayout<Dim>::initialize(const Index& i1, e_dim_tag p1, int vnodes) {
PInsist(Dim==1,
"Number of arguments does not match dimension of FieldLayout!!");
NDIndex<Dim> ndi(i1);
setup(ndi,&p1,vnodes);
PInsist(Dim==1,
"Number of arguments does not match dimension of FieldLayout!!");
NDIndex<Dim> ndi(i1);
setup(ndi,&p1,vnodes);
}
template<unsigned Dim>
......@@ -133,15 +133,15 @@ FieldLayout<Dim>::initialize(const Index& i1, const Index& i2,
PInsist(Dim==2,
"Number of arguments does not match dimension of FieldLayout!!");
e_dim_tag par[Dim];
par[0] = p1;
par[1] = p2;
NDIndex<Dim> ndi;
ndi[0] = i1;
ndi[1] = i2;
setup(ndi,par,vnodes);
PInsist(Dim==2,
"Number of arguments does not match dimension of FieldLayout!!");
e_dim_tag par[Dim];
par[0] = p1;
par[1] = p2;
NDIndex<Dim> ndi;
ndi[0] = i1;
ndi[1] = i2;
setup(ndi,par,vnodes);
}
template<unsigned Dim>
void
......@@ -149,17 +149,17 @@ FieldLayout<Dim>::initialize(const Index& i1, const Index& i2, const Index& i3,
e_dim_tag p1, e_dim_tag p2, e_dim_tag p3,
int vnodes) {
PInsist(Dim==3,
"Number of arguments does not match dimension of FieldLayout!!");
e_dim_tag par[Dim];
par[0] = p1;
par[1] = p2;
par[2] = p3;
NDIndex<Dim> ndi;
ndi[0] = i1;
ndi[1] = i2;
ndi[2] = i3;
setup(ndi,par,vnodes);
PInsist(Dim==3,
"Number of arguments does not match dimension of FieldLayout!!");
e_dim_tag par[Dim];
par[0] = p1;
par[1] = p2;
par[2] = p3;
NDIndex<Dim> ndi;
ndi[0] = i1;
ndi[1] = i2;
ndi[2] = i3;
setup(ndi,par,vnodes);
}
template<unsigned Dim>
void
......@@ -170,19 +170,19 @@ FieldLayout<Dim>::initialize(const Index& i1, const Index& i2, const Index& i3,
int vnodes) {
PInsist(Dim==4,
"Number of arguments does not match dimension of FieldLayout!!");
e_dim_tag par[Dim];
par[0] = p1;
par[1] = p2;
par[2] = p3;
par[3] = p4;
NDIndex<Dim> ndi;
ndi[0] = i1;
ndi[1] = i2;
ndi[2] = i3;
ndi[3] = i4;
setup(ndi,par,vnodes);
PInsist(Dim==4,
"Number of arguments does not match dimension of FieldLayout!!");
e_dim_tag par[Dim];
par[0] = p1;
par[1] = p2;
par[2] = p3;
par[3] = p4;
NDIndex<Dim> ndi;
ndi[0] = i1;
ndi[1] = i2;
ndi[2] = i3;
ndi[3] = i4;
setup(ndi,par,vnodes);
}
template<unsigned Dim>
void
......@@ -192,21 +192,21 @@ FieldLayout<Dim>::initialize(const Index& i1, const Index& i2, const Index& i3,
e_dim_tag p4, e_dim_tag p5,
int vnodes) {
PInsist(Dim==5,
"Number of arguments does not match dimension of FieldLayout!!");
e_dim_tag par[Dim];
par[0] = p1;
par[1] = p2;
par[2] = p3;
par[3] = p4;
par[4] = p5;
NDIndex<Dim> ndi;
ndi[0] = i1;
ndi[1] = i2;
ndi[2] = i3;
ndi[3] = i4;
ndi[4] = i5;
setup(ndi,par,vnodes);
PInsist(Dim==5,
"Number of arguments does not match dimension of FieldLayout!!");
e_dim_tag par[Dim];
par[0] = p1;
par[1] = p2;
par[2] = p3;
par[3] = p4;
par[4] = p5;
NDIndex<Dim> ndi;
ndi[0] = i1;
ndi[1] = i2;
ndi[2] = i3;
ndi[3] = i4;
ndi[4] = i5;
setup(ndi,par,vnodes);
}
template<unsigned Dim>
void
......@@ -216,23 +216,23 @@ FieldLayout<Dim>::initialize(const Index& i1, const Index& i2, const Index& i3,
e_dim_tag p4, e_dim_tag p5, e_dim_tag p6,
int vnodes) {
PInsist(Dim==6,
"Number of arguments does not match dimension of FieldLayout!!");
e_dim_tag par[Dim];
par[0] = p1;
par[1] = p2;
par[2] = p3;
par[3] = p4;
par[4] = p5;
par[5] = p6;
NDIndex<Dim> ndi;
ndi[0] = i1;
ndi[1] = i2;
ndi[2] = i3;
ndi[3] = i4;
ndi[4] = i5;
ndi[5] = i6;
setup(ndi,par,vnodes);
PInsist(Dim==6,
"Number of arguments does not match dimension of FieldLayout!!");
e_dim_tag par[Dim];
par[0] = p1;
par[1] = p2;
par[2] = p3;
par[3] = p4;
par[4] = p5;
par[5] = p6;
NDIndex<Dim> ndi;
ndi[0] = i1;
ndi[1] = i2;
ndi[2] = i3;
ndi[3] = i4;
ndi[4] = i5;
ndi[5] = i6;
setup(ndi,par,vnodes);
}
//-----------------------------------------------------------------------------
......@@ -249,20 +249,20 @@ FieldLayout<Dim>::initialize(const NDIndex<Dim>& domain,
bool recurse, int vnodes) {
// Default to correct total vnodes:
unsigned vnodesProduct = 1;
for (unsigned int d=0; d<Dim; d++) vnodesProduct *= vnodesPerDirection[d];
if (vnodes == -1) vnodes = vnodesProduct;
// Verify than total vnodes is product of per-dimension vnode counts:
if ((unsigned int) vnodes != vnodesProduct) {
ERRORMSG("FieldLayout constructor: "
<< "(vnodes != vnodesPerDirection[0]*vnodesPerDirection[1]*"
<< "...*vnodesPerDirection[" << Dim-1 << "])"
<< " ; vnodesPerDirection[0]*vnodesPerDirection[1]*"
<< "...*vnodesPerDirection[" << Dim-1 << "] = "
<< vnodesProduct << " ; vnodes = " << vnodes << endl);
}
setup(domain, p, vnodesPerDirection,recurse,vnodes);
// Default to correct total vnodes:
unsigned vnodesProduct = 1;
for (unsigned int d=0; d<Dim; d++) vnodesProduct *= vnodesPerDirection[d];
if (vnodes == -1) vnodes = vnodesProduct;
// Verify than total vnodes is product of per-dimension vnode counts:
if ((unsigned int) vnodes != vnodesProduct) {
ERRORMSG("FieldLayout constructor: "
<< "(vnodes != vnodesPerDirection[0]*vnodesPerDirection[1]*"
<< "...*vnodesPerDirection[" << Dim-1 << "])"
<< " ; vnodesPerDirection[0]*vnodesPerDirection[1]*"
<< "...*vnodesPerDirection[" << Dim-1 << "] = "
<< vnodesProduct << " ; vnodes = " << vnodes << endl);
}
setup(domain, p, vnodesPerDirection,recurse,vnodes);
}
template<unsigned Dim>
......@@ -272,10 +272,10 @@ FieldLayout<Dim>::initialize(const Index& i1, e_dim_tag p1,
PInsist(Dim==1,
"Number of arguments does not match dimension of FieldLayout!!");
NDIndex<Dim> ndi(i1);
setup(ndi,&p1,&vnodes1,recurse,vnodes);
PInsist(Dim==1,
"Number of arguments does not match dimension of FieldLayout!!");
NDIndex<Dim> ndi(i1);
setup(ndi,&p1,&vnodes1,recurse,vnodes);
}
template<unsigned Dim>
......@@ -285,18 +285,18 @@ FieldLayout<Dim>::initialize(const Index& i1, const Index& i2,
unsigned vnodes1, unsigned vnodes2,
bool recurse, int vnodes) {
PInsist(Dim==2,
"Number of arguments does not match dimension of FieldLayout!!");
e_dim_tag par[Dim];
par[0] = p1;
par[1] = p2;
NDIndex<Dim> ndi;
ndi[0] = i1;
ndi[1] = i2;
unsigned vnodesPerDirection[Dim];
vnodesPerDirection[0] = vnodes1;
vnodesPerDirection[1] = vnodes2;
setup(ndi,par,vnodesPerDirection,recurse,vnodes);
PInsist(Dim==2,
"Number of arguments does not match dimension of FieldLayout!!");
e_dim_tag par[Dim];
par[0] = p1;
par[1] = p2;
NDIndex<Dim> ndi;
ndi[0] = i1;
ndi[1] = i2;
unsigned vnodesPerDirection[Dim];
vnodesPerDirection[0] = vnodes1;
vnodesPerDirection[1] = vnodes2;
setup(ndi,par,vnodesPerDirection,recurse,vnodes);
}
template<unsigned Dim>
void
......@@ -306,21 +306,21 @@ FieldLayout<Dim>::initialize(const Index& i1, const Index& i2, const Index& i3,
unsigned vnodes3,
bool recurse, int vnodes) {
PInsist(Dim==3,
"Number of arguments does not match dimension of FieldLayout!!");
e_dim_tag par[Dim];
par[0] = p1;
par[1] = p2;
par[2] = p3;
NDIndex<Dim> ndi;
ndi[0] = i1;
ndi[1] = i2;
ndi[2] = i3;
unsigned vnodesPerDirection[Dim];
vnodesPerDirection[0] = vnodes1;
vnodesPerDirection[1] = vnodes2;
vnodesPerDirection[2] = vnodes3;
setup(ndi,par,vnodesPerDirection,recurse,vnodes);
PInsist(Dim==3,
"Number of arguments does not match dimension of FieldLayout!!");
e_dim_tag par[Dim];
par[0] = p1;
par[1] = p2;
par[2] = p3;
NDIndex<Dim> ndi;
ndi[0] = i1;
ndi[1] = i2;
ndi[2] = i3;
unsigned vnodesPerDirection[Dim];
vnodesPerDirection[0] = vnodes1;
vnodesPerDirection[1] = vnodes2;
vnodesPerDirection[2] = vnodes3;
setup(ndi,par,vnodesPerDirection,recurse,vnodes);
}
template<unsigned Dim>
void
......@@ -332,24 +332,24 @@ FieldLayout<Dim>::initialize(const Index& i1, const Index& i2, const Index& i3,
unsigned vnodes3, unsigned vnodes4,
bool recurse, int vnodes) {
PInsist(Dim==4,
"Number of arguments does not match dimension of FieldLayout!!");
e_dim_tag par[Dim];
par[0] = p1;
par[1] = p2;
par[2] = p3;
par[3] = p4;
NDIndex<Dim> ndi;
ndi[0] = i1;
ndi[1] = i2;
ndi[2] = i3;
ndi[3] = i4;
unsigned vnodesPerDirection[Dim];
vnodesPerDirection[0] = vnodes1;
vnodesPerDirection[1] = vnodes2;
vnodesPerDirection[2] = vnodes3;
vnodesPerDirection[3] = vnodes4;
setup(ndi,par,vnodesPerDirection,recurse,vnodes);
PInsist(Dim==4,
"Number of arguments does not match dimension of FieldLayout!!");
e_dim_tag par[Dim];
par[0] = p1;
par[1] = p2;
par[2] = p3;
par[3] = p4;
NDIndex<Dim> ndi;
ndi[0] = i1;
ndi[1] = i2;
ndi[2] = i3;
ndi[3] = i4;
unsigned vnodesPerDirection[Dim];
vnodesPerDirection[0] = vnodes1;
vnodesPerDirection[1] = vnodes2;
vnodesPerDirection[2] = vnodes3;
vnodesPerDirection[3] = vnodes4;
setup(ndi,par,vnodesPerDirection,recurse,vnodes);
}
template<unsigned Dim>
void
......@@ -362,27 +362,27 @@ FieldLayout<Dim>::initialize(const Index& i1, const Index& i2, const Index& i3,
unsigned vnodes5,
bool recurse, int vnodes) {
PInsist(Dim==5,
"Number of arguments does not match dimension of FieldLayout!!");
e_dim_tag par[Dim];
par[0] = p1;
par[1] = p2;
par[2] = p3;
par[3] = p4;
par[4] = p5;
NDIndex<Dim> ndi;
ndi[0] = i1;
ndi[1] = i2;
ndi[2] = i3;
ndi[3] = i4;
ndi[4] = i5;
unsigned vnodesPerDirection[Dim];
vnodesPerDirection[0] = vnodes1;
vnodesPerDirection[1] = vnodes2;
vnodesPerDirection[2] = vnodes3;
vnodesPerDirection[3] = vnodes4;
vnodesPerDirection[4] = vnodes5;
setup(ndi,par,vnodesPerDirection,recurse,vnodes);
PInsist(Dim==5,
"Number of arguments does not match dimension of FieldLayout!!");
e_dim_tag par[Dim];
par[0] = p1;
par[1] = p2;
par[2] = p3;
par[3] = p4;
par[4] = p5;
NDIndex<Dim> ndi;
ndi[0] = i1;
ndi[1] = i2;
ndi[2] = i3;
ndi[3] = i4;
ndi[4] = i5;
unsigned vnodesPerDirection[Dim];
vnodesPerDirection[0] = vnodes1;
vnodesPerDirection[1] = vnodes2;
vnodesPerDirection[2] = vnodes3;
vnodesPerDirection[3] = vnodes4;
vnodesPerDirection[4] = vnodes5;
setup(ndi,par,vnodesPerDirection,recurse,vnodes);
}
template<unsigned Dim>
void
......@@ -395,30 +395,30 @@ FieldLayout<Dim>::initialize(const Index& i1, const Index& i2, const Index& i3,
unsigned vnodes5, unsigned vnodes6,
bool recurse, int vnodes) {
PInsist(Dim==6,
"Number of arguments does not match dimension of FieldLayout!!");
e_dim_tag par[Dim];
par[0] = p1;
par[1] = p2;
par[2] = p3;
par[3] = p4;
par[4] = p5;
par[5] = p6;
NDIndex<Dim> ndi;
ndi[0] = i1;
ndi[1] = i2;
ndi[2] = i3;
ndi[3] = i4;
ndi[4] = i5;
ndi[5] = i6;
unsigned vnodesPerDirection[Dim];
vnodesPerDirection[0] = vnodes1;
vnodesPerDirection[1] = vnodes2;
vnodesPerDirection[2] = vnodes3;
vnodesPerDirection[3] = vnodes4;
vnodesPerDirection[4] = vnodes5;
vnodesPerDirection[5] = vnodes6;
setup(ndi,par,vnodesPerDirection,recurse,vnodes);
PInsist(Dim==6,
"Number of arguments does not match dimension of FieldLayout!!");
e_dim_tag par[Dim];
par[0] = p1;
par[1] = p2;
par[2] = p3;
par[3] = p4;
par[4] = p5;
par[5] = p6;
NDIndex<Dim> ndi;
ndi[0] = i1;
ndi[1] = i2;
ndi[2] = i3;
ndi[3] = i4;
ndi[4] = i5;
ndi[5] = i6;
unsigned vnodesPerDirection[Dim];
vnodesPerDirection[0] = vnodes1;
vnodesPerDirection[1] = vnodes2;
vnodesPerDirection[2] = vnodes3;
vnodesPerDirection[3] = vnodes4;
vnodesPerDirection[4] = vnodes5;
vnodesPerDirection[5] = vnodes6;
setup(ndi,par,vnodesPerDirection,recurse,vnodes);
}
//-----------------------------------------------------------------------------
......@@ -439,72 +439,72 @@ FieldLayout<Dim>::initialize(const NDIndex<Dim> &domain,
const int *nbegin, const int *nend)
{
// Loop variables
int i, j;
unsigned int d;
// Save the total domain.
Domain = domain;
// Find the number of vnodes requested
int vnodes = (nend - nbegin);
PInsist(vnodes > 0,
"A user-specified FieldLayout must have at least one vnode.");
PInsist(vnodes == (domend - dombegin),
"A user-specified FieldLayout must have equal length node and domain lists");
// Since we don't know any differently, indicate the requested
// layout is all parallel
for (d = 0; d < Dim; ++d)
RequestedLayout[d] = PARALLEL;
// This is not a grid-like layout, so set the pointer for this to 0
vnodesPerDirection_m = 0;
// Create the empty remote vnode list
ac_domain_vnodes *remote_ac = new ac_domain_vnodes(domain);
typedef typename ac_gc_domain_vnodes::value_type vntype;
Remotes_ac.insert( vntype(gc0(), remote_ac) );
// Loop through the vnodes, and add them to our local or remote lists.
// Do a sanity check on the vnodes, making sure each one does not
// intersect any other. Also, add up the size of each vnode, if it
// does not equal the size of the total domain, there are holes
// and it is an error.
size_t coverage = 0;
for (i = 0; i < vnodes; ++i) {
// Compare to other vnodes
for (j = (i+1); j < vnodes; ++j) {
PInsist(! (dombegin[i].touches(dombegin[j])),
"A user-specified FieldLayout cannot have overlapping domains.");
}
// Loop variables
int i, j;
unsigned int d;
// Save the total domain.
Domain = domain;
// Find the number of vnodes requested
int vnodes = (nend - nbegin);
PInsist(vnodes > 0,
"A user-specified FieldLayout must have at least one vnode.");
PInsist(vnodes == (domend - dombegin),
"A user-specified FieldLayout must have equal length node and domain lists");
// Since we don't know any differently, indicate the requested
// layout is all parallel
for (d = 0; d < Dim; ++d)
RequestedLayout[d] = PARALLEL;
// This is not a grid-like layout, so set the pointer for this to 0
vnodesPerDirection_m = 0;
// Create the empty remote vnode list
ac_domain_vnodes *remote_ac = new ac_domain_vnodes(domain);
typedef typename ac_gc_domain_vnodes::value_type vntype;
Remotes_ac.insert( vntype(gc0(), remote_ac) );
// Loop through the vnodes, and add them to our local or remote lists.
// Do a sanity check on the vnodes, making sure each one does not
// intersect any other. Also, add up the size of each vnode, if it
// does not equal the size of the total domain, there are holes
// and it is an error.
size_t coverage = 0;
for (i = 0; i < vnodes; ++i) {
// Compare to other vnodes
for (j = (i+1); j < vnodes; ++j) {
PInsist(! (dombegin[i].touches(dombegin[j])),
"A user-specified FieldLayout cannot have overlapping domains.");
}
// Make sure the processor ID is OK
PInsist(nbegin[i] >= 0 && nbegin[i] < Ippl::getNodes(),
"A user-specified FieldLayout must have legal node assignments.");
// Make sure the processor ID is OK
PInsist(nbegin[i] >= 0 && nbegin[i] < Ippl::getNodes(),
"A user-specified FieldLayout must have legal node assignments.");
// Add in the volume of this domain
coverage += dombegin[i].size();
// Add in the volume of this domain
coverage += dombegin[i].size();