00001
00002
00003
00004
00005
00006
00007
00008 #include <adio.h>
00009
00010 #include <stdio.h>
00011
00012 #ifdef HAVE_FCNTL_H
00013 #include <fcntl.h>
00014 #endif
00015 #ifdef HAVE_SYS_TYPES_H
00016 #include <sys/types.h>
00017 #endif
00018 #ifdef HAVE_STDLIB_H
00019 #include <stdlib.h>
00020 #endif
00021 #ifdef HAVE_STRING_H
00022 #include <string.h>
00023 #endif
00024 #ifdef HAVE_SYS_STAT_H
00025 #include <sys/stat.h>
00026 #endif
00027 #ifdef HAVE_UNISTD_H
00028 #include <unistd.h>
00029 #endif
00030 #ifdef HAVE_IO_H
00031 #include <io.h>
00032 #endif
00033
00034 #ifndef PATH_MAX
00035 #define PATH_MAX 65535
00036 #endif
00037
00038
00039
00040 #define ROMIO_HINT_DEFAULT_CFG "/etc/romio-hints"
00041 #define ROMIO_HINT_ENV_VAR "ROMIO_HINTS"
00042
00043
00044 static void dump_keys(MPI_Info info) ATTRIBUTE((unused, used));
00045
00046
00047
00048
00049 static void dump_keys(MPI_Info info)
00050 {
00051 int i, nkeys, flag;
00052 char key[MPI_MAX_INFO_KEY];
00053 char value[MPI_MAX_INFO_VAL];
00054
00055 MPI_Info_get_nkeys(info, &nkeys);
00056
00057 for (i=0; i<nkeys; i++) {
00058 MPI_Info_get_nthkey(info, i, key);
00059 ADIOI_Info_get(info, key, MPI_MAX_INFO_VAL-1, value, &flag);
00060 printf("key = %s, value = %s\n", key, value);
00061 }
00062 return;
00063 }
00064
00065
00066
00067
00068
00069 static int find_file(void)
00070 {
00071 int fd=-1;
00072 char * hintfile;
00073
00074 hintfile = getenv(ROMIO_HINT_ENV_VAR);
00075 if(hintfile)
00076 fd = open(hintfile, O_RDONLY);
00077 if (fd < 0 )
00078 fd = open(ROMIO_HINT_DEFAULT_CFG, O_RDONLY);
00079
00080 return fd;
00081 }
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093 static int file_to_info(int fd, MPI_Info info)
00094 {
00095 char *buffer, *token, *key, *val, *garbage;
00096 char *pos1=NULL, *pos2=NULL;
00097 int flag, ret;
00098 char dummy;
00099 struct stat statbuf;
00100
00101
00102 fstat(fd, &statbuf);
00103
00104 buffer = (char *)ADIOI_Calloc(statbuf.st_size + 1, sizeof (char));
00105 if (buffer == NULL) return -1;
00106
00107 ret = read(fd, buffer, statbuf.st_size);
00108 if (ret < 0) return -1;
00109 token = strtok_r(buffer, "\n", &pos1);
00110 do {
00111 if ( (key = strtok_r(token, " \t", &pos2)) == NULL)
00112
00113 continue;
00114 if (token[0] == '#')
00115
00116 continue;
00117 if ( (val = strtok_r(NULL, " \t", &pos2)) == NULL)
00118
00119 continue;
00120 if ( (garbage = strtok_r(NULL, " \t", &pos2)) != NULL)
00121
00122 continue;
00123
00124 #ifdef SYSHINT_DEBUG
00125 printf("found: key=%s val=%s\n", key, val);
00126 #endif
00127
00128
00129 ADIOI_Info_get(info, key, 1, &dummy, &flag);
00130 if (flag == 1) continue;
00131 ADIOI_Info_set(info, key, val);
00132 } while ((token = strtok_r(NULL, "\n", &pos1)) != NULL);
00133 ADIOI_Free(buffer);
00134 return 0;
00135 }
00136
00137 void ADIOI_process_system_hints(MPI_Info info)
00138 {
00139 int hintfd;
00140
00141 hintfd = find_file();
00142 if (hintfd < 0) {
00143 #ifdef SYSHINT_DEBUG
00144 perror("ADIOI_process_system_hints");
00145 #endif
00146 return;
00147 }
00148 file_to_info(hintfd, info);
00149 close(hintfd);
00150 }
00151
00152
00153
00154 void ADIOI_incorporate_system_hints(MPI_Info info,
00155 MPI_Info sysinfo,
00156 MPI_Info *new_info)
00157 {
00158 int i, nkeys_sysinfo, flag;
00159 char val[MPI_MAX_INFO_VAL], key[MPI_MAX_INFO_KEY];
00160
00161 if (sysinfo == MPI_INFO_NULL)
00162 nkeys_sysinfo = 0;
00163 else
00164 MPI_Info_get_nkeys(sysinfo, &nkeys_sysinfo);
00165
00166
00167 if (info == MPI_INFO_NULL && nkeys_sysinfo == 0) {
00168 *new_info = MPI_INFO_NULL;
00169 return;
00170 }
00171
00172 if (info == MPI_INFO_NULL)
00173 MPI_Info_create(new_info);
00174 else
00175 MPI_Info_dup(info, new_info);
00176
00177 for (i=0; i<nkeys_sysinfo; i++) {
00178 MPI_Info_get_nthkey(sysinfo, i, key);
00179
00180 if (info != MPI_INFO_NULL) ADIOI_Info_get(info, key, 1, val, &flag);
00181 if (flag == 1) continue;
00182 ADIOI_Info_get(sysinfo, key, MPI_MAX_INFO_VAL-1, val, &flag);
00183 ADIOI_Info_set(*new_info, key, val);
00184 flag = 0;
00185 }
00186
00187 return;
00188 }
00189
00190