| 323 | |
| 324 | |
| 325 | qcomp** cpu_allocMatrix(qindex dim) { |
| 326 | |
| 327 | // NOTE: |
| 328 | // this function creates a matrix where rows are not necessarily |
| 329 | // contiguous in memory, which can incur gratuitous caching penalties |
| 330 | // when accessed in hot loops. As such, we do not use this function |
| 331 | // to allocate memory for CompMatr (instead, cpu_allocAndInitMatrixWrapper()), |
| 332 | // but instead use it for the individual Kraus matrices of a KrausMap, |
| 333 | // which are each quadratically smaller than the important superoperator. |
| 334 | |
| 335 | // allocate outer array |
| 336 | qcomp** rows = (qcomp**) malloc(dim * sizeof *rows); // nullptr if failed |
| 337 | |
| 338 | // if that did not fail, allocate each inner array |
| 339 | if (rows != nullptr) |
| 340 | for (qindex r=0; r<dim; r++) |
| 341 | rows[r] = cpu_allocArray(dim); // nullptr if failed |
| 342 | |
| 343 | // caller will validate whether mallocs were successful |
| 344 | return rows; |
| 345 | } |
| 346 | |
| 347 | |
| 348 | void cpu_deallocMatrix(qcomp** matrix, qindex dim) { |
no test coverage detected