From 12507c5c1861ccd84188e3e041b22aedfbe9689d Mon Sep 17 00:00:00 2001 From: "joaquin.f.fernandez" Date: Fri, 3 Jan 2025 14:07:29 -0300 Subject: [PATCH] [iss-275] Squashed commit of the following: commit 2dd87fb886535318ec3e38efa54d84747e80e784 Author: joaquin.f.fernandez Date: Fri Jan 3 13:43:12 2025 -0300 Misc updated docs. commit e981a21f8d9f33fafb0b64a73ec61c1a434206d6 Author: joaquin.f.fernandez Date: Fri Jan 3 13:42:51 2025 -0300 Generate partition stats afile and abort if requested. commit 751c4d99bc612ecfc007cce683b26c557b9baac1 Author: joaquin.f.fernandez Date: Fri Jan 3 13:42:19 2025 -0300 Added settings to qss data structure. commit 22088a4f4a1238650a18019119f08d274c4bf78b Author: joaquin.f.fernandez Date: Fri Jan 3 13:41:44 2025 -0300 Added partition only settings to run models. --- src/engine/common/settings.c | 4 +++ src/engine/common/settings.h | 1 + src/engine/qss/parallel/qss_partition.c | 23 +++++++++++-- src/engine/qss/qss_data.c | 4 ++- src/engine/qss/qss_data.h | 2 ++ src/engine/qss/qss_file.h | 45 +------------------------ src/engine/qss/qss_quantizer.h | 8 ++--- 7 files changed, 36 insertions(+), 51 deletions(-) diff --git a/src/engine/common/settings.c b/src/engine/common/settings.c index 3b18fda2..e7184d8b 100644 --- a/src/engine/common/settings.c +++ b/src/engine/common/settings.c @@ -161,6 +161,7 @@ SET_settings SET_Settings(char *fname) p->CVODE_max_order = 0; p->BDFMaxStep = 0; p->x_output = 0; + p->partition_only = 0; if (config_lookup_float(cf, "minstep", &dres)) { if (dres == 0) { p->minstep = MIN_STEP; @@ -284,6 +285,9 @@ SET_settings SET_Settings(char *fname) if (config_lookup_int(cf, "XOutput", &ires)) { p->x_output = ires; } + if (config_lookup_int(cf, "partitionOnly", &ires)) { + p->partition_only = ires; + } config_destroy(cf); return p; } diff --git a/src/engine/common/settings.h b/src/engine/common/settings.h index 537c250b..1bfea8a9 100644 --- a/src/engine/common/settings.h +++ b/src/engine/common/settings.h @@ -48,6 +48,7 @@ struct SET_settings_ { SD_partitionerOptions partitionerOptions; int BDFPart; int x_output; + int partition_only; }; SET_settings SET_Settings(char *fname); diff --git a/src/engine/qss/parallel/qss_partition.c b/src/engine/qss/parallel/qss_partition.c index c3d956e2..a45bb872 100644 --- a/src/engine/qss/parallel/qss_partition.c +++ b/src/engine/qss/parallel/qss_partition.c @@ -424,6 +424,7 @@ void PRT_createPartitions(PRT_partition partition, QSS_data data, char *name) return; } char fileName[256]; + char partition_stats_file_name[256]; char graphType[64] = "static"; grp_t nparts = (data->params->lps == 0 ? 64 : data->params->lps); grp_t nvtxs = data->states + data->events; @@ -431,10 +432,20 @@ void PRT_createPartitions(PRT_partition partition, QSS_data data, char *name) grp_t *xadj = NULL, *adjncy = NULL, *vwgt = NULL, *ewgt = NULL; grp_t i, edges; SD_PartitionMethod pm = data->params->pm; + struct timespec *init_time = checkedMalloc(sizeof(struct timespec)); + struct timespec *end_time = checkedMalloc(sizeof(struct timespec)); + sprintf(partition_stats_file_name, "%s-%ld-%ld-partition-stats.log", name, nvtxs, nparts); + FILE *partition_time_stats = fopen(partition_stats_file_name, "w"); + getTime(init_time); if (GRP_createGraph(name, data, &xadj, &adjncy, &edges, &vwgt, &ewgt, 0, NULL) == GRP_ReadError) { fprintf(stderr, "Could not read generated graph files."); abort(); } + getTime(end_time); + subTime(end_time, init_time); + fprintf(partition_time_stats, "Graph generation time: %g ms\n", getTimeValue(end_time)); + + getTime(init_time); if (nvtxs > nparts) { switch (pm) { case SD_Metis: { @@ -444,6 +455,7 @@ void PRT_createPartitions(PRT_partition partition, QSS_data data, char *name) options[METIS_OPTION_CONTIG] = 1; options[METIS_OPTION_PTYPE] = METIS_PTYPE_KWAY; options[METIS_OPTION_OBJTYPE] = METIS_OBJTYPE_VOL; + options[METIS_OPTION_RTYPE] = METIS_RTYPE_FM; options[METIS_OPTION_SEED] = 1; PRT_setMetisOptions(options, data); METIS_PartGraphKway(&nvtxs, &ncon, xadj, adjncy, vwgt, NULL, ewgt, &nparts, NULL, NULL, options, &edgecut, partition->values); @@ -508,8 +520,8 @@ void PRT_createPartitions(PRT_partition partition, QSS_data data, char *name) SCOTCH_Graph *graph_sc = SCOTCH_graphAlloc(); SCOTCH_Strat *strat = SCOTCH_stratAlloc(); SCOTCH_stratInit(strat); - PRT_setScotchOptions(strat, data); - if (SCOTCH_graphBuild(graph_sc, 0, n, x, x + 1, vw, NULL, e, xa, ew) != 0) { + SCOTCH_stratGraphMapBuild(strat, SCOTCH_STRATDEFAULT, data->params->lps, 0.05); + if (SCOTCH_graphBuild(graph_sc, 0, n, x, NULL, vw, NULL, e, xa, ew) != 0) { printf("Error: Scotch Graph Build\n"); } if (SCOTCH_graphPart(graph_sc, np, strat, val) != 0) { @@ -540,6 +552,10 @@ void PRT_createPartitions(PRT_partition partition, QSS_data data, char *name) break; } } + getTime(end_time); + subTime(end_time, init_time); + fprintf(partition_time_stats, "Partition time: %g ms\n", getTimeValue(end_time)); + fclose(partition_time_stats); switch (pm) { case SD_Metis: sprintf(fileName, "%s-Metis-%s-%ld.partition", name, graphType, nparts); @@ -571,6 +587,9 @@ void PRT_createPartitions(PRT_partition partition, QSS_data data, char *name) if (ewgt != NULL) { free(ewgt); } + if (data->settings->partition_only > 0) { + abort(); + } } PRT_partition PRT_Partition(QSS_data data, char *name) diff --git a/src/engine/qss/qss_data.c b/src/engine/qss/qss_data.c index d61ec23a..4f9e87a4 100644 --- a/src/engine/qss/qss_data.c +++ b/src/engine/qss/qss_data.c @@ -425,7 +425,7 @@ QSS_data QSS_Data(int states, int discretes, int events, int inputs, int algs, i QSS_setReinitBuffer(TRUE); } p->jac_matrices = SD_JacMatrices(state_eqs, states, alg_eqs, algs); - freeSettings(settings); + p->settings = settings; return p; } @@ -619,6 +619,7 @@ QSS_data QSS_copyData(QSS_data data) p->it = data->it; p->ft = data->ft; p->maxRHS = data->maxRHS; + p->settings = data->settings; if (discretes) { p->d = (double *)malloc(discretes * sizeof(double)); for (i = 0; i < discretes; i++) { @@ -878,6 +879,7 @@ void QSS_freeData(QSS_data data) } SD_freeEventData(data->event, data->events); SD_freeParameters(data->params); + freeSettings(data->settings); free(data); } diff --git a/src/engine/qss/qss_data.h b/src/engine/qss/qss_data.h index 10129703..30a1c1d9 100644 --- a/src/engine/qss/qss_data.h +++ b/src/engine/qss/qss_data.h @@ -30,6 +30,7 @@ #include #include +#include #include #define QSS_REINIT_BUFFER 10000 @@ -230,6 +231,7 @@ struct QSS_data_ { SD_parameters params; QSS_LP_data lp; SD_jacMatrices jac_matrices; + SET_settings settings; }; QSS_data QSS_Data(int states, int discretes, int events, int inputs, int algs, int state_eqs, int alg_eqs, string name); diff --git a/src/engine/qss/qss_file.h b/src/engine/qss/qss_file.h index 5ecd1148..8e9e17cc 100644 --- a/src/engine/qss/qss_file.h +++ b/src/engine/qss/qss_file.h @@ -17,67 +17,24 @@ ******************************************************************************/ -#ifndef QSS_FILE_H_ -#define QSS_FILE_H_ +#pragma once #include #include #include -/** - * - * @param - * @param - * @param - */ void F_write(LG_log log, int i, double time, double value); -/** - * - * @param - * @param - * @param - */ void F_writeLine(LG_log log, int, double, double*); -/** - * - */ void F_toFile(LG_log log); -/** - * - * @param simData - * @param simOutput - */ void F_init(LG_log log, QSS_data simData, SD_output simOutput); -/** - * - * @param - * @param - * @param - */ void F_PAR_write(LG_log log, int i, double time, double value); -/** - * - * @param - * @param - * @param - */ void F_PAR_writeLine(LG_log log, int, double, double*); -/** - * - */ void F_PAR_toFile(LG_log log); -/** - * - * @param simData - * @param simOutput - */ void F_PAR_init(LG_log log, QSS_data simData, SD_output simOutput); - -#endif /* QSS_FILE_H_ */ diff --git a/src/engine/qss/qss_quantizer.h b/src/engine/qss/qss_quantizer.h index 582d95f4..4bb57b73 100644 --- a/src/engine/qss/qss_quantizer.h +++ b/src/engine/qss/qss_quantizer.h @@ -299,13 +299,13 @@ struct QA_quantizerState_ { * The above type defines a struct that contains function pointers for various operations related to * quantization. * - * @var QA_quantizerState_:: {QA_recomputeNextTimesFn} recomputeNextTimes - A function pointer that takes no arguments + * @var QA_quantizerState_::{QA_recomputeNextTimesFn} recomputeNextTimes - A function pointer that takes no arguments * and returns no value. It is used to recompute the next times for the quantizer. - * @var QA_quantizerState_:: {QA_recomputeNextTimeFn} recomputeNextTime - A function that takes in a quantized state + * @var QA_quantizerState_::{QA_recomputeNextTimeFn} recomputeNextTime - A function that takes in a quantized state * and returns the next time at which the state should be recomputed. - * @var QA_quantizerState_:: {QA_nextTimeFn} nextTime - The nextTime property is a function that calculates the next + * @var QA_quantizerState_::{QA_nextTimeFn} nextTime - The nextTime property is a function that calculates the next * time step for the quantizer. - * @var QA_quantizerState_:: {QA_updateQuantizedStateFn} updateQuantizedState - The updateQuantizedState property is a + * @var QA_quantizerState_::{QA_updateQuantizedStateFn} updateQuantizedState - The updateQuantizedState property is a * function that is responsible for updating the quantized state of the QA_quantizerOps_ struct. */ struct QA_quantizerOps_ {