Skip to content

Commit 5480514

Browse files
committed
final changes to model implementations
1 parent 61004f0 commit 5480514

4 files changed

Lines changed: 61 additions & 54 deletions

File tree

test/partitioner/external_tools/graph_partitioner.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,8 @@ std::tuple<Partition, std::chrono::duration<double>> GraphPartitioner::createPar
162162
auto end = std::chrono::high_resolution_clock::now();
163163
std::chrono::duration<double> duration = end - start;
164164

165-
std::cout << "Partition Time: " << duration.count() << " seconds." << std::endl;
165+
std::cout << "Partition Time: " << std::chrono::duration_cast<std::chrono::milliseconds>(duration).count() << " miliseconds."
166+
<< std::endl;
166167

167168
if (save_to_file) {
168169
const std::string fileName =
@@ -517,13 +518,13 @@ void GraphPartitioner::readGraphFromSBG()
517518
_edges = grp_t(_adjncy.size());
518519

519520
// @todo: Add logging, for the moment just comment the code.
520-
for (int i = 0; i < _nbr_vtxs; ++i) {
521+
/*for (int i = 0; i < _nbr_vtxs; ++i) {
521522
std::cout << "Node " << i << " Connections: ";
522523
for (int j = _xadj[i]; j < _xadj[i + 1]; ++j) {
523524
std::cout << _adjncy[j] << " ";
524525
}
525526
std::cout << std::endl;
526-
}
527+
}*/
527528

528529
// @todo: Read weights files.
529530
_vwgt.resize(_nbr_vtxs, 1);

test/partitioner/sim_models/advection_2D/advection2D.mo

Lines changed: 6 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,19 @@ model advection2D
3838
end for;
3939
annotation(
4040
experiment(
41-
MMO_Description = "Advection",
42-
MMO_Solver = QSS3,
41+
MMO_Description = " Advection",
42+
MMO_Solver = LIQSS2,
43+
MMO_Parallel = true,
4344
MMO_PartitionMethod = Manual,
45+
MMO_LPS = 12,
4446
MMO_DT_Min = 1,
4547
Jacobian = Dense,
4648
MMO_BDF_PDepth = 1,
4749
MMO_BDF_Max_Step = 0,
4850
StartTime = 0.0,
49-
StopTime = 10,
51+
StopTime = 300,
5052
Tolerance = {1e-3},
51-
AbsTolerance = {1e-3},
52-
MMO_LPS = 8,
53-
MMO_Parallel = true
53+
AbsTolerance = {1e-3}
5454
)
5555
);
5656

@@ -92,43 +92,6 @@ model advection2D
9292

9393

9494

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-
123-
124-
125-
126-
127-
128-
129-
130-
131-
13295

13396

13497

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
int
2-
getSection(int i)
1+
int getSection(int i)
32
{
4-
int ret = ((i-1)/1000)+1;
3+
int partition_size = 1000;
4+
int ret = ((i - 1) / partition_size) + 1;
55
return (ret);
66
}

test/partitioner/sim_models/sim_models.py

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,41 @@ def extract_size_from_partition(partition_name):
192192
)
193193

194194

195+
def generate_sections_file(size, partitions, destination):
196+
"""
197+
Generates the C file and copies it to the specified build directory.
198+
"""
199+
filename = "sections.c"
200+
partition_size = size // partitions
201+
202+
c_code = f"""int
203+
getSection(int i)
204+
{{
205+
int partition_size = {partition_size};
206+
int ret = ((i - 1) / partition_size) + 1;
207+
return (ret);
208+
}}
209+
"""
210+
try:
211+
# 1. Write the file
212+
with open(filename, "w") as f:
213+
f.write(c_code)
214+
print(f"Successfully generated '{filename}' with partition_size {partition_size}.")
215+
216+
# 2. Copy the file to the destination
217+
if not os.path.exists(destination):
218+
print(f"Error: Destination directory '{destination}' does not exist.")
219+
return
220+
221+
shutil.copy(filename, destination)
222+
print(f"Successfully copied '{filename}' to '{destination}'.")
223+
224+
except IOError as e:
225+
print(f"An error occurred during file operations: {e}")
226+
except PermissionError:
227+
print(f"Permission denied: Unable to write to '{destination}'.")
228+
229+
195230
def execute_simulation(model_path, partition_name):
196231
"""
197232
Compiles and executes the model dynamically, assigning N size constraints first.
@@ -200,6 +235,7 @@ def execute_simulation(model_path, partition_name):
200235

201236
model_p = Path(model_path).resolve()
202237
model_file = str(model_p)
238+
model = file_handlers.get_file_name(model_file)
203239

204240
partition_p = Path(partition_name).resolve()
205241

@@ -209,11 +245,15 @@ def execute_simulation(model_path, partition_name):
209245

210246
# Derive target destination (<model_name>.part in the model's directory)
211247
target_partition_path = model_p.with_suffix('.part')
212-
248+
build_target_path = new_path = Path(os.environ['MMOC_BUILD']) / model
249+
print("BUILD TARGET")
250+
print(build_target_path)
251+
213252
# Step 1: Copy custom partition to the required solver location
214253
try:
215254
print(f"Copying partition: {partition_p.name} -> {target_partition_path}")
216255
shutil.copy2(Path(partition_name).resolve(), target_partition_path)
256+
shutil.copy2(target_partition_path, build_target_path)
217257
except Exception as e:
218258
print(f"Failed to copy partition file: {e}")
219259
return False
@@ -225,8 +265,9 @@ def execute_simulation(model_path, partition_name):
225265
print(f"Current structural Constants: {current_constants}")
226266

227267
# Updating constant N size property
228-
set_constants(model_file, {"N": size})
268+
set_constants(model_file, {"N": size, "SECTIONS" : parts})
229269
print(f"Successfully set Constant 'N' to: {size}")
270+
print(f"Successfully set Constant 'SECTIONS' to: {parts}")
230271

231272
except Exception as e:
232273
print(f"Failed handling structural setup attributes: {e}")
@@ -247,7 +288,10 @@ def execute_simulation(model_path, partition_name):
247288
print(f" {key}: {value}")
248289
else:
249290
print(" No annotations found")
250-
291+
292+
if model == "airconds_cont":
293+
generate_sections_file(size, parts, build_target_path)
294+
251295
# Step 3: Compile the model
252296
print(f"\nCompiling model: {model_file}")
253297
if compile_model(model_file):
@@ -265,7 +309,6 @@ def execute_simulation(model_path, partition_name):
265309
return False
266310

267311
# Step 5: Get simulation results
268-
model = file_handlers.get_file_name(model_file)
269312
model_log_path = file_handlers.get_full_path(model, 'MMOC_LOG')
270313
sim_results(model_log_path)
271314
process_model_logs(file_handlers.get_base_path(model_log_path, 'MMOC_LOG'), model, sim_results)
@@ -306,4 +349,4 @@ def main():
306349

307350

308351
if __name__ == "__main__":
309-
main()
352+
main()

0 commit comments

Comments
 (0)