Skip to content

Commit 8af9faf

Browse files
authored
Fixed power flow build and run problems (#7)
* WIP * Fixed power flow * Consolidate and declutter build files
1 parent 3ba70b6 commit 8af9faf

File tree

8 files changed

+31
-171
lines changed

8 files changed

+31
-171
lines changed

.envrc.local

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#!/bin/zsh

BUILD.bazel

+16-103
Original file line numberDiff line numberDiff line change
@@ -59,29 +59,17 @@ cmake(
5959
cmake(
6060
name = "armadillo_lib",
6161
cache_entries = {
62-
# "CMAKE_INSTALL_PREFIX": ".",
63-
# "CMAKE_INSTALL_INCLUDEDIR": "include",
64-
# deps ":openblas_lib_bazel" will be copied to "$EXT_BUILD_DEPS"
65-
# The directory structure of ":openblas_lib_bazel" are retained,
66-
# usually libraries are under /lib and headers are under /include
67-
# "TPL_BLAS_LIBRARIES": "$EXT_BUILD_DEPS/lib/libopenblas.a"
6862
"BUILD_SHARED_LIBS": "OFF",
6963
},
7064
lib_source = "@armadillo//:all_srcs",
7165
out_static_libs = ["libarmadillo.a"],
72-
# out_include_dir = "include",
7366
deps = [
74-
# cannot directly use ":openblas_lib",
75-
# need bridged through a `cc_library` containing ":openblas_lib"
76-
# i.e. ":openblas_lib_bazel"
7767
":openblas_lib_bazel"
7868
],
7969
copts =[
8070
"-DARMA_DONT_USE_WRAPPER"
8171
],
8272
linkopts = [
83-
# "-lpthread",
84-
# "-L$EXT_BUILD_DEPS/lib", "-lopenblas",
8573
"-lgfortran",
8674
],
8775
)
@@ -94,100 +82,46 @@ cc_library(
9482
],
9583
)
9684

97-
cmake(
85+
#
86+
configure_make(
9887
name = "hdf5_lib",
99-
cache_entries = {
100-
# "CMAKE_INSTALL_PREFIX": ".",
101-
# "CMAKE_INSTALL_INCLUDEDIR": "include",
102-
# deps ":openblas_lib_bazel" will be copied to "$EXT_BUILD_DEPS"
103-
# The directory structure of ":openblas_lib_bazel" are retained,
104-
# usually libraries are under /lib and headers are under /include
105-
# "TPL_BLAS_LIBRARIES": "$EXT_BUILD_DEPS/lib/libopenblas.a"
106-
"BUILD_SHARED_LIBS": "OFF",
107-
"CMAKE_BUILD_TYPE": "Release",
108-
"HDF5_BUILD_TOOLS": "ON",
109-
"BUILD_TESTING": "ON",
110-
"SZIP_USE_EXTERNAL": "ON",
111-
"ZLIB_USE_EXTERNAL": "ON",
112-
"USE_LIBAEC_STATIC": "ON",
113-
"SZIP_INCLUDE_DIR": "$EXT_BUILD_DEPS/include",
114-
"ZLIB_INCLUDE_DIR": "$EXT_BUILD_DEPS/include",
115-
"SZIP_LIBRARY": "$EXT_BUILD_DEPS/lib/libsz.a",
116-
"ZLIB_LIBRARY": "$EXT_BUILD_DEPS/lib/libz.a",
117-
},
88+
configure_in_place = True,
89+
configure_options = [
90+
"--with-szlib=libaec/include,$EXT_BUILD_DEPS/libaec/lib",
91+
"--with-zlib=z_lib/include,$EXT_BUILD_DEPS/z_lib/lib",
92+
],
11893
lib_source = "@hdf5//:all_srcs",
119-
out_static_libs = ["libhdf5.a"],
120-
# out_include_dir = "include",
12194
deps = [
122-
# cannot directly use ":openblas_lib",
123-
# need bridged through a `cc_library` containing ":openblas_lib"
124-
# i.e. ":openblas_lib_bazel"
125-
# ":openblas_lib_bazel"
12695
":hdf5_deps_lib",
12796
],
128-
linkopts = [
129-
# "-lpthread",
130-
# "-L$EXT_BUILD_DEPS/lib", "-lopenblas",
131-
# "-lgfortran",
132-
# "-lsz", "-lz",
133-
],
97+
out_static_libs = ["libhdf5.a"],
98+
linkopts = ["-lpthread"],
99+
includes = [
100+
"z_lib/include",
101+
"libaec/include",
102+
]
134103
)
135104

136105
cmake(
137106
name = "z_lib",
138107
cache_entries = {
139-
# "CMAKE_INSTALL_PREFIX": ".",
140-
# "CMAKE_INSTALL_INCLUDEDIR": "include",
141-
# deps ":openblas_lib_bazel" will be copied to "$EXT_BUILD_DEPS"
142-
# The directory structure of ":openblas_lib_bazel" are retained,
143-
# usually libraries are under /lib and headers are under /include
144-
# "TPL_BLAS_LIBRARIES": "$EXT_BUILD_DEPS/lib/libopenblas.a"
145108
"BUILD_SHARED_LIBS": "OFF",
146109
},
147110
lib_source = "@zlib//:all_srcs",
148111
out_static_libs = ["libz.a"],
149-
# out_include_dir = "include",
150-
deps = [
151-
# cannot directly use ":openblas_lib",
152-
# need bridged through a `cc_library` containing ":openblas_lib"
153-
# i.e. ":openblas_lib_bazel"
154-
# ":openblas_lib_bazel"
155-
],
156-
linkopts = [
157-
# "-lpthread",
158-
# "-L$EXT_BUILD_DEPS/lib", "-lopenblas",
159-
# "-lgfortran",
160-
],
112+
copts = ["-fPIC"] # this is necessary otherwise will cause hdf5 build to complain
161113
)
162114

163115
cmake(
164116
name = "libaec",
165117
cache_entries = {
166-
# "CMAKE_INSTALL_PREFIX": ".",
167-
# "CMAKE_INSTALL_INCLUDEDIR": "include",
168-
# deps ":openblas_lib_bazel" will be copied to "$EXT_BUILD_DEPS"
169-
# The directory structure of ":openblas_lib_bazel" are retained,
170-
# usually libraries are under /lib and headers are under /include
171-
# "TPL_BLAS_LIBRARIES": "$EXT_BUILD_DEPS/lib/libopenblas.a"
172118
"BUILD_SHARED_LIBS": "OFF",
173119
},
174120
lib_source = "@libaec//:all_srcs",
175121
out_static_libs = [
176122
"libaec.a",
177123
"libsz.a",
178124
],
179-
# out_include_dir = "include",
180-
deps = [
181-
# cannot directly use ":openblas_lib",
182-
# need bridged through a `cc_library` containing ":openblas_lib"
183-
# i.e. ":openblas_lib_bazel"
184-
# ":openblas_lib_bazel"
185-
],
186-
linkopts = [
187-
# "-lpthread",
188-
# "-L$EXT_BUILD_DEPS/lib", "-lopenblas",
189-
# "-lgfortran",
190-
],
191125
)
192126

193127
#
@@ -197,15 +131,12 @@ configure_make(
197131
configure_options = [
198132
"--enable-mat73=yes",
199133
"--enable-extended-sparse=yes",
200-
"--with-zlib=\"$EXT_BUILD_DEPS/hdf5_lib/lib\"",
201-
"--with-hdf5=\"$EXT_BUILD_DEPS/z_lib/lib\"",
134+
"--with-hdf5=\"$EXT_BUILD_DEPS/hdf5_lib/lib\"",
135+
"--with-zlib=\"$EXT_BUILD_DEPS/z_lib/lib\"",
202136
"--with-default-file-ver=7.3",
203137
],
204138
lib_source = "@libmatio//:all_srcs",
205139
deps = [
206-
# cannot directly use ":openblas_lib",
207-
# need bridged through a `cc_library` containing ":openblas_lib"
208-
# i.e. ":openblas_lib_bazel"
209140
":hdf5_lib",
210141
":z_lib",
211142
],
@@ -216,28 +147,10 @@ configure_make(
216147
cmake(
217148
name = "libjsoncpp",
218149
cache_entries = {
219-
# "CMAKE_INSTALL_PREFIX": ".",
220-
# "CMAKE_INSTALL_INCLUDEDIR": "include",
221-
# deps ":openblas_lib_bazel" will be copied to "$EXT_BUILD_DEPS"
222-
# The directory structure of ":openblas_lib_bazel" are retained,
223-
# usually libraries are under /lib and headers are under /include
224-
# "TPL_BLAS_LIBRARIES": "$EXT_BUILD_DEPS/lib/libopenblas.a"
225150
"BUILD_SHARED_LIBS": "OFF",
226151
},
227152
lib_source = "@jsoncpp//:all_srcs",
228153
out_static_libs = [
229154
"libjsoncpp.a",
230155
],
231-
# out_include_dir = "include",
232-
deps = [
233-
# cannot directly use ":openblas_lib",
234-
# need bridged through a `cc_library` containing ":openblas_lib"
235-
# i.e. ":openblas_lib_bazel"
236-
# ":openblas_lib_bazel"
237-
],
238-
linkopts = [
239-
# "-lpthread",
240-
# "-L$EXT_BUILD_DEPS/lib", "-lopenblas",
241-
# "-lgfortran",
242-
],
243156
)

app/BUILD.bazel

+4-1
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,8 @@ cc_binary(
1313
"//sas:sas_expr_parser_lib",
1414
"//sas:sas_model_parser_lib",
1515
"@nvwa//:nvwa_pctimer_headers",
16-
]
16+
],
17+
env = {
18+
19+
}
1720
)

app/main.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ int main(int argc, char **argv)
400400
double alphaTol = 1e-4;
401401
double diffTol = 1e-6;
402402
double diffTolMax = 1e-2;
403-
int repeat = 10;
403+
int repeat = 1;
404404
for (int iArg = 2; iArg < argc; iArg++)
405405
{
406406
string arg = argv[iArg];

pf/ChePFCalculator.cpp

+6-65
Original file line numberDiff line numberDiff line change
@@ -1232,7 +1232,8 @@ namespace che {
12321232
if(this->perm_c==NULL){
12331233
options.ColPerm=arma::superlu::COLAMD;
12341234
}else{
1235-
options.ColPerm=arma::superlu::MY_PERMC;
1235+
// TODO - rygx: work with arma team to fix the enum slip issue
1236+
options.ColPerm=static_cast<arma::superlu::colperm_t>(8); // This represents the MY_PERMC in SuperLu 6.0
12361237
arrayops::copy(perm_c,this->perm_c,A.n_cols + 1);
12371238
}
12381239
options.Fact=arma::superlu::DOFACT;
@@ -1243,37 +1244,8 @@ namespace che {
12431244
arrayops::copy(perm_r,this->perm_r,A.n_rows + 1);
12441245
arrayops::copy(etree,this->etree,A.n_cols + 1);
12451246
}
1246-
if (use_iter_solver){
1247-
// arma_wrapper(dgssvx)(&options, &superA, perm_c, perm_r, etree, equed, R, C, &superL, &superU, &work[0], lwork, &superB, &superX, &rpg, &rcond, ferr, berr, &glu, &mu, &stat, &superInfo);
1248-
arma_wrapper(ilu_set_default_options)(&options);
1249-
options.Equil=arma::superlu::NO;
1250-
lwork=0;
1251-
char equedx[1]={'N'};
1252-
arma_wrapper(dgsisx)(&options, &superA, perm_c, perm_r, etree, equedx, R, C, &superL, &superU, NULL, 0, &superB, &superX, &rpg, &rcond, &glu, &mu, &stat, &superInfo);
1253-
// arma_wrapper(dgsitrf)(&options, &superA, 2, 10, etree, &work[0], lwork, perm_c, perm_r, &superL, &superU, &glu, &stat, &superInfo);
1254-
// arma_wrapper(dgstrs)(options.Trans, &superL, &superU, perm_c, perm_r, &superX, &stat, &superInfo);
1255-
1256-
vec xx=RHS;
1257-
arma::superlu::SuperMatrix superX2; arrayops::inplace_set(reinterpret_cast<char*>(&superX2), char(0), sizeof(arma::superlu::SuperMatrix));
1258-
1259-
const bool status_x2 = sp_auxlib::wrap_to_supermatrix(superX2, xx);
1260-
arma_wrapper(dgstrs)(options.Trans, &superL, &superU, perm_c, perm_r, &superX2, &stat, &superInfo);
1261-
x=xx;
1262-
sp_auxlib::destroy_supermatrix(superX2);
1263-
1264-
int max_it=5000;
1265-
double tol=1.0e-10;
1266-
double err=0.0;
1267-
int iter=0;
1268-
int flag=0;
1269-
// x.fill(0.0);
1270-
// LHS_mat.print("A");
1271-
vec cbx=RHS;
1272-
bicgstab(LHS_mat, x, cbx, options.Trans, &superL, &superU, perm_c, perm_r, &stat, &superInfo, max_it, tol, &err, &iter, &flag);
1273-
}else{
1274-
arma_wrapper(dgssvx)(&options, &superA, perm_c, perm_r, etree, equed, R, C, &superL, &superU, &work[0], lwork, &superB, &superX, &rpg, &rcond, ferr, berr, &glu, &mu, &stat, &superInfo);
1275-
}
1276-
// arma_wrapper(dgssvx)(&options, &superA, perm_c, perm_r, etree, equed, R, C, &superL, &superU, &work[0], lwork, &superB, &superX, &rpg, &rcond, ferr, berr, &glu, &mu, &stat, &superInfo);
1247+
1248+
arma_wrapper(dgssvx)(&options, &superA, perm_c, perm_r, etree, equed, R, C, &superL, &superU, &work[0], lwork, &superB, &superX, &rpg, &rcond, ferr, berr, &glu, &mu, &stat, &superInfo);
12771249

12781250
if(this->perm_c==NULL){
12791251
this->perm_c=new int[A.n_cols + 1];
@@ -1288,39 +1260,8 @@ namespace che {
12881260
arrayops::copy(this->perm_r,perm_r,A.n_rows + 1);
12891261
arrayops::copy(this->etree,etree,A.n_cols + 1);
12901262
}
1291-
else {
1292-
if (use_iter_solver){
1293-
// x.print("xx");
1294-
// arma_wrapper(dgstrs)(options.Trans, &superL, &superU, perm_c, perm_r, &superX, &stat, &superInfo);
1295-
// x.print("xx");
1296-
arma_wrapper(ilu_set_default_options)(&options);
1297-
options.Equil=arma::superlu::NO;
1298-
// lwork=0;
1299-
// char equedx[1]={'B'};
1300-
// arma_wrapper(dgsisx)(&options, &superA, perm_c, perm_r, etree, equedx, R, C, &superL, &superU, NULL, 0, &superB, &superX, &rpg, &rcond, &glu, &mu, &stat, &superInfo);
1301-
1302-
int max_it=5000;
1303-
double tol=1.0e-10;
1304-
double err=0.0;
1305-
int iter=0;
1306-
int flag=0;
1307-
1308-
vec xx=RHS;
1309-
arma::superlu::SuperMatrix superX2; arrayops::inplace_set(reinterpret_cast<char*>(&superX2), char(0), sizeof(arma::superlu::SuperMatrix));
1310-
1311-
const bool status_x2 = sp_auxlib::wrap_to_supermatrix(superX2, xx);
1312-
arma_wrapper(dgstrs)(options.Trans, &superL, &superU, perm_c, perm_r, &superX2, &stat, &superInfo);
1313-
x=xx;
1314-
sp_auxlib::destroy_supermatrix(superX2);
1315-
1316-
// x.print("x");
1317-
vec cbx=RHS;
1318-
bicgstab(LHS_mat, x, cbx, options.Trans, &superL, &superU, perm_c, perm_r, &stat, &superInfo, max_it, tol, &err, &iter, &flag);
1319-
// x.print("x");
1320-
}else{
1321-
arma_wrapper(dgstrs)(options.Trans, &superL, &superU, perm_c, perm_r, &superX, &stat, &superInfo);
1322-
}
1323-
1263+
else {
1264+
arma_wrapper(dgstrs)(options.Trans, &superL, &superU, perm_c, perm_r, &superX, &stat, &superInfo);
13241265
}
13251266

13261267
// x.print("x");

pf/ChePFCalculator.h

+1
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ namespace che {
8383

8484
virtual CheSolution* getCheSolution();
8585
};
86+
8687
}
8788
}
8889

sas/BUILD.bazel

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ cc_library(
9494
"ModelParser.cpp",
9595
],
9696
deps = [
97-
":sas_expr_lib",
97+
":sas_expr_parser_lib",
9898
]
9999
)
100100

util/SafeArmadillo.h

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#define _Che_SafeArmadillo_H
2929

3030
#define ARMA_USE_SUPERLU
31+
#define ARMA_USE_LAPACK
3132
#define ARMA_DONT_USE_WRAPPER
3233
#include <armadillo>
3334

0 commit comments

Comments
 (0)