OMCompiler/Compiler/BackEnd/BackendDAEEXT.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 BackendDAEEXT | ||
| 37 | " file: BackendDAEEXT.mo | ||
| 38 | package: BackendDAEEXT | ||
| 39 | description: The BackendDAEEXT module is an externally implemented module (in file | ||
| 40 | Compiler/runtime/BackendDAEEXT.cpp) used for the BLT and index reduction | ||
| 41 | algorithms in BackendDAE. | ||
| 42 | The implementation mainly consists of several bitvectors implemented | ||
| 43 | using std::vector<bool> since such functionality is not available in | ||
| 44 | MetaModelica Compiler (MMC). | ||
| 45 | |||
| 46 | " | ||
| 47 | |||
| 48 | ✗ | public function initMarks | |
| 49 | input Integer inInteger1; | ||
| 50 | input Integer inInteger2; | ||
| 51 | |||
| 52 | external "C" BackendDAEEXT_initMarks(inInteger1,inInteger2) annotation(Library = "omcruntime"); | ||
| 53 | end initMarks; | ||
| 54 | |||
| 55 | ✗ | public function eMark | |
| 56 | input Integer inInteger; | ||
| 57 | |||
| 58 | external "C" BackendDAEEXT_eMark(inInteger) annotation(Library = "omcruntime"); | ||
| 59 | end eMark; | ||
| 60 | |||
| 61 | /* TODO: Implement an external C function for bootstrapped omc or remove me. DO NOT SIMPLY REMOVE THIS COMMENT | ||
| 62 | public function getEMark | ||
| 63 | input Integer inInteger; | ||
| 64 | output Boolean outBoolean; | ||
| 65 | |||
| 66 | external "C" outBoolean=BackendDAEEXT_getEMark(inInteger) annotation(Library = "omcruntime"); | ||
| 67 | end getEMark;*/ | ||
| 68 | |||
| 69 | ✗ | public function vMark | |
| 70 | input Integer inInteger; | ||
| 71 | |||
| 72 | external "C" BackendDAEEXT_vMark(inInteger) annotation(Library = "omcruntime"); | ||
| 73 | end vMark; | ||
| 74 | |||
| 75 | ✗ | public function getVMark | |
| 76 | input Integer inInteger; | ||
| 77 | output Boolean outBoolean; | ||
| 78 | |||
| 79 | external "C" outBoolean=BackendDAEEXT_getVMark(inInteger) annotation(Library = "omcruntime"); | ||
| 80 | end getVMark; | ||
| 81 | |||
| 82 | ✗ | public function getMarkedEqns | |
| 83 | output list<Integer> outIntegerLst; | ||
| 84 | |||
| 85 | external "C" outIntegerLst=BackendDAEEXT_getMarkedEqns() annotation(Library = "omcruntime"); | ||
| 86 | end getMarkedEqns; | ||
| 87 | |||
| 88 | ✗ | public function getDifferentiatedEqns | |
| 89 | output list<Integer> outIntegerLst; | ||
| 90 | |||
| 91 | external "C" outIntegerLst=BackendDAEEXT_getDifferentiatedEqns() annotation(Library = "omcruntime"); | ||
| 92 | end getDifferentiatedEqns; | ||
| 93 | |||
| 94 | ✗ | public function clearDifferentiated | |
| 95 | |||
| 96 | external "C" BackendDAEEXT_clearDifferentiated() annotation(Library = "omcruntime"); | ||
| 97 | end clearDifferentiated; | ||
| 98 | |||
| 99 | ✗ | public function markDifferentiated | |
| 100 | input Integer inInteger; | ||
| 101 | |||
| 102 | external "C" BackendDAEEXT_markDifferentiated(inInteger) annotation(Library = "omcruntime"); | ||
| 103 | end markDifferentiated; | ||
| 104 | |||
| 105 | ✗ | public function getMarkedVariables | |
| 106 | output list<Integer> outIntegerLst; | ||
| 107 | |||
| 108 | external "C" outIntegerLst=BackendDAEEXT_getMarkedVariables() annotation(Library = "omcruntime"); | ||
| 109 | end getMarkedVariables; | ||
| 110 | |||
| 111 | ✗ | public function initLowLink | |
| 112 | input Integer inInteger; | ||
| 113 | |||
| 114 | external "C" BackendDAEEXT_initLowLink(inInteger) annotation(Library = "omcruntime"); | ||
| 115 | end initLowLink; | ||
| 116 | |||
| 117 | ✗ | public function initNumber | |
| 118 | input Integer inInteger; | ||
| 119 | |||
| 120 | external "C" BackendDAEEXT_initNumber(inInteger) annotation(Library = "omcruntime"); | ||
| 121 | end initNumber; | ||
| 122 | |||
| 123 | ✗ | public function setLowLink | |
| 124 | input Integer inInteger1; | ||
| 125 | input Integer inInteger2; | ||
| 126 | |||
| 127 | external "C" BackendDAEEXT_setLowLink(inInteger1,inInteger2) annotation(Library = "omcruntime"); | ||
| 128 | end setLowLink; | ||
| 129 | |||
| 130 | ✗ | public function getLowLink | |
| 131 | input Integer inInteger; | ||
| 132 | output Integer outInteger; | ||
| 133 | |||
| 134 | external "C" outInteger=BackendDAEEXT_getLowLink(inInteger) annotation(Library = "omcruntime"); | ||
| 135 | end getLowLink; | ||
| 136 | |||
| 137 | ✗ | public function setNumber | |
| 138 | input Integer inInteger1; | ||
| 139 | input Integer inInteger2; | ||
| 140 | |||
| 141 | external "C" BackendDAEEXT_setNumber(inInteger1,inInteger2) annotation(Library = "omcruntime"); | ||
| 142 | end setNumber; | ||
| 143 | |||
| 144 | ✗ | public function getNumber | |
| 145 | input Integer inInteger; | ||
| 146 | output Integer outInteger; | ||
| 147 | |||
| 148 | external "C" outInteger=BackendDAEEXT_getNumber(inInteger) annotation(Library = "omcruntime"); | ||
| 149 | end getNumber; | ||
| 150 | |||
| 151 | /* TODO: Implement an external C function for bootstrapped omc or remove me. DO NOT SIMPLY REMOVE THIS COMMENT | ||
| 152 | public function dumpMarkedEquations | ||
| 153 | input Integer inInteger; | ||
| 154 | |||
| 155 | external "C" BackendDAEEXT_dumpMarkedEquations(inInteger) annotation(Library = "omcruntime"); | ||
| 156 | end dumpMarkedEquations; | ||
| 157 | |||
| 158 | public function dumpMarkedVariables | ||
| 159 | input Integer inInteger; | ||
| 160 | |||
| 161 | external "C" BackendDAEEXT_dumpMarkedVariables(inInteger) annotation(Library = "omcruntime"); | ||
| 162 | end dumpMarkedVariables; | ||
| 163 | |||
| 164 | public function initV | ||
| 165 | input Integer inInteger; | ||
| 166 | |||
| 167 | external "C" BackendDAEEXT_initV(inInteger) annotation(Library = "omcruntime"); | ||
| 168 | end initV; | ||
| 169 | |||
| 170 | public function initF | ||
| 171 | input Integer inInteger; | ||
| 172 | |||
| 173 | external "C" BackendDAEEXT_initF(inInteger) annotation(Library = "omcruntime"); | ||
| 174 | end initF; | ||
| 175 | |||
| 176 | public function setV | ||
| 177 | input Integer inInteger1; | ||
| 178 | input Integer inInteger2; | ||
| 179 | |||
| 180 | external "C" BackendDAEEXT_setV(inInteger1,inInteger2) annotation(Library = "omcruntime"); | ||
| 181 | end setV; | ||
| 182 | |||
| 183 | public function getV | ||
| 184 | input Integer inInteger; | ||
| 185 | output Integer outInteger; | ||
| 186 | |||
| 187 | external "C" outInteger=BackendDAEEXT_getV(inInteger) annotation(Library = "omcruntime"); | ||
| 188 | end getV; | ||
| 189 | |||
| 190 | public function setF | ||
| 191 | input Integer inInteger1; | ||
| 192 | input Integer inInteger2; | ||
| 193 | |||
| 194 | external "C" BackendDAEEXT_setF(inInteger1,inInteger2) annotation(Library = "omcruntime"); | ||
| 195 | end setF; | ||
| 196 | |||
| 197 | public function getF | ||
| 198 | input Integer inInteger; | ||
| 199 | output Integer outInteger; | ||
| 200 | |||
| 201 | external "C" outInteger=BackendDAEEXT_getF(inInteger) annotation(Library = "omcruntime"); | ||
| 202 | end getF; | ||
| 203 | */ | ||
| 204 | |||
| 205 | /****************************************** | ||
| 206 | C-Implementation Stuff from | ||
| 207 | Kamer Kaya, Johannes Langguth and Bora Ucar | ||
| 208 | see: http://bmi.osu.edu/~kamer/index.html | ||
| 209 | *****************************************/ | ||
| 210 | |||
| 211 | ✗ | public function setAdjacencyMatrix "author: Frenkel TUD 2012-04" | |
| 212 | input Integer nv; | ||
| 213 | input Integer ne; | ||
| 214 | input Integer nz; | ||
| 215 | input array<list<Integer>> m; | ||
| 216 | |||
| 217 | external "C" BackendDAEEXT_setAdjacencyMatrix(nv,ne,nz,m) annotation(Library = "omcruntime"); | ||
| 218 | end setAdjacencyMatrix; | ||
| 219 | |||
| 220 | 120973 | public function setAdjacencyMatrixFlat "the adjacency matrix with each row stored as a slice of one flat buffer" | |
| 221 | input Integer nv; | ||
| 222 | input Integer ne; | ||
| 223 | input Integer nz; | ||
| 224 | input array<Integer> start "row -> 1-based index of its first entry in data"; | ||
| 225 | input array<Integer> len "row -> number of entries"; | ||
| 226 | input array<Integer> data; | ||
| 227 | |||
| 228 | external "C" BackendDAEEXT_setAdjacencyMatrixFlat(nv,ne,nz,start,len,data) annotation(Library = "omcruntime"); | ||
| 229 | end setAdjacencyMatrixFlat; | ||
| 230 | |||
| 231 | /* TODO: Implement an external C function for bootstrapped omc or remove me. DO NOT SIMPLY REMOVE THIS COMMENT | ||
| 232 | public function cheapmatching | ||
| 233 | "author: Frenkel TUD 2012-04 | ||
| 234 | calls cheapmatching algorithms | ||
| 235 | cheapID: id of cheap algo (1-4) | ||
| 236 | 1: Simple Greedy | ||
| 237 | 2: Karp-Sipser | ||
| 238 | 3: Random Karp-Sipser (DEFAULT) | ||
| 239 | 4: Minimum Degree (two-sided) | ||
| 240 | |||
| 241 | Other than these two, non-positive values are not allowed. | ||
| 242 | " | ||
| 243 | input Integer nv; | ||
| 244 | input Integer ne; | ||
| 245 | input Integer cheapID; | ||
| 246 | input Integer clear_match; | ||
| 247 | external "C" BackendDAEEXT_cheapmatching(nv,ne,cheapID,clear_match) annotation(Library = "omcruntime"); | ||
| 248 | end cheapmatching;*/ | ||
| 249 | |||
| 250 | 2101 | public function matching | |
| 251 | "author: Frenkel TUD 2012-04 | ||
| 252 | calls matching algorithms | ||
| 253 | matchingID: id of match algo (1-10) | ||
| 254 | 1: DFS based | ||
| 255 | 2: BFS based | ||
| 256 | 3: MC21 (DFS + lookahead) | ||
| 257 | 4: PF (Pothen and Fan' algorithm) | ||
| 258 | 5: PF+ (PF + fairness) | ||
| 259 | 6: HK (Hopcroft and Karp's algorithm) | ||
| 260 | 7: HK-DW (Duff-Wiberg implementation of HK) | ||
| 261 | 8: ABMP (Alt et al.'s algorithm) | ||
| 262 | 9: ABMP-BFS (ABMP + BFS) | ||
| 263 | 10: PR-FIFO-FAIR (DEFAULT) | ||
| 264 | |||
| 265 | cheapID: id of cheap algo (0-4) | ||
| 266 | 0: No Cheap Matching | ||
| 267 | 1: Simple Greedy | ||
| 268 | 2: Karp-Sipser | ||
| 269 | 3: Random Karp-Sipser (DEFAULT) | ||
| 270 | 4: Minimum Degree (two-sided) | ||
| 271 | |||
| 272 | relabel_period: used only when matchID = 10. Otherwise it is ignored. | ||
| 273 | For the PR based algorithm, a global relabeling is started after | ||
| 274 | every (m+n) x 'relabel_period' pushes where m and | ||
| 275 | n are the number of rows and columns of the matrix. Default is 1. | ||
| 276 | -1: for a global relabeling after every m pushes | ||
| 277 | -2: for a global relabeling after every n pushes | ||
| 278 | Other than these two, non-positive values are not allowed. | ||
| 279 | " | ||
| 280 | input Integer nv; | ||
| 281 | input Integer ne; | ||
| 282 | input Integer matchingID; | ||
| 283 | input Integer cheapID; | ||
| 284 | input Real relabel_period; | ||
| 285 | input Integer clear_match; | ||
| 286 | external "C" BackendDAEEXT_matching(nv,ne,matchingID,cheapID,relabel_period,clear_match) annotation(Library = "omcruntime"); | ||
| 287 | end matching; | ||
| 288 | |||
| 289 | 123074 | public function getAssignment "author: Frenkel TUD 2012-04" | |
| 290 | input array<Integer> ass1; | ||
| 291 | input array<Integer> ass2; | ||
| 292 | external "C" BackendDAEEXT_getAssignment(ass1, ass2) annotation(Library = "omcruntime"); | ||
| 293 | end getAssignment; | ||
| 294 | |||
| 295 | 123074 | public function setAssignment | |
| 296 | "author: Frenkel TUD 2012-04" | ||
| 297 | input Integer lenass1; | ||
| 298 | input Integer lenass2; | ||
| 299 | input array<Integer> ass1; | ||
| 300 | input array<Integer> ass2; | ||
| 301 | output Boolean outBoolean; | ||
| 302 | |||
| 303 | external "C" outBoolean=BackendDAEEXT_setAssignment(lenass1,lenass2,ass1,ass2) annotation(Library = "omcruntime"); | ||
| 304 | end setAssignment; | ||
| 305 | |||
| 306 | annotation(__OpenModelica_Interface="backend_util"); | ||
| 307 | end BackendDAEEXT; | ||
| 308 |