| 422 | |
| 423 | |
| 424 | void finalizeQuESTEnv() { |
| 425 | validate_envIsInit(__func__); |
| 426 | |
| 427 | // NOTE: |
| 428 | // calling this will not automatically |
| 429 | // free the memory of existing Quregs |
| 430 | |
| 431 | if (globalEnvPtr->isGpuAccelerated) |
| 432 | gpu_clearCache(); // syncs first |
| 433 | |
| 434 | if (globalEnvPtr->isGpuAccelerated && gpu_isCuQuantumCompiled()) |
| 435 | gpu_finalizeCuQuantum(); |
| 436 | |
| 437 | if (globalEnvPtr->isDistributed) { |
| 438 | comm_sync(); |
| 439 | comm_end(); |
| 440 | } |
| 441 | |
| 442 | // free global env's heap memory and flag it as unallocated |
| 443 | free(globalEnvPtr); |
| 444 | globalEnvPtr = nullptr; |
| 445 | |
| 446 | // flag that the environment was finalised, to ensure it is never re-initialised |
| 447 | hasEnvBeenFinalized = true; |
| 448 | } |
| 449 | |
| 450 | |
| 451 | void syncQuESTEnv() { |