This source file includes following definitions.
- main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 #define _GNU_SOURCE
16
17 #include <assert.h>
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <string.h>
21 #include <libgen.h>
22
23 #include <dlfcn.h>
24
25 #define MCA_BTL_USNIC_SO "mca_btl_usnic.so"
26
27 typedef void (*run_tests_fn_t)(void);
28
29 int main(int argc, char **argv)
30 {
31 void *mpi_handle;
32 void *usnic_handle;
33 void (*run_tests)(void);
34 int (*init)(int *, char ***);
35 int (*finalize)(void);
36 Dl_info info;
37 char *libmpi_path;
38 char *path;
39 char *to;
40 int path_len;
41
42 mpi_handle = dlopen("lib" OMPI_LIBMPI_NAME ".so", RTLD_NOW|RTLD_GLOBAL);
43 if (mpi_handle == NULL) {
44 fprintf(stderr, "mpi_handle=NULL dlerror()=%s\n", dlerror());
45 abort();
46 }
47
48
49 *(void **)(&init) = dlsym(mpi_handle, "MPI_Init");
50 if (init == NULL) {
51 fprintf(stderr, "init=NULL dlerror()=%s\n", dlerror());
52 abort();
53 }
54
55 *(void **)(&finalize) = dlsym(mpi_handle, "MPI_Finalize");
56 if (finalize == NULL) {
57 fprintf(stderr, "finalize=%p dlerror()=%s\n", *(void **)(&finalize), dlerror());
58 abort();
59 }
60
61
62 init(&argc, &argv);
63
64
65 if (!dladdr(*(void **)(&init), &info)) {
66 fprintf(stderr, "ERROR: unable to dladdr(init,...)\n");
67 abort();
68 }
69 libmpi_path = strdup(info.dli_fname);
70 assert(libmpi_path != NULL);
71 path_len = strlen(libmpi_path) + strlen("/openmpi/") + strlen(MCA_BTL_USNIC_SO);
72 path = calloc(path_len+1, 1);
73 to = path;
74 to = stpcpy(to, dirname(libmpi_path));
75 to = stpcpy(to, "/openmpi/");
76 to = stpcpy(to, MCA_BTL_USNIC_SO);
77
78 usnic_handle = dlopen(path, RTLD_NOW|RTLD_LOCAL);
79 if (usnic_handle == NULL) {
80 fprintf(stderr, "usnic_handle=%p dlerror()=%s\n", (void *)usnic_handle, dlerror());
81 abort();
82 }
83
84 free(libmpi_path);
85 free(path);
86
87
88 *(void **)(&run_tests) = dlsym(usnic_handle, BTL_USNIC_RUN_TESTS_SYMBOL);
89 if (run_tests == NULL) {
90 fprintf(stderr, "run_tests=%p dlerror()=%s\n",
91 *(void **)(&run_tests), dlerror());
92 abort();
93 }
94 run_tests();
95
96 finalize();
97
98
99
100
101 return 0;
102 }