Changeset 33963 for trunk/Ohana/src/opihi/dvo/dvo_host_utils.c
- Timestamp:
- May 30, 2012, 1:46:12 PM (14 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
Ohana/src/opihi/dvo/dvo_host_utils.c (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk
-
trunk/Ohana/src/opihi/dvo/dvo_host_utils.c
r33662 r33963 4 4 # define PARALLEL_MANUAL 0 5 5 # define PARALLEL_SERIAL 0 6 # define MAX_PATH_LENGTH 1024 7 8 int HostTableLaunchJobs (HostTable *table, char *basecmd, char *options) { 6 # define DVO_MAX_PATH 1024 7 8 # define DIE(WHO,MSG) { perror(WHO); myAbort(MSG); } 9 10 int HostTableLaunchJobs (HostTable *table, char *basecmd, char *options, int VERBOSE) { 9 11 10 12 char uniquer[12]; … … 13 15 snprintf (uniquer, 12, "%05d.%05d", PID, TIME % 100000); 14 16 17 int top_status = TRUE; 15 18 int i; 16 19 for (i = 0; i < table->Nhosts; i++) { 17 20 18 21 // ensure that the paths are absolute path names 19 char *tmppath = abspath (table->hosts[i].pathname, MAX_PATH_LENGTH);22 char *tmppath = abspath (table->hosts[i].pathname, DVO_MAX_PATH); 20 23 free (table->hosts[i].pathname); 21 24 table->hosts[i].pathname = tmppath; … … 23 26 // need to save the results filename with the uniquer 24 27 // XXX a bit of a waste (but only 1024 * 60 bytes or so 25 ALLOCATE (table->hosts[i].results, char, MAX_PATH_LENGTH);26 snprintf (table->hosts[i].results, MAX_PATH_LENGTH, "%s/dvo.results.%s.fits", table->hosts[i].pathname, uniquer);27 28 char commandBase[ MAX_PATH_LENGTH];29 snprintf (commandBase, MAX_PATH_LENGTH, "dvo.command.%s.txt", uniquer);30 char *commandFile = abspath(commandBase, MAX_PATH_LENGTH);28 ALLOCATE (table->hosts[i].results, char, DVO_MAX_PATH); 29 snprintf (table->hosts[i].results, DVO_MAX_PATH, "%s/dvo.results.%s.fits", table->hosts[i].pathname, uniquer); 30 31 char commandBase[DVO_MAX_PATH]; 32 snprintf (commandBase, DVO_MAX_PATH, "dvo.command.%s.txt", uniquer); 33 char *commandFile = abspath(commandBase, DVO_MAX_PATH); 31 34 32 35 FILE *f = fopen (commandFile, "w"); 33 36 fprintf (f, "%s\n", basecmd); 34 fclose (f); 37 if (fflush (f)) DIE("flush", "failed to flush"); 38 39 int fd = fileno (f); 40 if (fsync (fd)) DIE("fsync", "failed to fsync"); 41 42 if (fclose (f)) DIE("close", "failed to close"); 43 44 // force NFS to write the file to disk 45 int state; 46 f = fsetlockfile (commandFile, 0.5, LCK_XCLD, &state); 47 fclearlockfile (commandFile, f, LCK_XCLD, &state); 35 48 36 49 char command[1024]; … … 38 51 free (commandFile); 39 52 40 if ( DEBUG || PARALLEL_MANUAL) fprintf (stderr, "command: %s\n", command);53 if (VERBOSE) gprint (GP_ERR, "command: %s\n", command); 41 54 42 55 if (PARALLEL_MANUAL) { … … 47 60 int status = system (command); 48 61 if (status) { 49 fprintf (stderr, "ERROR running relphot_client\n");50 exit (2);62 gprint (GP_ERR, "ERROR running relphot_client\n"); 63 top_status = FALSE; 51 64 } 52 65 } else { … … 55 68 int pid = rconnect ("ssh", table->hosts[i].hostname, command, table->hosts[i].stdio, &errorInfo, FALSE); 56 69 if (!pid) { 57 if (DEBUG) fprintf (stderr, "failure to start %s (error %d)\n", table->hosts[i].hostname, errorInfo); 58 exit (1); 70 gprint (GP_ERR, "failure to start %s (error %d)\n", table->hosts[i].hostname, errorInfo); 71 top_status = FALSE; 72 continue; 59 73 } 60 74 table->hosts[i].pid = pid; // save for future reference 61 75 } 62 76 } 63 return TRUE;77 return top_status; 64 78 } 65 79 … … 86 100 } 87 101 88 char *CATDIR = abspath (tmppath, MAX_PATH_LENGTH);102 char *CATDIR = abspath (tmppath, DVO_MAX_PATH); 89 103 if (!CATDIR) { 90 104 gprint (GP_ERR, "failed to make an absolute path from %s (too long)\n", tmppath); … … 126 140 127 141 // launch this command remotely 128 HostTableLaunchJobs (table, basecmd, options );142 HostTableLaunchJobs (table, basecmd, options, VERBOSE); 129 143 free (options); 130 144 free (basecmd); … … 184 198 return TRUE; 185 199 } 200 201 // re-gather the remote results files: this can be used in case one of the clients failed, 202 // and has since been re-run 203 int HostTableReloadResults (char *uniquer, int VERBOSE) { 204 205 int i; 206 207 // load the list of hosts 208 SkyTable *sky = GetSkyTable(); 209 if (!sky) { 210 gprint (GP_ERR, "failed to load sky table for database\n"); 211 return FALSE; 212 } 213 214 char *CATDIR = GetCATDIR (); 215 if (!CATDIR) { 216 gprint (GP_ERR, "failed to get CATDIR for database\n"); 217 return FALSE; 218 } 219 220 HostTable *table = HostTableLoad (CATDIR, sky->hosts); 221 if (!table) { 222 gprint (GP_ERR, "ERROR: failure reading Host Table %s for database %s\n", sky->hosts, CATDIR); 223 return FALSE; 224 } 225 226 // load fields from file 227 int Nvec = 0; 228 Vector **vec = NULL; 229 for (i = 0; i < table->Nhosts; i++) { 230 // ensure that the paths are absolute path names 231 char *tmppath = abspath (table->hosts[i].pathname, DVO_MAX_PATH); 232 free (table->hosts[i].pathname); 233 table->hosts[i].pathname = tmppath; 234 235 // need to save the results filename with the uniquer 236 // XXX a bit of a waste (but only 1024 * 60 bytes or so 237 ALLOCATE (table->hosts[i].results, char, DVO_MAX_PATH); 238 snprintf (table->hosts[i].results, DVO_MAX_PATH, "%s/dvo.results.%s.fits", table->hosts[i].pathname, uniquer); 239 240 int Ninvec = 0; 241 Vector **invec = ReadVectorTableFITS (table->hosts[i].results, "RESULT", &Ninvec); 242 if (!invec) { 243 // failed to read the file, now what? 244 gprint (GP_ERR, "failed to read remote result file : %s\n", table->hosts[i].results); 245 free (table->hosts[i].results); 246 table->hosts[i].results = NULL; 247 continue; 248 } 249 free (table->hosts[i].results); 250 table->hosts[i].results = NULL; 251 252 // fprintf (stderr, "%s : %d\n", table->hosts[i].pathname, invec[0]->Nelements); 253 254 vec = MergeVectors (vec, &Nvec, invec, Ninvec); 255 if (vec != invec) { 256 FreeVectorArray (invec, Ninvec); 257 } 258 } 259 260 for (i = 0; i < Nvec; i++) { 261 AssignVector (vec[i], vec[i]->name, ANYVECTOR, TRUE); 262 } 263 free (vec); 264 265 free (table); 266 return TRUE; 267 }
Note:
See TracChangeset
for help on using the changeset viewer.
