7 static int (*mpi_init)(int *argc, char ***argv) = NULL;
8 static int (*mpi_deinit)() = NULL;
9 static int (*mpi_comm_rank)(MPI_Comm, int *) = NULL;
10 static int (*mpi_send)(void *, int, MPI_Datatype, int, int, MPI_Comm) = NULL;
11 static int (*mpi_recv)(void *, int, MPI_Datatype, int, int, MPI_Comm, MPI_Status *) = NULL;
13 static int hcall_enabled=0;
15 int connect_handler(void)
20 handle = dlopen("/usr/local/lib/libmpich.so", RTLD_LAZY);
22 fputs(dlerror(), stderr);
25 mpi_init = dlsym(handle, "MPI_Init");
26 if ((err = dlerror()) != NULL) {
27 fprintf(stderr, "%s\n", err);
30 mpi_deinit = dlsym(handle, "MPI_Finalize");
31 if ((err = dlerror()) != NULL) {
32 fprintf(stderr, "%s\n", err);
35 mpi_comm_rank = dlsym(handle, "MPI_Comm_rank");
36 if ((err = dlerror()) != NULL) {
37 fprintf(stderr, "%s\n", err);
40 mpi_recv = dlsym(handle, "MPI_Recv");
41 if ((err = dlerror()) != NULL) {
42 fprintf(stderr, "%s\n", err);
45 mpi_send = dlsym(handle, "MPI_Send");
46 if ((err = dlerror()) != NULL) {
47 fprintf(stderr, "%s\n", err);
55 int MPI_Init(int *argc, char ***argv)
60 if (mpi_init == NULL){
64 // Make sure that ***argv is in memory
67 rc = mpi_init(argc,argv);
73 fprintf(stderr,"Invoking mpi_init_hcall(%p,%p)\n",argc,argv);
75 if (mpi_init_hcall(argc,argv)<0) {
78 fprintf(stderr,"No connection to V3VEE MPI accelerator\n");
82 fprintf(stderr,"Connected to V3VEE MPI accelerator\n");
90 if (mpi_deinit == NULL){
95 if (mpi_deinit_hcall()<0) {
96 fprintf(stderr,"Could not disconnect from V3VEE MPI accelerator\n");
106 int MPI_Comm_rank(MPI_Comm comm, int *rank)
111 if (mpi_comm_rank == NULL){
116 rc=mpi_comm_rank(comm,rank);
122 // Make sure *rank is in memory
126 if (mpi_comm_rank_hcall(comm,rank)<0) {
127 fprintf(stderr,"Could not invoke mpi_comm_rank on V3VEE MPI accelerator\n");
135 int MPI_Send(void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm)
137 if (mpi_send == NULL){
147 for (i=0;i<count;i+=4096) {
148 temp=((char*)buf)[i];
151 if ((rc=mpi_send_hcall(buf,count,datatype,dest,tag,comm))<0) {
152 fprintf(stderr, "Could not send using V3VEE MPI accelerator - Trying Slow Path\n");
153 return mpi_send(buf, count, datatype, dest, tag, comm);
158 return mpi_send(buf, count, datatype, dest, tag, comm);
162 int MPI_Recv(void *buf, int count, MPI_Datatype datatype, int source, int tag,
163 MPI_Comm comm, MPI_Status *status)
165 if (mpi_recv == NULL){
172 volatile char temp=93;
175 for (i=0;i<count;i+=4096) {
176 ((char*)buf)[i]=temp;
178 if ((rc=mpi_recv_hcall(buf,count,datatype,source,tag,comm,status))<0) {
179 fprintf(stderr, "Could not receive using V3VEE MPI accelerator - Trying Slow Path\n");
180 return mpi_recv(buf, count, datatype, source, tag, comm, status);
185 return mpi_recv(buf, count, datatype, source, tag, comm, status);