Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
16179f1
Make env.isX bool to match env.userOwnsMpi
TysonRayJones May 29, 2026
1ddfb6b
Add MPI status validation
TysonRayJones May 29, 2026
507c2e4
Simplify comm_init()
TysonRayJones May 29, 2026
e80f768
Enable error msgs even when MPI config is invalid
TysonRayJones May 29, 2026
8b73cd3
Add Oliver's custom MPI examples
TysonRayJones May 29, 2026
e91f54f
renamed env.userOwnsMpi to env.isMpiUserOwned
TysonRayJones May 29, 2026
fe1020c
Remove redundant stdbool include
TysonRayJones May 29, 2026
d363d09
Add validation to initCustomMpiCommQuESTEnv
TysonRayJones May 29, 2026
70ac569
Rename mpiCommQuest to global_mpiComm
TysonRayJones May 29, 2026
ef6860b
Rename mpiCommQuest (local var) to mpiComm
TysonRayJones May 29, 2026
d85e064
Made environment.cpp adhere to global_ convention
TysonRayJones May 29, 2026
8fe9bbe
Remove suspicious updateQuESTEnvDistInfo()
TysonRayJones May 29, 2026
314e72e
Error in comm_getMpiComm() when comm=NULL
TysonRayJones May 29, 2026
51c0731
Remove MPI leak from comm_config.hpp
TysonRayJones May 29, 2026
047ede7
Rename comm_isMpiSubCommunicatorCompiled to comm_isMpiSubCommCompiled
TysonRayJones May 29, 2026
1680a12
Replace magic number
TysonRayJones May 29, 2026
00332a8
Make initCustomMpiCommQuESTEnv validate against re-init
TysonRayJones May 29, 2026
6763af0
Make initCustomMpiCommQuESTEnv validate subcomm is non-null
TysonRayJones May 29, 2026
1c9072c
Make initCustomMpiCommQuESTEnv validate set-subcomm succeeds
TysonRayJones May 29, 2026
7c75e72
Remove redundant env.bool tests
TysonRayJones May 29, 2026
93f30f2
Rename error_commDoubleSetMpiComm
TysonRayJones May 29, 2026
790d11c
Skip custom MPI examples when no MPI
TysonRayJones May 29, 2026
ac86d12
Patches
TysonRayJones May 29, 2026
28ddedd
Polished examples (and extended to C and C++)
TysonRayJones May 31, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions examples/extended/user_owned_mpi.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/** @file
*
* An example of using QuEST's experimental
* initCustomMpiQuESTEnv() function, to
* initialise QuEST in an environment where
* MPI is owned and controlled by the user.
*
* @author Oliver Brown
* @author Tyson Jones (doc)
*/

#include "quest.h"
#include <stdio.h>


// This example requires linking with MPI, which the CMake
// build only enables when QUEST_ENABLE_SUBCOMM is ON, which
// results in quest.h defining QUEST_COMPILE_SUBCOMM. To
// enable this example to always be compilable (like during
// our CI), we guard against when QUEST_ENABLE_SUBCOMM is OFF.
#if ! QUEST_COMPILE_SUBCOMM
int main(void)
{
printf("Example skipped since MPI is not linked.\n");
return 0;
}
#else


#include <mpi.h>

int main(void)
{
const int USE_DISTRIB = 1;
const bool USER_MPI = 1;
const int USE_OPENMP = 1;
const int USE_GPU = 0;

MPI_Init(NULL, NULL);
initCustomMpiQuESTEnv(USE_DISTRIB, USER_MPI, USE_GPU, USE_OPENMP);
reportQuESTEnv();
finalizeQuESTEnv();
MPI_Finalize();

return 0;
}


#endif // QUEST_COMPILE_SUBCOMM
49 changes: 49 additions & 0 deletions examples/extended/user_owned_mpi.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/** @file
*
* An example of using QuEST's experimental
* initCustomMpiQuESTEnv() function to
* initialise QuEST in an environment where
* MPI is owned and controlled by the user.
*
* @author Oliver Brown
* @author Tyson Jones (doc)
*/

#include "quest.h"
#include <cstdio>


// This example requires linking with MPI, which the CMake
// build only enables when QUEST_ENABLE_SUBCOMM is ON, which
// results in quest.h defining QUEST_COMPILE_SUBCOMM. To
// enable this example to always be compilable (like during
// our CI), we guard against when QUEST_ENABLE_SUBCOMM is OFF.
#if ! QUEST_COMPILE_SUBCOMM
int main(void)
{
std::printf("Example skipped since MPI is not linked.\n");
return 0;
}
#else


#include <mpi.h>

int main(void)
{
const int USE_DISTRIB = 1;
const bool USER_MPI = 1;
const int USE_OPENMP = 1;
const int USE_GPU = 0;

MPI_Init(NULL, NULL);
initCustomMpiQuESTEnv(USE_DISTRIB, USER_MPI, USE_GPU, USE_OPENMP);
reportQuESTEnv();
finalizeQuESTEnv();
MPI_Finalize();

return 0;
}


#endif // QUEST_COMPILE_SUBCOMM
84 changes: 84 additions & 0 deletions examples/extended/user_owned_submpi.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/** @file
*
* An example of using QuEST's experimental
* initCustomMpiCommQuESTEnv() function to
* dedicate only some user-owned MPI processes
* to QuEST, and dedicate the remainder to
* other tasks.
*
* @author Oliver Brown
* @author Tyson Jones (doc)
*/

#include "quest.h"
#include <stdio.h>


// This example requires linking with MPI, which the CMake
// build only enables when QUEST_ENABLE_SUBCOMM is ON, which
// results in quest.h defining QUEST_COMPILE_SUBCOMM. To
// enable this example to always be compilable (like during
// our CI), we guard against when QUEST_ENABLE_SUBCOMM is OFF.
#if ! QUEST_COMPILE_SUBCOMM
int main()
{
printf("Example skipped since MPI is not linked.\n");
return 0;
}
#else


#include <mpi.h>

int main (void)
{
int nprocs, quest_nprocs, world_rank, quest_rank;
MPI_Comm comm_split, comm_quantum, comm_classical;

MPI_Init(NULL, NULL);

MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
MPI_Comm_rank(MPI_COMM_WORLD, &world_rank);

const int I_AM_QUANTUM = world_rank % 2;

printf("[%d] Hello from rank %d of %d in MPI_COMM_WORLD.\n", world_rank, world_rank, nprocs);

MPI_Comm_split(MPI_COMM_WORLD, I_AM_QUANTUM, world_rank, &comm_split);

if (I_AM_QUANTUM) {
MPI_Comm_dup(comm_split, &comm_quantum);
MPI_Comm_size(comm_quantum, &quest_nprocs);
MPI_Comm_rank(comm_quantum, &quest_rank);
printf("[%d] Hello from rank %d of %d in comm_quantum.\n", world_rank, quest_rank, quest_nprocs);
} else {
MPI_Comm_dup(comm_split, &comm_classical);
quest_rank = -1;
quest_nprocs = -1;
}

// only procs in quantum comm initialise QuEST
if (I_AM_QUANTUM) {
printf("[%d] Initialising QuEST.\n", world_rank);
initCustomMpiCommQuESTEnv(comm_quantum, -1, -1); // -1 = auto-deployments

reportQuESTEnv();

printf("[%d] Finalising QuEST.\n", world_rank);
finalizeQuESTEnv();
}

MPI_Comm_free(&comm_split);
if (I_AM_QUANTUM) {
MPI_Comm_free(&comm_quantum);
} else {
MPI_Comm_free(&comm_classical);
}

MPI_Finalize();

return 0;
}


#endif // QUEST_COMPILE_SUBCOMM
84 changes: 84 additions & 0 deletions examples/extended/user_owned_submpi.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/** @file
*
* An example of using QuEST's experimental
* initCustomMpiCommQuESTEnv() function to
* dedicate only some user-owned MPI processes
* to QuEST, and dedicate the remainder to
* other tasks.
*
* @author Oliver Brown
* @author Tyson Jones (doc)
*/

#include "quest.h"
#include <cstdio>


// This example requires linking with MPI, which the CMake
// build only enables when QUEST_ENABLE_SUBCOMM is ON, which
// results in quest.h defining QUEST_COMPILE_SUBCOMM. To
// enable this example to always be compilable (like during
// our CI), we guard against when QUEST_ENABLE_SUBCOMM is OFF.
#if ! QUEST_COMPILE_SUBCOMM
int main()
{
std::printf("Example skipped since MPI is not linked.\n");
return 0;
}
#else


#include <mpi.h>

int main (void)
{
int nprocs, quest_nprocs, world_rank, quest_rank;
MPI_Comm comm_split, comm_quantum, comm_classical;

MPI_Init(NULL, NULL);

MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
MPI_Comm_rank(MPI_COMM_WORLD, &world_rank);

const int I_AM_QUANTUM = world_rank % 2;

std::printf("[%d] Hello from rank %d of %d in MPI_COMM_WORLD.\n", world_rank, world_rank, nprocs);

MPI_Comm_split(MPI_COMM_WORLD, I_AM_QUANTUM, world_rank, &comm_split);

if (I_AM_QUANTUM) {
MPI_Comm_dup(comm_split, &comm_quantum);
MPI_Comm_size(comm_quantum, &quest_nprocs);
MPI_Comm_rank(comm_quantum, &quest_rank);
std::printf("[%d] Hello from rank %d of %d in comm_quantum.\n", world_rank, quest_rank, quest_nprocs);
} else {
MPI_Comm_dup(comm_split, &comm_classical);
quest_rank = -1;
quest_nprocs = -1;
}

// only procs in quantum comm initialise QuEST
if (I_AM_QUANTUM) {
std::printf("[%d] Initialising QuEST.\n", world_rank);
initCustomMpiCommQuESTEnv(comm_quantum, modeflag::USE_AUTO, modeflag::USE_AUTO);

reportQuESTEnv();

std::printf("[%d] Finalising QuEST.\n", world_rank);
finalizeQuESTEnv();
}

MPI_Comm_free(&comm_split);
if (I_AM_QUANTUM) {
MPI_Comm_free(&comm_quantum);
} else {
MPI_Comm_free(&comm_classical);
}

MPI_Finalize();

return 0;
}


#endif // QUEST_COMPILE_SUBCOMM
12 changes: 6 additions & 6 deletions quest/include/environment.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@ extern "C" {
typedef struct {

// deployment modes which can be runtime disabled
int isMultithreaded;
int isGpuAccelerated;
int isDistributed;
bool userOwnsMpi;
bool isMultithreaded;
bool isGpuAccelerated;
bool isDistributed;
bool isMpiUserOwned;

// deployment modes which cannot be directly changed after compilation
int isCuQuantumEnabled;
bool isCuQuantumEnabled;

// deployment configurations which can be changed via environment variables
int isGpuSharingEnabled;
bool isGpuSharingEnabled;

// distributed configuration
int rank;
Expand Down
Loading
Loading