Last active
November 12, 2020 22:24
-
-
Save wesbland/065de74b3582913c3945099af5cf5130 to your computer and use it in GitHub Desktop.
Example QMPI Tool implementing the API from https://github.com/pmodels/mpich/pull/4715
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CC=mpicc | |
CFLAGS= -std=c99 -fPIC -rdynamic -shared -O2 -g | |
OBJ= mpich_example.so | |
all: $(OBJ) | |
mpich_example.so: mpich_example.c | |
$(CC) $(CFLAGS) -o $@ $< | |
clean: | |
rm -f *.so | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <time.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <mpi.h> | |
#ifndef _EXTERN_C_ | |
#ifdef __cplusplus | |
#define _EXTERN_C_ extern "C" | |
#else /* __cplusplus */ | |
#define _EXTERN_C_ | |
#endif /* __cplusplus */ | |
#endif /* _EXTERN_C_ */ | |
_EXTERN_C_ int Example_Init(QMPI_Context context, int tool_id, int *argc, char ***argv); | |
_EXTERN_C_ int Example_Recv(QMPI_Context context, int tool_id, void *buf, int count, | |
MPI_Datatype datatype, int source, int tag, MPI_Comm comm, | |
MPI_Status *status); | |
_EXTERN_C_ int Example_Send(QMPI_Context context, int tool_id, const void *buf, int count, | |
MPI_Datatype datatype, int dest, int tag, MPI_Comm comm); | |
_EXTERN_C_ int Example_Irecv(QMPI_Context context, int tool_id, void *buf, int count, | |
MPI_Datatype datatype, int source, int tag, MPI_Comm comm, | |
MPI_Request *request); | |
_EXTERN_C_ int Example_Isend(QMPI_Context context, int tool_id, const void *buf, int count, | |
MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, | |
MPI_Request *request); | |
struct tool_struct { | |
int my_tool_id; | |
}; | |
QMPI_Recv_t *next_recv_fn; int next_recv_id; | |
QMPI_Send_t *next_send_fn; int next_send_id; | |
QMPI_Irecv_t *next_irecv_fn; int next_irecv_id; | |
QMPI_Isend_t *next_isend_fn; int next_isend_id; | |
void example_init_function_pointer(int tool_id); | |
__attribute__((constructor)) void register_my_tool() | |
{ | |
fprintf(stderr, "Registering init function\n"); | |
QMPI_Register_tool_name("example", &example_init_function_pointer); | |
} | |
void example_init_function_pointer(int tool_id) | |
{ | |
fprintf(stderr, "Init callback function\n"); | |
struct tool_struct * my_tool_struct = calloc(0, sizeof(struct tool_struct)); | |
my_tool_struct->my_tool_id = tool_id; | |
QMPI_Register_tool_storage(tool_id, my_tool_struct); | |
QMPI_Register_function(tool_id, MPI_INIT_T, (void (*)(void)) &Example_Init); | |
QMPI_Register_function(tool_id, MPI_SEND_T, (void (*)(void)) &Example_Send); | |
QMPI_Register_function(tool_id, MPI_RECV_T, (void (*)(void)) &Example_Recv); | |
QMPI_Register_function(tool_id, MPI_ISEND_T, (void (*)(void)) &Example_Isend); | |
QMPI_Register_function(tool_id, MPI_IRECV_T, (void (*)(void)) &Example_Irecv); | |
} | |
_EXTERN_C_ int Example_Init(QMPI_Context context, int tool_id, int *argc, char ***argv) | |
{ | |
QMPI_Init_t *next_init_fn; | |
int next_tool_id, ret; | |
QMPI_Get_function(tool_id, MPI_INIT_T, (void (**)(void)) &next_init_fn, &context, &next_tool_id); | |
QMPI_Get_function(tool_id, MPI_RECV_T, (void (**)(void)) &next_recv_fn, &context, &next_recv_id); | |
QMPI_Get_function(tool_id, MPI_SEND_T, (void (**)(void)) &next_send_fn, &context, &next_send_id); | |
QMPI_Get_function(tool_id, MPI_IRECV_T, (void (**)(void)) &next_irecv_fn, &context, &next_irecv_id); | |
QMPI_Get_function(tool_id, MPI_ISEND_T, (void (**)(void)) &next_isend_fn, &context, &next_isend_id); | |
ret = (*next_init_fn)(context, next_tool_id, argc, argv); | |
return ret; | |
} | |
_EXTERN_C_ int Example_Recv(QMPI_Context context, int tool_id, void *buf, int count, | |
MPI_Datatype datatype, int source, int tag, MPI_Comm comm, | |
MPI_Status *status) | |
{ | |
int ret; | |
struct tool_struct *storage; | |
QMPI_Get_tool_storage(context, tool_id, (void *) &storage); | |
//fprintf(stderr, "In Example Receive QMPI wrapper. Storage tool ID: %d\n", storage->my_tool_id); | |
ret = (*next_recv_fn)(context, next_recv_id, buf, count, datatype, source, tag, comm, status); | |
return ret; | |
} | |
_EXTERN_C_ int Example_Send(QMPI_Context context, int tool_id, const void *buf, int count, | |
MPI_Datatype datatype, int dest, int tag, MPI_Comm comm) | |
{ | |
int ret; | |
struct tool_struct *storage; | |
QMPI_Get_tool_storage(context, tool_id, (void *) &storage); | |
//fprintf(stderr, "In Example Send QMPI wrapper. Storage tool ID: %d\n", storage->my_tool_id); | |
ret = (*next_send_fn)(context, next_send_id, buf, count, datatype, dest, tag, comm); | |
return ret; | |
} | |
_EXTERN_C_ int Example_Irecv(QMPI_Context context, int tool_id, void *buf, int count, | |
MPI_Datatype datatype, int source, int tag, MPI_Comm comm, | |
MPI_Request *request) | |
{ | |
int ret; | |
struct tool_struct *storage; | |
QMPI_Get_tool_storage(context, tool_id, (void *) &storage); | |
//fprintf(stderr, "In Example Ireceive QMPI wrapper. Storage tool ID: %d\n", storage->my_tool_id); | |
ret = (*next_irecv_fn)(context, next_irecv_id, buf, count, datatype, source, tag, comm, request); | |
return ret; | |
} | |
_EXTERN_C_ int Example_Isend(QMPI_Context context, int tool_id, const void *buf, int count, | |
MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, | |
MPI_Request *request) | |
{ | |
int ret; | |
struct tool_struct *storage; | |
QMPI_Get_tool_storage(context, tool_id, (void *) &storage); | |
//fprintf(stderr, "In Example Isend QMPI wrapper. Storage tool ID: %d\n", storage->my_tool_id); | |
ret = (*next_isend_fn)(context, next_isend_id, buf, count, datatype, dest, tag, comm, request); | |
return ret; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment