Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions test/partitioner/external_tools/3rd-party/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
set(3RD_PARTY_DIR ${CMAKE_CURRENT_SOURCE_DIR})

set(KAHIP_LIB "${CMAKE_INSTALL_PREFIX}/lib/libkahip.a")

add_custom_command(
OUTPUT ${KAHIP_LIB}
COMMAND ${CMAKE_COMMAND} -E echo "Building KaHIP."
COMMAND ${CMAKE_COMMAND} -E tar xvzf ${3RD_PARTY_DIR}/KaHIP/KaHIP-3.16.tar.gz
COMMAND cd ${CMAKE_CURRENT_BINARY_DIR}/KaHIP-3.16 && ./compile_withcmake.sh
COMMAND ${CMAKE_COMMAND} -E echo "Installing KaHIP."
COMMAND ${CMAKE_COMMAND} -E rm -rf ${3RD_PARTY_DIR}/KaHIP/deploy
COMMAND mv ${CMAKE_CURRENT_BINARY_DIR}/KaHIP-3.16/deploy ${3RD_PARTY_DIR}/KaHIP/

COMMAND ${CMAKE_COMMAND} -E echo "Installing SBG Library."
COMMAND ${CMAKE_COMMAND} -E rm -rf ${3RD_PARTY_DIR}/sbg
COMMAND mkdir -p ${3RD_PARTY_DIR}/sbg
COMMAND cp ${CMAKE_CURRENT_SOURCE_DIR}/../../../../install/lib/* ${3RD_PARTY_DIR}/sbg
)

add_custom_target(
3rd-party-libs
DEPENDS ${KAHIP_LIB}
)

add_dependencies(graph-partitioner 3rd-party-libs)
Binary file not shown.
65 changes: 65 additions & 0 deletions test/partitioner/external_tools/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
cmake_minimum_required(VERSION 3.16)

project(ExtPartitioners)

set(CMAKE_INSTALL_PREFIX ${PROJECT_SOURCE_DIR}/install)

# Set default build type to Debug if not specified
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug CACHE STRING "Build type" FORCE)
endif()

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# Add libraries
add_library(graph-partitioner STATIC)

set_target_properties(graph-partitioner PROPERTIES DEBUG_POSTFIX "d")

target_include_directories(graph-partitioner PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

target_include_directories(graph-partitioner PRIVATE 3rd-party/KaHIP/deploy ${PROJECT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/../../../)

target_sources(
graph-partitioner
PRIVATE
graph_partitioner.cpp
)


# Source files.
add_subdirectory(3rd-party)

# Add executable
add_executable(
graph_partitioner
)

target_sources(
graph_partitioner
PRIVATE
main.cpp
)

target_link_directories(graph_partitioner PRIVATE 3rd-party/KaHIP/deploy 3rd-party/sbg)

target_link_libraries(
graph_partitioner
PRIVATE
graph-partitioner
metis
scotch
scotcherr
kahip.a
sbg-part-lib
sbg-util-lib
sbg-dev
)

# install
install(
TARGETS graph_partitioner
RUNTIME DESTINATION bin
COMPONENT graph_partitioner
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
model adv_dif_reac
constant Integer N=1000;
parameter Real a=1;
parameter Real d=1e-4;
parameter Real r=10;
parameter Real L=10;
parameter Real dx=L/N;
Real u[N];

initial algorithm
for i in 1:N/3 loop
u[i]:=1;
end for;

equation
der(u[1])=-a*(u[1]-1)/dx+d*(-2*u[1]+1)/(dx^2)+r*(u[1]^2)*(1-u[1]);
for i in 2:N loop
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]);
end for;
annotation(

experiment(
MMO_Description=" Advection",
MMO_Solver=LIQSS2,
MMO_Parallel=true,
MMO_PartitionMethod=Metis,
MMO_LPS=2,
MMO_DT_Min= 2,
MMO_Output={u[N]},
Jacobian=Dense,
MMO_BDF_PDepth=1,
MMO_BDF_Max_Step= 0,
StartTime= 0.0,
StopTime=10,
Tolerance={1e-3},
AbsTolerance={1e-3}
));
end adv_dif_reac;
122 changes: 122 additions & 0 deletions test/partitioner/external_tools/experiments/airconds/airconds.mo
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
model airconds
import math;
constant Integer N = 10000;
parameter Real CAP[N], RES[N], POT[N], THA = 32,pmax=0;
Real th[N];
discrete Real on[N];
discrete Real tref[N];
discrete Real nextSample[N];
discrete Real noise[N];
discrete Real nextTref[N];

initial algorithm
for i in 1:N loop
th[i] := rand(4)+ 18;
CAP[i] := rand(100)+ 550;
RES[i] := rand(0.4)+ 1.8;
POT[i] := rand(2)+ 13;
pmax:=pmax+POT[i];
nextSample[i] := 1;
noise[i] := rand(2)-1;
tref[i] := 20;
nextTref[i] := 1000;
end for;
for i in 1:N loop
if th[i] - tref[i] - 0.5 > 0 then
on[i] := 1;
end if;
end for;

equation
for i in 1:N loop
der(th[i]) = (THA/RES[i]-POT[i]*on[i]-th[i]/RES[i]+noise[i]/RES[i])/CAP[i];
end for;

algorithm
for i in 1:N loop
when th[i] - tref[i] + on[i] - 0.5 > 0 then
on[i] := 1;
elsewhen th[i] - tref[i] + on[i] - 0.5 < 0 then
on[i] := 0;
end when;
end for;
for i in 1:N loop
when time > nextTref[i] then
if (nextTref[i] == 1000) then
tref[i] := 20.5;
else
tref[i] := 20;
end if;
nextTref[i] := 2000;
end when;
end for;
for i in 1:N loop
when time > nextSample[i] then
nextSample[i] := nextSample[i]+1;
noise[i] := 2*abs(sin(i*time))-1;
end when;
end for;
annotation(
experiment(
MMO_Description = "Power consumption in a large population of air conditioners.",
MMO_Solver = QSS2,
MMO_Period = {3000/5000},
MMO_Parallel = true,
MMO_PartitionMethod = Scotch,
MMO_LPS = 4,
MMO_DT_Synch = SD_DT_Fixed,
MMO_DT_Min = 3000,
MMO_Output = {th[1]},
MMO_OutputType = CI_Sampled,
Jacobian = Dense,
MMO_BDF_PDepth = 1,
MMO_BDF_Max_Step = 0,
StartTime = 0,
StopTime = 3000,
Tolerance = {1e-3},
AbsTolerance = {1e-3}
)
);










































end airconds;
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Airconds and Advection examples to get partition results using classic partitioners.

# General configuration to access qss-sover methods (the solver needs to be installed first).
# libconf is needded as an external dep, run: `pip install libconf` first.`

import argparse
import os
import sys

MMOC_SRC = os.environ['MMOC_SRC']
MMOC_OUTPUT = os.environ['MMOC_OUTPUT']
sys.path.append(MMOC_SRC+'/python')
sys.path.append(MMOC_SRC+'/python/qss_solver')

import qss_solver
import qss_solver.results as solver_results
import qss_solver.model as solver_model
import qss_solver.simulate as solver_sim

def run_experiments(path, model_name):
# Model constants size.
model_size = [1000, 10000, 100000, 1000000, 10000000]

# Partitioners
model_partitioners = ['Metis', 'Scotch']
print(path)

model_full_path = path+'/'+model_name+'.mo'

for s in model_size:
for p in model_partitioners:
# The parameter should be the full path name if not stored in the solver default folders.
model_constant = solver_model.constants(model_full_path)
model_constant['N'] = s

solver_model.set_constants(model_full_path, model_constant)
model_annotations = solver_model.annotations(model_full_path)
model_annotations['MMO_PartitionMethod'] = p
# Store the number of LPS (partitions) we are using.
lps = model_annotations['MMO_LPS']
solver_model.set_annotations(model_full_path, model_annotations)

# Compile the model to generate the excecutabe ini file.
solver_sim.compile_model(model_full_path)

# Now update the ini file to set the 'partitionOnly' flag to avoid running the simulation.
model_config = solver_model.config(model_name)
model_config['partitionOnly'] = 1
solver_model.set_config(model_name, model_config)

# Now go ahead and execute the model.
solver_sim.execute_model(model_full_path)

# Finally, get the partitioner stats into a dict.
# Full size of the advection model.
model_full_size = s
if model_name == 'airconds':
# Update full size for airconds model.
model_full_size = s*4
partitioner_log_file = model_name+'-'+str(model_full_size)+'-'+lps+'-partition-stats.log'
partition_log = solver_results.simulation_log(MMOC_OUTPUT+'/'+model_name+'/'+partitioner_log_file)
print('Partition method: '+ p)
print('Model size: ' + str(s))
print('Results')
print(partition_log)


# Example usage: python3 ./airconds_experimets.py /home/joaquin/work/sbg-partitioner/src/external_tools/experiments/airconds airconds

def main():
parser = argparse.ArgumentParser(description='Run experiments for classic partitioners.')
parser.add_argument('path', type=str, help='Full path to the folder where the airconds model .mo file is located.')
parser.add_argument('model_name', type=str, help='Model name whitout .mo extension. It should be one of \'advection\' or \'airconds\'')

args = parser.parse_args()

run_experiments(args.path, args.model_name)

if __name__ == '__main__':
main()
Loading