OMCompiler/Compiler/BackEnd/HpcOmBenchmark.mo
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * This file is part of OpenModelica. | ||
| 3 | * | ||
| 4 | * Copyright (c) 1998-2026, Open Source Modelica Consortium (OSMC), | ||
| 5 | * c/o Linköpings universitet, Department of Computer and Information Science, | ||
| 6 | * SE-58183 Linköping, Sweden. | ||
| 7 | * | ||
| 8 | * All rights reserved. | ||
| 9 | * | ||
| 10 | * THIS PROGRAM IS PROVIDED UNDER THE TERMS OF AGPL VERSION 3 LICENSE OR | ||
| 11 | * THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.8. | ||
| 12 | * ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES | ||
| 13 | * RECIPIENT'S ACCEPTANCE OF THE OSMC PUBLIC LICENSE OR THE GNU AGPL | ||
| 14 | * VERSION 3, ACCORDING TO RECIPIENTS CHOICE. | ||
| 15 | * | ||
| 16 | * The OpenModelica software and the OSMC (Open Source Modelica Consortium) | ||
| 17 | * Public License (OSMC-PL) are obtained from OSMC, either from the above | ||
| 18 | * address, from the URLs: | ||
| 19 | * http://www.openmodelica.org or | ||
| 20 | * https://github.com/OpenModelica/ or | ||
| 21 | * http://www.ida.liu.se/projects/OpenModelica, | ||
| 22 | * and in the OpenModelica distribution. | ||
| 23 | * | ||
| 24 | * GNU AGPL version 3 is obtained from: | ||
| 25 | * https://www.gnu.org/licenses/licenses.html#GPL | ||
| 26 | * | ||
| 27 | * This program is distributed WITHOUT ANY WARRANTY; without | ||
| 28 | * even the implied warranty of MERCHANTABILITY or FITNESS | ||
| 29 | * FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH | ||
| 30 | * IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL. | ||
| 31 | * | ||
| 32 | * See the full OSMC Public License conditions for more details. | ||
| 33 | * | ||
| 34 | */ | ||
| 35 | |||
| 36 | encapsulated package HpcOmBenchmark | ||
| 37 | " file: HpcOmBenchmark.mo | ||
| 38 | package: HpcOmBenchmark | ||
| 39 | description: HpcOmBenchmark contains the whole logic to measure the communication and processing time. | ||
| 40 | |||
| 41 | " | ||
| 42 | |||
| 43 | protected import HpcOmBenchmarkExt; | ||
| 44 | protected import System; | ||
| 45 | |||
| 46 | public function benchSystem | ||
| 47 | output tuple<tuple<Integer,Integer>,tuple<Integer,Integer>> oTime; //required time for <op,com> | ||
| 48 | |||
| 49 | protected | ||
| 50 | Integer comCostM,comCostN,opCostM,opCostN; | ||
| 51 | list<Integer> opCosts, comCosts; | ||
| 52 | String s1,s2; | ||
| 53 | algorithm | ||
| 54 | //Don't use the opCost-calculation, the values are bad for equation systems | ||
| 55 | 1760 | opCosts := HpcOmBenchmarkExt.requiredTimeForOp(); | |
| 56 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1760 times.
|
1760 | true := listLength(opCosts) == 2; |
| 57 | 1760 | opCostM := listGet(opCosts,1); //m | |
| 58 | 1760 | opCostN := listGet(opCosts,2); //n | |
| 59 | 1760 | s1 := intString(opCostM); | |
| 60 | 1760 | s2 := intString(opCostN); | |
| 61 | //print("Test op y= " + s1 + " * x + " + s2 + "\n"); | ||
| 62 | |||
| 63 | 1760 | comCosts := HpcOmBenchmarkExt.requiredTimeForComm(); | |
| 64 | 1760 | comCostM := listGet(comCosts,1); //m | |
| 65 | 1760 | comCostN := listGet(comCosts,2); //n | |
| 66 | 1760 | s1 := intString(comCostM); | |
| 67 | 1760 | s2 := intString(comCostN); | |
| 68 | //print("Test comm y= " + s1 + " * x + " + s2 + "\n"); | ||
| 69 | |||
| 70 | 1760 | oTime := ((opCostM,opCostN),(comCostM,comCostN)); | |
| 71 | end benchSystem; | ||
| 72 | |||
| 73 | public function readCalcTimesFromFile "author: marcusw | ||
| 74 | Tries to find a file named <%iFileNamePrefix%>.xml or <%iFileNamePrefix%>.json. If such a file exists, the | ||
| 75 | calculation times are read out. If not, the function will fail." | ||
| 76 | input String iFileNamePrefix; | ||
| 77 | output list<tuple<Integer,Integer,Real>> calcTimes; //<simEqIdx,numberOfCalcs,calcTimeSum> | ||
| 78 | protected | ||
| 79 | String fullFileName; | ||
| 80 | list<tuple<Integer,Integer,Real>> tmpCalcTimes; | ||
| 81 | algorithm | ||
| 82 | calcTimes := matchcontinue iFileNamePrefix | ||
| 83 | case _ | ||
| 84 | algorithm | ||
| 85 | 8 | fullFileName := iFileNamePrefix + ".json"; | |
| 86 |
2/4✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
✓ Branch 3 taken 8 times.
✗ Branch 4 not taken.
|
8 | SOME(_) := System.getFileModificationTime(fullFileName); |
| 87 | //json-file does exist | ||
| 88 | ✗ | print("Using json-file\n"); | |
| 89 | ✗ | tmpCalcTimes := readCalcTimesFromJson(fullFileName); | |
| 90 | then tmpCalcTimes; | ||
| 91 | case _ | ||
| 92 | algorithm | ||
| 93 | 8 | fullFileName := iFileNamePrefix + ".xml"; | |
| 94 |
2/4✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
✓ Branch 3 taken 8 times.
✗ Branch 4 not taken.
|
8 | SOME(_) := System.getFileModificationTime(fullFileName); |
| 95 | //xml-file does exist | ||
| 96 | ✗ | tmpCalcTimes := readCalcTimesFromXml(fullFileName); | |
| 97 | then tmpCalcTimes; | ||
| 98 | else | ||
| 99 | algorithm | ||
| 100 | 8 | print("readCalcTimesFromFile: No valid profiling-file found.\n"); | |
| 101 | 8 | then fail(); | |
| 102 | end matchcontinue; | ||
| 103 | end readCalcTimesFromFile; | ||
| 104 | |||
| 105 | protected function readCalcTimesFromXml "author: marcusw | ||
| 106 | Reads the calculation times of the different simCode-equations out of the given xml-file (fileName). Make sure that the file exists before invoking this | ||
| 107 | method, otherwise it will return an misleading error-message. | ||
| 108 | Deprecated since commit r20267. Use the generated *.json-file instead." | ||
| 109 | input String fileName; | ||
| 110 | output list<tuple<Integer,Integer,Real>> calcTimes; //<simEqIdx,numberOfCalcs,calcTimeSum> | ||
| 111 | protected | ||
| 112 | list<Real> tmpResult; | ||
| 113 | algorithm | ||
| 114 | ✗ | tmpResult := HpcOmBenchmarkExt.readCalcTimesFromXml(fileName); | |
| 115 | ✗ | calcTimes := expandCalcTimes(tmpResult,{}); | |
| 116 | end readCalcTimesFromXml; | ||
| 117 | |||
| 118 | protected function readCalcTimesFromJson "author: marcusw | ||
| 119 | Reads the calculation times of the different simCode-equations out of the given json-file (fileName). Make sure that the file exists before invoking this | ||
| 120 | method, otherwise it will return an misleading error-message." | ||
| 121 | input String fileName; | ||
| 122 | output list<tuple<Integer,Integer,Real>> calcTimes; //<simEqIdx,numberOfCalcs,calcTimeSum> | ||
| 123 | protected | ||
| 124 | list<Real> tmpResult; | ||
| 125 | algorithm | ||
| 126 | ✗ | tmpResult := HpcOmBenchmarkExt.readCalcTimesFromJson(fileName); | |
| 127 | ✗ | calcTimes := expandCalcTimes(tmpResult,{}); | |
| 128 | end readCalcTimesFromJson; | ||
| 129 | |||
| 130 | protected function expandCalcTimes "author: marcusw | ||
| 131 | Takes a list of real vars and puts the first three entries into the tuple list. Afterwards it will cut off these entries and repeat with a tail-recursive call." | ||
| 132 | input list<Real> iList; | ||
| 133 | input list<tuple<Integer,Integer,Real>> iTuples; //<eqIdx,numOfCalcs,calcTimeSum> attention: eqIdx starts with zero | ||
| 134 | output list<tuple<Integer,Integer,Real>> oTuples; | ||
| 135 | protected | ||
| 136 | Real eqIdx, numOfCalcs, calcTimeSum; | ||
| 137 | Integer intNumOfCalcs,intEqIdx; | ||
| 138 | list<Real> rest; | ||
| 139 | list<tuple<Integer,Integer,Real>> tmpTuples; | ||
| 140 | algorithm | ||
| 141 | oTuples := matchcontinue iList | ||
| 142 | case numOfCalcs::calcTimeSum::eqIdx::rest | ||
| 143 | algorithm | ||
| 144 | //print("readCalcTimesFromXml1 eqIdx: " + intString(realInt(eqIdx)) + " numOfCalcs: " + intString(realInt(numOfCalcs)) + " calcTime: " + realString(calcTimeSum) + " \n"); | ||
| 145 | ✗ | intNumOfCalcs := realInt(numOfCalcs); | |
| 146 | ✗ | intEqIdx := realInt(eqIdx); | |
| 147 | ✗ | tmpTuples := expandCalcTimes(rest, (intEqIdx,intNumOfCalcs,calcTimeSum)::iTuples); | |
| 148 | then tmpTuples; | ||
| 149 | case {} | ||
| 150 | then iTuples; | ||
| 151 | else | ||
| 152 | algorithm | ||
| 153 | ✗ | print("expandCalcTimes: Invalid number of list-entries\n"); | |
| 154 | ✗ | then fail(); | |
| 155 | end matchcontinue; | ||
| 156 | end expandCalcTimes; | ||
| 157 | |||
| 158 | annotation(__OpenModelica_Interface="backend"); | ||
| 159 | end HpcOmBenchmark; | ||
| 160 |