Skip to content

Commit e6c91f5

Browse files
committed
Merge remote-tracking branch 'origin/fix_desc_leak' into model_training
2 parents 92df041 + 1c6efe9 commit e6c91f5

File tree

6 files changed

+85
-7
lines changed

6 files changed

+85
-7
lines changed

src/interface/matrix.cxx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/*Copyright (c) 2011, Edgar Solomonik, all rights reserved.*/
22

33
#include "common.h"
4+
#include "world.h"
45
#include "../shared/blas_symbs.h"
56
#include "../shared/lapack_symbs.h"
67
#include <stdlib.h>
@@ -236,7 +237,7 @@ namespace CTF {
236237
}
237238
}
238239
this->write(nmyr*nmyc, pairs);
239-
CTF_int::cdealloc(pairs);
240+
delete [] pairs;
240241
}
241242
}
242243

@@ -296,7 +297,17 @@ namespace CTF {
296297
int ctxt;
297298
IASSERT(this->wrld->comm == MPI_COMM_WORLD);
298299
CTF_SCALAPACK::Cblacs_get(-1, 0, &ctxt);
299-
CTF_SCALAPACK::Cblacs_gridinit(&ctxt, &C, pr, pc);
300+
CTF_int::grid_wrapper gw;
301+
gw.pr = pr;
302+
gw.pc = pc;
303+
std::set<CTF_int::grid_wrapper>::iterator s = CTF_int::scalapack_grids.find(gw);
304+
if (s != CTF_int::scalapack_grids.end()){
305+
ctxt = s->ctxt;
306+
} else {
307+
CTF_SCALAPACK::Cblacs_gridinit(&ctxt, &C, pr, pc);
308+
gw.ctxt = ctxt;
309+
CTF_int::scalapack_grids.insert(gw);
310+
}
300311
ictxt = ctxt;
301312

302313
desc = (int*)malloc(sizeof(int)*9);
@@ -439,6 +450,8 @@ namespace CTF {
439450
CTF_SCALAPACK::porgqr<dtype>(m,n,n,dQ,1,1,desca,tau,work,lwork,&info);
440451
Q = Matrix<dtype>(desca, dQ, (*(this->wrld)));
441452
free(work);
453+
free(tau);
454+
free(desca);
442455
//make upper-tri
443456
int syns[] = {SY, NS};
444457
Tensor<dtype> tR(R,syns);

src/interface/partition.cxx

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,32 @@ namespace CTF {
4141

4242
Idx_Partition::Idx_Partition(Partition const & part_, char const * idx_){
4343
part = part_;
44-
idx = idx_;
44+
idx = (char*)malloc(part.order*sizeof(char));
45+
memcpy(idx, idx_, part.order*sizeof(char));
4546
}
47+
48+
Idx_Partition::~Idx_Partition(){
49+
if (idx != NULL){
50+
free(idx);
51+
idx = NULL;
52+
}
53+
}
54+
55+
Idx_Partition Idx_Partition::reduce_order() const {
56+
int * new_lens = (int*)malloc(part.order*sizeof(int));
57+
int new_order = 0;
58+
char * new_idx = (char*)malloc(part.order);
59+
for (int i=0; i<part.order; i++){
60+
if (part.lens[i] != 1){
61+
new_lens[new_order] = part.lens[i];
62+
new_idx[new_order] = idx[i];
63+
new_order++;
64+
}
65+
}
66+
Idx_Partition p = Partition(new_order, new_lens)[new_idx];
67+
free(new_idx);
68+
free(new_lens);
69+
return p;
70+
}
71+
4672
}

src/interface/partition.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,16 @@ namespace CTF {
2828
class Idx_Partition {
2929
public:
3030
Partition part;
31-
char const * idx;
31+
char * idx;
3232
Idx_Partition();
33+
~Idx_Partition();
3334
Idx_Partition(Partition const & part, char const * idx);
35+
36+
/**
37+
* \brief extracts non-trivial part of partition by ommitting unit dimensions
38+
* \return new partition with all dimensions non-unit
39+
*/
40+
Idx_Partition reduce_order() const;
3441
};
3542

3643
/**

src/interface/world.cxx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include "common.h"
44
#include "world.h"
5+
#include "../shared/lapack_symbs.h"
56
#include "../tensor/algstrct.h"
67
#include "../shared/util.h"
78
#include "../shared/memcontrol.h"
@@ -14,6 +15,18 @@ extern "C"
1415

1516
using namespace CTF_int;
1617

18+
namespace CTF_int {
19+
bool grid_wrapper::operator<(grid_wrapper const & other) const {
20+
if (this->pr == other.pr)
21+
return this->pc < other.pc;
22+
else
23+
return this->pr < other.pr;
24+
}
25+
26+
/** \brief index for ScaLAPACK processor grids */
27+
std::set<grid_wrapper> scalapack_grids;
28+
}
29+
1730
namespace CTF {
1831
bool universe_exists = false;
1932
World universe("");
@@ -96,6 +109,10 @@ namespace CTF {
96109
initialized = 0;
97110
mem_exit(rank);
98111
if (get_num_instances() == 0){
112+
for (std::set<grid_wrapper>::iterator it=scalapack_grids.begin(); it!=scalapack_grids.end(); it++){
113+
//printf("HERE %d %d %d\n",it->pr,it->pc,it->ctxt);
114+
CTF_SCALAPACK::Cblacs_gridexit(it->ctxt);
115+
}
99116
#ifdef OFFLOAD
100117
offload_exit();
101118
#endif

src/interface/world.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define __WORLD_H__
33

44
#include "common.h"
5+
#include <set>
56
#include "../mapping/topology.h"
67

78
namespace CTF {
@@ -144,6 +145,19 @@ namespace CTF {
144145
/**
145146
* @}
146147
*/
148+
147149
}
148150

151+
namespace CTF_int {
152+
class grid_wrapper {
153+
public:
154+
int pr;
155+
int pc;
156+
int ctxt;
157+
158+
bool operator<(grid_wrapper const & other) const;
159+
};
160+
extern std::set<grid_wrapper> scalapack_grids;
161+
162+
}
149163
#endif

src/tensor/untyped_tensor.cxx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,8 +1224,9 @@ namespace CTF_int {
12241224
}
12251225

12261226
void tensor::set_distribution(char const * idx,
1227-
Idx_Partition const & prl,
1227+
Idx_Partition const & prl_,
12281228
Idx_Partition const & blk){
1229+
Idx_Partition prl = prl_.reduce_order();
12291230
topology * top = new topology(prl.part.order, prl.part.lens, wrld->cdt);
12301231
int itopo = find_topology(top, wrld->topovec);
12311232
/* if (wrld->rank == 0){
@@ -1239,7 +1240,7 @@ namespace CTF_int {
12391240
if (itopo == -1){
12401241
itopo = wrld->topovec.size();
12411242
wrld->topovec.push_back(top);
1242-
}
1243+
} else delete top;
12431244
ASSERT(itopo != -1);
12441245
assert(itopo != -1);
12451246

@@ -1284,7 +1285,7 @@ namespace CTF_int {
12841285
ASSERT(0);
12851286
assert(0);
12861287
}
1287-
1288+
cdealloc(idx_A);
12881289
}
12891290

12901291

0 commit comments

Comments
 (0)