Changeset 34749 for trunk/Ohana/src/opihi/dvo/dvo_host_utils.c
- Timestamp:
- Nov 30, 2012, 10:06:05 AM (14 years ago)
- File:
-
- 1 edited
-
trunk/Ohana/src/opihi/dvo/dvo_host_utils.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/opihi/dvo/dvo_host_utils.c
r34260 r34749 79 79 } 80 80 81 // bundle the arguments into a command and pass to dvo_client. this implementation 82 // expects there to be a result file from the clients, and to load this into vectors in 83 // the main shell. 'Nelements' is a temp hack : for most commands, the result vectors are 84 // concatenated, but for avmatch, the vectors are merged by index into a pre-known 85 // length. this is probably not a solution to a general problem.. 86 int HostTableParallelOps (int argc, char **argv, char *ResultFile, int Nelements, int VERBOSE) { 81 // bundle the arguments into a command and pass to dvo_client. 82 83 // the normal ending step expects there to be a result file from the clients, and to load 84 // this into vectors in the main shell. 'Nelements' is a temp hack : for most commands, 85 // the result vectors are concatenated, but for avmatch, the vectors are merged by index 86 // into a pre-known length. this is probably not a solution to a general problem.. 87 88 // an alternative ending step ignores the result files and instead saves the names into 89 // the list 'result:n' for the user to access as desired 90 int HostTableParallelOps (int argc, char **argv, char *ResultFile, int ReadVectors, int Nelements, int VERBOSE) { 87 91 88 92 int i; … … 153 157 } 154 158 159 // create the result file list 160 char name[256]; 161 snprintf (name, 256, "RESULT_FILE:n"); 162 set_int_variable (name, table->Nhosts); 163 snprintf (name, 256, "RESULT_DATA:n"); 164 set_int_variable (name, table->Nhosts); 165 snprintf (name, 256, "RESULT_STATUS:n"); 166 set_int_variable (name, table->Nhosts); 167 155 168 // load fields from file 156 169 int Nvec = 0; 157 170 Vector **vec = NULL; 158 171 for (i = 0; i < table->Nhosts; i++) { 172 173 snprintf (name, 256, "RESULT_FILE:%d", i); 174 set_str_variable (name, table->hosts[i].results); 175 176 // DATA : 0 (unread), 1 (read) 177 snprintf (name, 256, "RESULT_DATA:%d", i); 178 set_int_variable (name, 0); 179 180 // STATUS : 0 (normal exit), -1 (crash), N (failure exit status) 181 snprintf (name, 256, "RESULT_STATUS:%d", i); 182 set_int_variable (name, table->hosts[i].status); 183 159 184 if (table->hosts[i].status) continue; 185 186 if (ReadVectors) { 187 int Ninvec = 0; 188 Vector **invec = ReadVectorTableFITS (table->hosts[i].results, "RESULT", &Ninvec); 189 if (!invec) { 190 // failed to read the file, now what? 191 gprint (GP_ERR, "failed to read remote result file : %s\n", table->hosts[i].results); 192 free (table->hosts[i].results); 193 table->hosts[i].results = NULL; 194 continue; 195 } 196 free (table->hosts[i].results); 197 table->hosts[i].results = NULL; 198 set_int_variable (name, 1); // result file has been read 199 200 if (Nelements == 0) { 201 vec = MergeVectors (vec, &Nvec, invec, Ninvec); 202 if (vec != invec) { 203 FreeVectorArray (invec, Ninvec); 204 } 205 } else { 206 vec = MergeVectorsByIndex (vec, &Nvec, invec, Ninvec, Nelements); 207 FreeVectorArray (invec, Ninvec); 208 } 209 } 210 } 211 212 // write vectors to a table (this is used by parallel dvo operations, but can be used elsewhere) 213 if (ResultFile) { 214 int status = WriteVectorTableFITS (ResultFile, "RESULT", vec, Nvec, FALSE, NULL); 215 if (!status) { 216 gprint (GP_ERR, "failed to write result file %s\n", ResultFile); 217 return FALSE; 218 } 219 } 220 221 for (i = 0; i < Nvec; i++) { 222 AssignVector (vec[i], vec[i]->name, ANYVECTOR, TRUE); 223 } 224 free (vec); 225 226 free (table); 227 return TRUE; 228 } 229 230 // re-gather the remote results files: this can be used in case one of the clients failed, 231 // and has since been re-run 232 int HostTableReloadResults (char *uniquer, int VERBOSE) { 233 234 int i; 235 236 // load the list of hosts 237 SkyTable *sky = GetSkyTable(); 238 if (!sky) { 239 gprint (GP_ERR, "failed to load sky table for database\n"); 240 return FALSE; 241 } 242 243 char *CATDIR = GetCATDIR (); 244 if (!CATDIR) { 245 gprint (GP_ERR, "failed to get CATDIR for database\n"); 246 return FALSE; 247 } 248 249 HostTable *table = HostTableLoad (CATDIR, sky->hosts); 250 if (!table) { 251 gprint (GP_ERR, "ERROR: failure reading Host Table %s for database %s\n", sky->hosts, CATDIR); 252 return FALSE; 253 } 254 255 // load fields from file 256 int Nvec = 0; 257 Vector **vec = NULL; 258 for (i = 0; i < table->Nhosts; i++) { 259 // ensure that the paths are absolute path names 260 char *tmppath = abspath (table->hosts[i].pathname, DVO_MAX_PATH); 261 free (table->hosts[i].pathname); 262 table->hosts[i].pathname = tmppath; 263 264 // need to save the results filename with the uniquer 265 // XXX a bit of a waste (but only 1024 * 60 bytes or so 266 ALLOCATE (table->hosts[i].results, char, DVO_MAX_PATH); 267 snprintf (table->hosts[i].results, DVO_MAX_PATH, "%s/dvo.results.%s.fits", table->hosts[i].pathname, uniquer); 160 268 161 269 int Ninvec = 0; … … 171 279 table->hosts[i].results = NULL; 172 280 173 if (Nelements == 0) { 174 vec = MergeVectors (vec, &Nvec, invec, Ninvec); 175 if (vec != invec) { 176 FreeVectorArray (invec, Ninvec); 177 } 178 } else { 179 vec = MergeVectorsByIndex (vec, &Nvec, invec, Ninvec, Nelements); 281 // fprintf (stderr, "%s : %d\n", table->hosts[i].pathname, invec[0]->Nelements); 282 283 vec = MergeVectors (vec, &Nvec, invec, Ninvec); 284 if (vec != invec) { 180 285 FreeVectorArray (invec, Ninvec); 181 }182 }183 184 // write vectors to a table (this is used by parallel dvo operations, but can be used elsewhere)185 if (ResultFile) {186 int status = WriteVectorTableFITS (ResultFile, "RESULT", vec, Nvec, FALSE, NULL);187 if (!status) {188 gprint (GP_ERR, "failed to write result file %s\n", ResultFile);189 return FALSE;190 286 } 191 287 } … … 199 295 return TRUE; 200 296 } 201 202 // re-gather the remote results files: this can be used in case one of the clients failed,203 // and has since been re-run204 int HostTableReloadResults (char *uniquer, int VERBOSE) {205 206 int i;207 208 // load the list of hosts209 SkyTable *sky = GetSkyTable();210 if (!sky) {211 gprint (GP_ERR, "failed to load sky table for database\n");212 return FALSE;213 }214 215 char *CATDIR = GetCATDIR ();216 if (!CATDIR) {217 gprint (GP_ERR, "failed to get CATDIR for database\n");218 return FALSE;219 }220 221 HostTable *table = HostTableLoad (CATDIR, sky->hosts);222 if (!table) {223 gprint (GP_ERR, "ERROR: failure reading Host Table %s for database %s\n", sky->hosts, CATDIR);224 return FALSE;225 }226 227 // load fields from file228 int Nvec = 0;229 Vector **vec = NULL;230 for (i = 0; i < table->Nhosts; i++) {231 // ensure that the paths are absolute path names232 char *tmppath = abspath (table->hosts[i].pathname, DVO_MAX_PATH);233 free (table->hosts[i].pathname);234 table->hosts[i].pathname = tmppath;235 236 // need to save the results filename with the uniquer237 // XXX a bit of a waste (but only 1024 * 60 bytes or so238 ALLOCATE (table->hosts[i].results, char, DVO_MAX_PATH);239 snprintf (table->hosts[i].results, DVO_MAX_PATH, "%s/dvo.results.%s.fits", table->hosts[i].pathname, uniquer);240 241 int Ninvec = 0;242 Vector **invec = ReadVectorTableFITS (table->hosts[i].results, "RESULT", &Ninvec);243 if (!invec) {244 // failed to read the file, now what?245 gprint (GP_ERR, "failed to read remote result file : %s\n", table->hosts[i].results);246 free (table->hosts[i].results);247 table->hosts[i].results = NULL;248 continue;249 }250 free (table->hosts[i].results);251 table->hosts[i].results = NULL;252 253 // fprintf (stderr, "%s : %d\n", table->hosts[i].pathname, invec[0]->Nelements);254 255 vec = MergeVectors (vec, &Nvec, invec, Ninvec);256 if (vec != invec) {257 FreeVectorArray (invec, Ninvec);258 }259 }260 261 for (i = 0; i < Nvec; i++) {262 AssignVector (vec[i], vec[i]->name, ANYVECTOR, TRUE);263 }264 free (vec);265 266 free (table);267 return TRUE;268 }
Note:
See TracChangeset
for help on using the changeset viewer.
