00001
00002 #include "ampi_funcptr_loader.h"
00003
00004 #include <stdio.h>
00005 #include <string.h>
00006
00007
00008 static void AMPI_FuncPtr_Pack(struct AMPI_FuncPtr_Transport * x)
00009 {
00010 #define AMPI_CUSTOM_FUNC(return_type, function_name, ...) \
00011 x->function_name = function_name;
00012 #if AMPI_HAVE_PMPI
00013 #define AMPI_FUNC(return_type, function_name, ...) \
00014 x->function_name = function_name; \
00015 x->P##function_name = P##function_name;
00016 #else
00017 #define AMPI_FUNC AMPI_CUSTOM_FUNC
00018 #endif
00019 #define AMPI_FUNC_NOIMPL AMPI_FUNC
00020
00021 #include "ampi_functions.h"
00022
00023 #undef AMPI_FUNC
00024 #undef AMPI_FUNC_NOIMPL
00025 #undef AMPI_CUSTOM_FUNC
00026 }
00027
00028 static void AMPI_FuncPtr_Unpack_Dispatch(SharedObject myexe, struct AMPI_FuncPtr_Transport * x)
00029 {
00030 typedef int (*myPtrUnpackType)(struct AMPI_FuncPtr_Transport *);
00031 auto myPtrUnpack = (myPtrUnpackType)dlsym(myexe, "AMPI_FuncPtr_Unpack");
00032
00033 if (myPtrUnpack == nullptr)
00034 {
00035 CkError("dlsym error: %s\n", dlerror());
00036 CkAbort("Could not complete AMPI_FuncPtr_Unpack!");
00037 }
00038
00039 myPtrUnpack(x);
00040 }
00041
00042
00043 static int AMPI_Main_Dispatch(SharedObject myexe, int argc, char ** argv)
00044 {
00045 typedef int (*maintype)(int, char **);
00046 typedef void (*fmpimaintype)(void);
00047
00048 auto AMPI_Main_cpp_ptr = (maintype)dlsym(myexe, "AMPI_Main_cpp");
00049 if (AMPI_Main_cpp_ptr)
00050 return AMPI_Main_cpp_ptr(argc, argv);
00051
00052 auto AMPI_Main_c_ptr = (maintype)dlsym(myexe, "AMPI_Main_c");
00053 if (AMPI_Main_c_ptr)
00054 return AMPI_Main_c_ptr(argc, argv);
00055
00056 auto AMPI_Main_ptr = (maintype)dlsym(myexe, "AMPI_Main");
00057 if (AMPI_Main_ptr)
00058 return AMPI_Main_ptr(argc, argv);
00059
00060 auto fmpi_main_ptr = (fmpimaintype)dlsym(myexe, STRINGIZE(FTN_NAME(MPI_MAIN,mpi_main)));
00061 if (fmpi_main_ptr)
00062 {
00063 fmpi_main_ptr();
00064 return 0;
00065 }
00066
00067 CkAbort("Could not find any AMPI entry points!");
00068
00069 return 1;
00070 }
00071
00072
00073 int AMPI_FuncPtr_Loader(SharedObject myexe, int argc, char ** argv)
00074 {
00075
00076 {
00077 AMPI_FuncPtr_Transport x;
00078 AMPI_FuncPtr_Pack(&x);
00079 AMPI_FuncPtr_Unpack_Dispatch(myexe, &x);
00080 }
00081
00082
00083 return AMPI_Main_Dispatch(myexe, argc, argv);
00084 }