Skip to content

Commit c3a7930

Browse files
Port external tools from sbg partitioner. (#122)
* Port external tools from sbg partitioner. * generate graph from sbg input --------- Co-authored-by: Franco Sansone <sansone@cifasis-conicet.gov.ar>
1 parent 6713869 commit c3a7930

13 files changed

Lines changed: 1422 additions & 0 deletions

File tree

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
set(3RD_PARTY_DIR ${CMAKE_CURRENT_SOURCE_DIR})
2+
3+
set(KAHIP_LIB "${CMAKE_INSTALL_PREFIX}/lib/libkahip.a")
4+
5+
add_custom_command(
6+
OUTPUT ${KAHIP_LIB}
7+
COMMAND ${CMAKE_COMMAND} -E echo "Building KaHIP."
8+
COMMAND ${CMAKE_COMMAND} -E tar xvzf ${3RD_PARTY_DIR}/KaHIP/KaHIP-3.16.tar.gz
9+
COMMAND cd ${CMAKE_CURRENT_BINARY_DIR}/KaHIP-3.16 && ./compile_withcmake.sh
10+
COMMAND ${CMAKE_COMMAND} -E echo "Installing KaHIP."
11+
COMMAND ${CMAKE_COMMAND} -E rm -rf ${3RD_PARTY_DIR}/KaHIP/deploy
12+
COMMAND mv ${CMAKE_CURRENT_BINARY_DIR}/KaHIP-3.16/deploy ${3RD_PARTY_DIR}/KaHIP/
13+
14+
COMMAND ${CMAKE_COMMAND} -E echo "Installing SBG Library."
15+
COMMAND ${CMAKE_COMMAND} -E rm -rf ${3RD_PARTY_DIR}/sbg
16+
COMMAND mkdir -p ${3RD_PARTY_DIR}/sbg
17+
COMMAND cp ${CMAKE_CURRENT_SOURCE_DIR}/../../../../install/lib/* ${3RD_PARTY_DIR}/sbg
18+
)
19+
20+
add_custom_target(
21+
3rd-party-libs
22+
DEPENDS ${KAHIP_LIB}
23+
)
24+
25+
add_dependencies(graph-partitioner 3rd-party-libs)
Binary file not shown.
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
cmake_minimum_required(VERSION 3.16)
2+
3+
project(ExtPartitioners)
4+
5+
set(CMAKE_INSTALL_PREFIX ${PROJECT_SOURCE_DIR}/install)
6+
7+
# Set default build type to Debug if not specified
8+
if(NOT CMAKE_BUILD_TYPE)
9+
set(CMAKE_BUILD_TYPE Debug CACHE STRING "Build type" FORCE)
10+
endif()
11+
12+
set(CMAKE_CXX_STANDARD 17)
13+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
14+
15+
# Add libraries
16+
add_library(graph-partitioner STATIC)
17+
18+
set_target_properties(graph-partitioner PROPERTIES DEBUG_POSTFIX "d")
19+
20+
target_include_directories(graph-partitioner PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
21+
22+
target_include_directories(graph-partitioner PRIVATE 3rd-party/KaHIP/deploy ${PROJECT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/../../../)
23+
24+
target_sources(
25+
graph-partitioner
26+
PRIVATE
27+
graph_partitioner.cpp
28+
)
29+
30+
31+
# Source files.
32+
add_subdirectory(3rd-party)
33+
34+
# Add executable
35+
add_executable(
36+
graph_partitioner
37+
)
38+
39+
target_sources(
40+
graph_partitioner
41+
PRIVATE
42+
main.cpp
43+
)
44+
45+
target_link_directories(graph_partitioner PRIVATE 3rd-party/KaHIP/deploy 3rd-party/sbg)
46+
47+
target_link_libraries(
48+
graph_partitioner
49+
PRIVATE
50+
graph-partitioner
51+
metis
52+
scotch
53+
scotcherr
54+
kahip.a
55+
sbg-part-lib
56+
sbg-util-lib
57+
sbg-dev
58+
)
59+
60+
# install
61+
install(
62+
TARGETS graph_partitioner
63+
RUNTIME DESTINATION bin
64+
COMPONENT graph_partitioner
65+
)
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
model adv_dif_reac
2+
constant Integer N=1000;
3+
parameter Real a=1;
4+
parameter Real d=1e-4;
5+
parameter Real r=10;
6+
parameter Real L=10;
7+
parameter Real dx=L/N;
8+
Real u[N];
9+
10+
initial algorithm
11+
for i in 1:N/3 loop
12+
u[i]:=1;
13+
end for;
14+
15+
equation
16+
der(u[1])=-a*(u[1]-1)/dx+d*(-2*u[1]+1)/(dx^2)+r*(u[1]^2)*(1-u[1]);
17+
for i in 2:N loop
18+
der(u[i])=-a*(u[i]-u[i-1])/dx+ d*(-2*u[i]+u[i-1])/(dx^2)+ r*(u[i]^2)*(1-u[i]);
19+
end for;
20+
annotation(
21+
22+
experiment(
23+
MMO_Description=" Advection",
24+
MMO_Solver=LIQSS2,
25+
MMO_Parallel=true,
26+
MMO_PartitionMethod=Metis,
27+
MMO_LPS=2,
28+
MMO_DT_Min= 2,
29+
MMO_Output={u[N]},
30+
Jacobian=Dense,
31+
MMO_BDF_PDepth=1,
32+
MMO_BDF_Max_Step= 0,
33+
StartTime= 0.0,
34+
StopTime=10,
35+
Tolerance={1e-3},
36+
AbsTolerance={1e-3}
37+
));
38+
end adv_dif_reac;
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
model airconds
2+
import math;
3+
constant Integer N = 10000;
4+
parameter Real CAP[N], RES[N], POT[N], THA = 32,pmax=0;
5+
Real th[N];
6+
discrete Real on[N];
7+
discrete Real tref[N];
8+
discrete Real nextSample[N];
9+
discrete Real noise[N];
10+
discrete Real nextTref[N];
11+
12+
initial algorithm
13+
for i in 1:N loop
14+
th[i] := rand(4)+ 18;
15+
CAP[i] := rand(100)+ 550;
16+
RES[i] := rand(0.4)+ 1.8;
17+
POT[i] := rand(2)+ 13;
18+
pmax:=pmax+POT[i];
19+
nextSample[i] := 1;
20+
noise[i] := rand(2)-1;
21+
tref[i] := 20;
22+
nextTref[i] := 1000;
23+
end for;
24+
for i in 1:N loop
25+
if th[i] - tref[i] - 0.5 > 0 then
26+
on[i] := 1;
27+
end if;
28+
end for;
29+
30+
equation
31+
for i in 1:N loop
32+
der(th[i]) = (THA/RES[i]-POT[i]*on[i]-th[i]/RES[i]+noise[i]/RES[i])/CAP[i];
33+
end for;
34+
35+
algorithm
36+
for i in 1:N loop
37+
when th[i] - tref[i] + on[i] - 0.5 > 0 then
38+
on[i] := 1;
39+
elsewhen th[i] - tref[i] + on[i] - 0.5 < 0 then
40+
on[i] := 0;
41+
end when;
42+
end for;
43+
for i in 1:N loop
44+
when time > nextTref[i] then
45+
if (nextTref[i] == 1000) then
46+
tref[i] := 20.5;
47+
else
48+
tref[i] := 20;
49+
end if;
50+
nextTref[i] := 2000;
51+
end when;
52+
end for;
53+
for i in 1:N loop
54+
when time > nextSample[i] then
55+
nextSample[i] := nextSample[i]+1;
56+
noise[i] := 2*abs(sin(i*time))-1;
57+
end when;
58+
end for;
59+
annotation(
60+
experiment(
61+
MMO_Description = "Power consumption in a large population of air conditioners.",
62+
MMO_Solver = QSS2,
63+
MMO_Period = {3000/5000},
64+
MMO_Parallel = true,
65+
MMO_PartitionMethod = Scotch,
66+
MMO_LPS = 4,
67+
MMO_DT_Synch = SD_DT_Fixed,
68+
MMO_DT_Min = 3000,
69+
MMO_Output = {th[1]},
70+
MMO_OutputType = CI_Sampled,
71+
Jacobian = Dense,
72+
MMO_BDF_PDepth = 1,
73+
MMO_BDF_Max_Step = 0,
74+
StartTime = 0,
75+
StopTime = 3000,
76+
Tolerance = {1e-3},
77+
AbsTolerance = {1e-3}
78+
)
79+
);
80+
81+
82+
83+
84+
85+
86+
87+
88+
89+
90+
91+
92+
93+
94+
95+
96+
97+
98+
99+
100+
101+
102+
103+
104+
105+
106+
107+
108+
109+
110+
111+
112+
113+
114+
115+
116+
117+
118+
119+
120+
121+
122+
end airconds;
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# Airconds and Advection examples to get partition results using classic partitioners.
2+
3+
# General configuration to access qss-sover methods (the solver needs to be installed first).
4+
# libconf is needded as an external dep, run: `pip install libconf` first.`
5+
6+
import argparse
7+
import os
8+
import sys
9+
10+
MMOC_SRC = os.environ['MMOC_SRC']
11+
MMOC_OUTPUT = os.environ['MMOC_OUTPUT']
12+
sys.path.append(MMOC_SRC+'/python')
13+
sys.path.append(MMOC_SRC+'/python/qss_solver')
14+
15+
import qss_solver
16+
import qss_solver.results as solver_results
17+
import qss_solver.model as solver_model
18+
import qss_solver.simulate as solver_sim
19+
20+
def run_experiments(path, model_name):
21+
# Model constants size.
22+
model_size = [1000, 10000, 100000, 1000000, 10000000]
23+
24+
# Partitioners
25+
model_partitioners = ['Metis', 'Scotch']
26+
print(path)
27+
28+
model_full_path = path+'/'+model_name+'.mo'
29+
30+
for s in model_size:
31+
for p in model_partitioners:
32+
# The parameter should be the full path name if not stored in the solver default folders.
33+
model_constant = solver_model.constants(model_full_path)
34+
model_constant['N'] = s
35+
36+
solver_model.set_constants(model_full_path, model_constant)
37+
model_annotations = solver_model.annotations(model_full_path)
38+
model_annotations['MMO_PartitionMethod'] = p
39+
# Store the number of LPS (partitions) we are using.
40+
lps = model_annotations['MMO_LPS']
41+
solver_model.set_annotations(model_full_path, model_annotations)
42+
43+
# Compile the model to generate the excecutabe ini file.
44+
solver_sim.compile_model(model_full_path)
45+
46+
# Now update the ini file to set the 'partitionOnly' flag to avoid running the simulation.
47+
model_config = solver_model.config(model_name)
48+
model_config['partitionOnly'] = 1
49+
solver_model.set_config(model_name, model_config)
50+
51+
# Now go ahead and execute the model.
52+
solver_sim.execute_model(model_full_path)
53+
54+
# Finally, get the partitioner stats into a dict.
55+
# Full size of the advection model.
56+
model_full_size = s
57+
if model_name == 'airconds':
58+
# Update full size for airconds model.
59+
model_full_size = s*4
60+
partitioner_log_file = model_name+'-'+str(model_full_size)+'-'+lps+'-partition-stats.log'
61+
partition_log = solver_results.simulation_log(MMOC_OUTPUT+'/'+model_name+'/'+partitioner_log_file)
62+
print('Partition method: '+ p)
63+
print('Model size: ' + str(s))
64+
print('Results')
65+
print(partition_log)
66+
67+
68+
# Example usage: python3 ./airconds_experimets.py /home/joaquin/work/sbg-partitioner/src/external_tools/experiments/airconds airconds
69+
70+
def main():
71+
parser = argparse.ArgumentParser(description='Run experiments for classic partitioners.')
72+
parser.add_argument('path', type=str, help='Full path to the folder where the airconds model .mo file is located.')
73+
parser.add_argument('model_name', type=str, help='Model name whitout .mo extension. It should be one of \'advection\' or \'airconds\'')
74+
75+
args = parser.parse_args()
76+
77+
run_experiments(args.path, args.model_name)
78+
79+
if __name__ == '__main__':
80+
main()

0 commit comments

Comments
 (0)