kupl_shm_comm_create
Creates a KUPL communicator.
Interface Definition
int kupl_shm_comm_create(int size, int rank, int pid, kupl_shm_oob_cb_h oob_cbs, void *group, kupl_shm_comm_h *comm);
Parameters
Parameter |
Type |
Description |
Input/Output |
|---|---|---|---|
size |
int |
Size of the KUPL communicator to be created. |
Input |
rank |
int |
Rank (zero-indexed rank) of the current process. |
Input |
pid |
int |
Process identifier (PID) of the current process. |
Input |
oob_cbs |
kupl_shm_oob_cb_h |
Out-of-band function pointer. For details, see the following Table 2. |
Input |
group |
void * |
Parameters on which the out-of-band function pointer depends. |
Input |
comm |
kupl_shm_comm_h |
KUPL communicator to be created. |
Output |
Parameter |
Type |
Description |
|---|---|---|
oob_allgather |
int (*kupl_shm_oob_allgather_cb_t)(const void*, void*, int, void*, kupl_shm_datatype_t) |
Pointer to the out-of-band allgather function, which collects process-related information during the creation of kupl_comm. |
oob_barrier |
int (*kupl_shm_oob_barrier_cb_t)(void *) |
Pointer to the out-of-band barrier function, which ensures the correct creation of kupl_comm. |
Return Value
- Success: KUPL_OK
- Failure: KUPL_ERROR
Examples
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | #include <stdio.h> #include <mpi.h> #include <unistd.h> #include "kupl.h" // Callback 1 required for creating a KUPL communicator. static int oob_barrier_callback(void *group) { return MPI_Barrier((MPI_Comm)group); } // Callback 2 required for creating a KUPL communicator. static int oob_allgather_callback(const void *sendbuf, void *recvbuf, int size, void *group, kupl_shm_datatype_t datatype) { switch (datatype) { case KUPL_SHM_DATATYPE_CHAR: return MPI_Allgather(sendbuf, size, MPI_CHAR, recvbuf, size, MPI_CHAR, (MPI_Comm)group); default: fprintf(stderr, "not support datatype"); return KUPL_ERROR; } } int main(int argc, char *argv[]) { // Initialize the MPI environment. MPI_Init(&argc, &argv); MPI_Comm comm = MPI_COMM_WORLD; // Obtain the size of the MPI communicator. int world_size; MPI_Comm_size(comm, &world_size); // Obtain the rank of the process. int world_rank; MPI_Comm_rank(comm, &world_rank); // Obtain the PID. int pid = getpid(); // Create a KUPL communicator. kupl_shm_oob_cb_t oob_cbs; kupl_shm_oob_cb_h oob_cbs_h = &oob_cbs; oob_cbs_h->oob_allgather = oob_allgather_callback; oob_cbs_h->oob_barrier = oob_barrier_callback; kupl_shm_comm_h kupl_comm; int ret = kupl_shm_comm_create(world_size, world_rank, pid, oob_cbs_h, (void *)comm, &kupl_comm); if (ret != KUPL_OK || kupl_comm == NULL) { fprintf(stderr, "kupl shm comm create failed: %d\n", ret); return -1; } kupl_shm_comm_destroy(kupl_comm); MPI_Finalize(); return 0; } |
The preceding example demonstrates how to create and destroy a KUPL communicator. The kupl_shm_comm_create function creates the KUPL communicator.