Skip to content

Commit a1df7b8

Browse files
authored
Merge pull request #495 from SCOREC/yus/update_python_wrapper
Update python wrappers
2 parents 0250bc3 + f0c2b20 commit a1df7b8

File tree

6 files changed

+268
-18
lines changed

6 files changed

+268
-18
lines changed
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
name: Build and Test PUMI Python Interface
2+
3+
on:
4+
push:
5+
branches: [develop]
6+
pull_request:
7+
branches: [develop]
8+
9+
jobs:
10+
build-and-test:
11+
runs-on: ubuntu-latest
12+
13+
env:
14+
PYTHONPATH: ${{ github.workspace }}/build/python_wrappers
15+
LD_LIBRARY_PATH: ${{ github.workspace }}/libs/install/lib:${LD_LIBRARY_PATH}
16+
17+
steps:
18+
- name: Checkout repository
19+
uses: actions/checkout@v3
20+
21+
- name: Install dependencies
22+
run: |
23+
sudo apt-get update
24+
sudo apt-get install -y cmake mpich build-essential libbz2-dev
25+
pip3 install mpi4py
26+
27+
- name: Build SWIG
28+
run: |
29+
git clone https://github.com/swig/swig.git
30+
cd swig
31+
./autogen.sh
32+
./configure --prefix=${{ github.workspace }}/libs/install
33+
make
34+
make install
35+
36+
- name: Build GKlib
37+
run: |
38+
git clone https://github.com/KarypisLab/GKlib.git
39+
cd GKlib
40+
make config prefix=${{ github.workspace }}/libs/install
41+
make install
42+
43+
- name: Build METIS
44+
run: |
45+
git clone https://github.com/KarypisLab/METIS.git
46+
cd METIS
47+
make config prefix=${{ github.workspace }}/libs/install
48+
make install
49+
50+
- name: Build ParMETIS
51+
run: |
52+
git clone https://github.com/KarypisLab/ParMETIS.git
53+
cd ParMETIS
54+
make config prefix=${{ github.workspace }}/libs/install
55+
make install
56+
57+
- name: Build Zoltan from Trilinos (minimal)
58+
run: |
59+
git clone https://github.com/trilinos/Trilinos.git
60+
mkdir build-zoltan
61+
cd build-zoltan
62+
cmake ../Trilinos \
63+
-DCMAKE_INSTALL_PREFIX=${{ github.workspace }}/libs/install \
64+
-DTPL_ENABLE_MPI:BOOL=ON \
65+
-DCMAKE_C_FLAGS="-O3 -fPIC" \
66+
-DCMAKE_CXX_FLAGS="-O3 -fPIC" \
67+
-DTrilinos_ENABLE_ALL_PACKAGES:BOOL=OFF \
68+
-DTrilinos_ENABLE_Zoltan:BOOL=ON \
69+
-DZoltan_ENABLE_EXAMPLES:BOOL=OFF \
70+
-DZoltan_ENABLE_TESTS:BOOL=OFF \
71+
-DZoltan_ENABLE_ParMETIS:BOOL=ON \
72+
-DParMETIS_INCLUDE_DIRS=${{ github.workspace }}/libs/install \
73+
-DParMETIS_LIBRARY_DIRS=${{ github.workspace }}/libs/install
74+
make
75+
make install
76+
77+
- name: Configure PUMI
78+
run: |
79+
cmake -S . -B build \
80+
-DCMAKE_INSTALL_PREFIX=${{ github.workspace }}/build/install \
81+
-DCMAKE_C_COMPILER=mpicc \
82+
-DCMAKE_CXX_COMPILER=mpicxx \
83+
-DSCOREC_CXX_OPTIMIZE=ON \
84+
-DMDS_ID_TYPE=int \
85+
-DPCU_COMPRESS=ON \
86+
-DENABLE_ZOLTAN=ON \
87+
-DZOLTAN_PREFIX=${{ github.workspace }}/libs/install \
88+
-DPUMI_PYTHON_INTERFACE=ON \
89+
-DBUILD_SHARED_LIBS=ON \
90+
-DBUILD_EXES=OFF \
91+
-DIS_TESTING=OFF \
92+
-DENABLE_OMEGA_H=OFF \
93+
-DPARMETIS_PREFIX=${{ github.workspace }}/libs/install \
94+
-DENABLE_SIMMETRIX=OFF
95+
96+
- name: Build and install
97+
run: |
98+
cmake --build build -j 4 --target install
99+
100+
- name: Run Python test
101+
working-directory: ${{github.workspace}}/python_wrappers
102+
run: |
103+
python3 test_pyCore.py -g input/cube.dmg -m input/cube.smb

pcu/PCU.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,15 @@ class PCU {
117117
int Received(size_t *size) noexcept;
118118
void *Extract(size_t size) noexcept;
119119

120+
/*
121+
* Debug print function with printf-style formatting
122+
* This function is excluded from SWIG parsing due to complex macro usage
123+
* with variadic argument. Also, such functionalities is not needed for the Python API.
124+
*/
125+
#ifndef SWIG
120126
void DebugPrint(const char* format, ...) noexcept PCU_FORMAT_ATTRIBUTE(2, 3)
121127
void DebugPrint(const char* format, va_list args) noexcept;
128+
#endif // SWIG
122129
/* Debug functions */
123130
void DebugOpen() noexcept;
124131

@@ -148,7 +155,12 @@ void Init(int *argc, char ***argv);
148155
*/
149156
void Finalize();
150157

151-
/* explicit instantiations of template functions */
158+
/*
159+
* Explicit instantiations of template functions,
160+
* ignored by SWIG to avoid difficulties when parsing macros involving
161+
* template functions. Templates are initialized manually in the interface file.
162+
*/
163+
#ifndef SWIG
152164
#define PCU_EXPL_INST_DECL(T) \
153165
extern template void PCU::Add<T>(T * p, size_t n) noexcept; \
154166
extern template T PCU::Add<T>(T p) noexcept; \
@@ -165,6 +177,7 @@ PCU_EXPL_INST_DECL(size_t)
165177
PCU_EXPL_INST_DECL(long)
166178
PCU_EXPL_INST_DECL(double)
167179
#undef PCU_EXPL_INST_DECL
180+
#endif // SWIG
168181

169182
} // namespace pcu
170183

python_wrappers/apf.i

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
%{
33
#include <mpi.h>
44
#include <vector>
5+
#include <pcu_defines.h>
6+
#include <PCU.h>
57
#include <PCU_C.h>
68
#include <pcu_util.h>
79
#include <gmi.h>
@@ -40,14 +42,35 @@
4042

4143
/* PCU RELATED WRAPPERS */
4244
/* ==== FROM PCU.h ====*/
43-
MPI_Comm PCU_Get_Comm(void);
44-
int PCU_Comm_Init(void);
45-
int PCU_Comm_Free(void);
45+
int PCU_Comm_Init(PCU_t* h);
46+
int PCU_Comm_Free(PCU_t* h);
4647

47-
int PCU_Comm_Self(void);
48-
int PCU_Comm_Peers(void);
48+
int PCU_Comm_Self(PCU_t h);
49+
int PCU_Comm_Peers(PCU_t h);
4950
double PCU_Time(void);
50-
bool PCU_Comm_Initialized(void);
51+
bool PCU_Comm_Initialized(PCU_t h);
52+
%include<pcu_defines.h>
53+
%include<PCU.h>
54+
%template(Add_int) pcu::PCU::Add<int>;
55+
%template(Min_int) pcu::PCU::Min<int>;
56+
%template(Max_int) pcu::PCU::Max<int>;
57+
%template(Exscan_int) pcu::PCU::Exscan<int>;
58+
%template(ALLgather_int) pcu::PCU::Allgather<int>;
59+
%template(Add_size_t) pcu::PCU::Add<size_t>;
60+
%template(Min_size_t) pcu::PCU::Min<size_t>;
61+
%template(Max_size_t) pcu::PCU::Max<size_t>;
62+
%template(Exscan_size_t) pcu::PCU::Exscan<size_t>;
63+
%template(ALLgather_size_t) pcu::PCU::Allgather<size_t>;
64+
%template(Add_long) pcu::PCU::Add<long>;
65+
%template(Min_long) pcu::PCU::Min<long>;
66+
%template(Max_long) pcu::PCU::Max<long>;
67+
%template(Exscan_long) pcu::PCU::Exscan<long>;
68+
%template(ALLgather_long) pcu::PCU::Allgather<long>;
69+
%template(Add_double) pcu::PCU::Add<double>;
70+
%template(Min_double) pcu::PCU::Min<double>;
71+
%template(Max_double) pcu::PCU::Max<double>;
72+
%template(Exscan_double) pcu::PCU::Exscan<double>;
73+
%template(ALLgather_double) pcu::PCU::Allgather<double>;
5174

5275
/* ==== FROM pcu_util.h ====*/
5376
void PCU_Assert_Fail(const char* msg);
@@ -221,7 +244,7 @@ void lion_set_verbosity(int lvl);
221244
local_min = val;
222245
}
223246
self->end(it);
224-
PCU_Min_Doubles(&local_min, 1);
247+
self->getPCU()->Min(&local_min, 1);
225248
return local_min;
226249
}
227250
double getMaxOfScalarField(apf::Field* field)
@@ -238,7 +261,7 @@ void lion_set_verbosity(int lvl);
238261
local_max = val;
239262
}
240263
self->end(it);
241-
PCU_Max_Doubles(&local_max, 1);
264+
self->getPCU()->Max(&local_max, 1);
242265
return local_max;
243266
}
244267
bool isBoundingModelRegion(int rtag, int dim, int tag)
@@ -262,16 +285,17 @@ void lion_set_verbosity(int lvl);
262285

263286
#define __attribute__(x)
264287
%ignore apf::fail;
288+
%ignore apf::writeCGNS;
265289
%include<apf.h>
266290
%include<apfNumbering.h>
267291
%include<apfShape.h>
268292

269293

270294

271295
namespace apf {
272-
apf::Mesh2* makeEmptyMdsMesh(gmi_model* model, int dim, bool isMatched);
273-
apf::Mesh2* loadMdsMesh(const char* modelfile, const char* meshfile);
274-
apf::Mesh2* loadMdsMesh(gmi_model* model, const char* meshfile);
296+
apf::Mesh2* makeEmptyMdsMesh(gmi_model* model, int dim, bool isMatched, pcu::PCU *PCUObj);
297+
apf::Mesh2* loadMdsMesh(const char* modelfile, const char* meshfile, pcu::PCU *PCUObj);
298+
apf::Mesh2* loadMdsMesh(gmi_model* model, const char* meshfile, pcu::PCU *PCUObj);
275299
void writeASCIIVtkFiles(const char* prefix, apf::Mesh2* m);
276300
/* void writeVtkFiles(const char* prefix, apf::Mesh* m, int cellDim = -1); */
277301
/* void writeVtkFiles(const char* prefix, apf::Mesh* m, */

python_wrappers/input/sphere.smd

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
smi 5 0
2+
<part> smd 33
3+
simple 33 1
4+
*
5+
-1
6+
-0.00050000000000000001 -0.00050000000000000001 -0.00050000000000000001
7+
0.00050000000000000001 0.00050000000000000001 0.00029999999999999997
8+
1 1007 9 0
9+
0 0 0 0
10+
-0.00050000000000000001 -0.00050000000000000001 -0.00050000000000000001
11+
0.00050000000000000001 0.00050000000000000001 0.00029999999999999997
12+
_sim_empty
13+
-1
14+
0 0 0 0
15+
16+
0
17+
1 2 1 0
18+
0 0 0 0
19+
0 0 0 0
20+
0 0 0 0
21+
2
22+
1 5 65 -1 -1
23+
2 5 65 -1 -1
24+
65 1 9 0 210 0 2 -1 -1
25+
1 2
26+
_sim_empty
27+
-1
28+
1 3.1415926535897931 -0.00040000000000000002 4.8985871965894131e-20 0.00029999999999999997
29+
1e-08
30+
1 3
31+
0 6.2831853071795862
32+
0 0 0.00029999999999999997
33+
0.00040000000000000002 6.2831853071795862
34+
0 0 1
35+
1 0 0
36+
1 6 11 1 0 2
37+
1 65 1 0 2 6 11 0 0 1
38+
1 65 2 1 11 2 9 0 203 0
39+
1 1
40+
0
41+
42+
1 2
43+
0
44+
45+
0
46+
_sim_empty
47+
-1
48+
0 0 0 0 0 0
49+
0
50+
1 3
51+
0 0 0
52+
0 1 0
53+
1 -0 0
54+
0 0 -1
55+
0.00050000000000000001 0 0 6.2831853071795862
56+
3 6 100 1 0 4
57+
1 65 1 1 4 6 100 0 0 3
58+
1 65 2 0 100 2 9 0 203 0
59+
1 3
60+
0
61+
62+
1 4
63+
0
64+
65+
0
66+
_sim_empty
67+
-1
68+
0 0 0 0 0 0
69+
0
70+
1 0
71+
0 0 0.00029999999999999997
72+
1 0 0
73+
0 1 0
74+
1 1 1
75+
1 8 1 2
76+
11 0 100 0 1 3 9 0 205 0 1
77+
1
78+
0
79+
0
80+
_sim_empty
81+
-1
82+
0 -1
83+
3 8 2 2
84+
11 1 100 1 2 3 8 0 303 0 1
85+
3
86+
0
87+
0
88+
_sim_empty
89+
-1
90+
0
91+
0 -1
92+
0 -1
93+
0 -1
94+
0 -1
95+
0 -1
96+
<part> auxmm 3
97+
0
98+
0
99+
<index>
100+
2
101+
smd 8
102+
auxmm 1160
103+
</index>
104+
<header>
105+
4
106+
71 file:///lore/yus9/scorec_software/core/python_wrappers/input/sphere.smd24 model.nonmanifold.simple6 # 1 0 0
107+
0
108+
0
109+
</header>
110+
1179 1215

python_wrappers/test_pyCore.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ def main(argv):
2323
print('Mesh file is "', mesh)
2424

2525
# PCU initialization
26-
pyCore.PCU_Comm_Init()
26+
PCUObj = pyCore.PCU(MPI.COMM_WORLD)
2727

2828
# gmi initialization
2929
pyCore.gmi_register_mesh()
3030

3131
# load the mesh and model and write the initial mesh to vtk
32-
mesh = pyCore.loadMdsMesh(model, mesh)
32+
mesh = pyCore.loadMdsMesh(model, mesh, PCUObj)
3333
pyCore.writeASCIIVtkFiles('before', mesh);
3434

3535
# setup uniform refiner and call mesh adapt
@@ -40,7 +40,7 @@ def main(argv):
4040
pyCore.writeASCIIVtkFiles('after', mesh);
4141

4242
# gmi finalization
43-
pyCore.PCU_Comm_Free()
43+
del PCUObj
4444

4545
if __name__ == "__main__":
4646
main(sys.argv[1:])

python_wrappers/test_pyCore_with_simx.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def main(argv):
2525
pyCore.lion_set_verbosity(1)
2626

2727
# PCU initialization
28-
pyCore.PCU_Comm_Init()
28+
PCUObj = pyCore.PCU(MPI.COMM_WORLD)
2929

3030
# SIMX initialization
3131
pyCore.start_sim('simlog.txt')
@@ -38,7 +38,7 @@ def main(argv):
3838
pyCore.gmi_register_sim()
3939

4040
# load the mesh and model and write the initial mesh to vtk
41-
mesh = pyCore.loadMdsMesh(model, mesh)
41+
mesh = pyCore.loadMdsMesh(model, mesh, PCUObj)
4242
print("num verts in the mesh is ", mesh.count(0))
4343

4444
it = mesh.begin(0)
@@ -85,7 +85,7 @@ def main(argv):
8585
pyCore.stop_sim()
8686

8787
# gmi finalization
88-
pyCore.PCU_Comm_Free()
88+
del PCUObj
8989

9090
if __name__ == "__main__":
9191
main(sys.argv[1:])

0 commit comments

Comments
 (0)