- Timestamp:
- Mar 16, 2012, 7:51:21 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20111122/Ohana/src/opihi/dvo/mextract.c
r33520 r33543 1 1 # include "dvoshell.h" 2 3 # define DEBUG 04 # define PARALLEL_MANUAL 05 # define PARALLEL_SERIAL 06 # define MAX_PATH_LENGTH 10247 8 int HostTableLaunchJobs (HostTable *table, char *basecmd);9 Vector **MergeVectors (Vector **vec, int *Nvec, Vector **invec, int Ninvec);10 int HostTableParallelOps (int argc, char **argv, char *ResultFile);11 2 12 3 int mextract (int argc, char **argv) { … … 77 68 if (!SetSkyRegions (selection)) goto escape; 78 69 79 int status = HostTableParallelOps (argc, argv, ResultFile );70 int status = HostTableParallelOps (argc, argv, ResultFile, 0); 80 71 return status; 81 72 } … … 161 152 162 153 // does this host ID match the desired location for the table? 163 if ( !HostTableTestHost(skylist[0].regions[i], HOST_ID)) continue;154 if (PARALLEL && !HostTableTestHost(skylist[0].regions[i], HOST_ID)) continue; 164 155 165 156 /* lock, load, unlock catalog */ … … 380 371 return (FALSE); 381 372 } 382 383 int HostTableLaunchJobs (HostTable *table, char *basecmd) {384 385 int i;386 for (i = 0; i < table->Nhosts; i++) {387 388 // ensure that the paths are absolute path names389 char *tmppath = abspath (table->hosts[i].pathname, MAX_PATH_LENGTH);390 free (table->hosts[i].pathname);391 table->hosts[i].pathname = tmppath;392 393 char resultFile[MAX_PATH_LENGTH];394 snprintf (resultFile, MAX_PATH_LENGTH, "%s/dvo.results.fits", table->hosts[i].pathname);395 396 char command[1024];397 snprintf (command, 1024, "dvo_client %s -result %s -hostID %d -hostdir %s", basecmd, resultFile, table->hosts[i].hostID, table->hosts[i].pathname);398 399 if (DEBUG || PARALLEL_MANUAL) fprintf (stderr, "command: %s\n", command);400 401 if (PARALLEL_MANUAL) {402 continue;403 }404 405 if (PARALLEL_SERIAL) {406 int status = system (command);407 if (status) {408 fprintf (stderr, "ERROR running relphot_client\n");409 exit (2);410 }411 } else {412 // launch the job on the remote machine (no handshake)413 int errorInfo = 0;414 int pid = rconnect ("ssh", table->hosts[i].hostname, command, table->hosts[i].stdio, &errorInfo, FALSE);415 if (!pid) {416 if (DEBUG) fprintf (stderr, "failure to start %s (error %d)\n", table->hosts[i].hostname, errorInfo);417 exit (1);418 }419 table->hosts[i].pid = pid; // save for future reference420 }421 }422 return TRUE;423 }424 425 // take two arrays of vectors and merge equal named vectors.426 // for ease, require that the order of the names match & number of vectors match427 Vector **MergeVectors (Vector **vec, int *Nvec, Vector **invec, int Ninvec) {428 429 int i, j;430 431 if (vec == NULL) {432 *Nvec = Ninvec;433 return invec;434 }435 436 myAssert (*Nvec == Ninvec, "programming error (1)");437 438 for (i = 0; i < Ninvec; i++) {439 myAssert (!strcmp(vec[i]->name, invec[i]->name), "programming error (2)");440 myAssert (vec[i]->type == invec[i]->type, "programming error (2)");441 442 int N = vec[i]->Nelements;443 if (vec[i]->type == OPIHI_FLT) {444 REALLOCATE (vec[i]->elements.Flt, opihi_flt, vec[i]->Nelements + invec[i]->Nelements);445 for (j = 0; j < invec[i]->Nelements; j++) {446 vec[i]->elements.Flt[N+j] = invec[i]->elements.Flt[j];447 }448 } else {449 REALLOCATE (vec[i]->elements.Int, opihi_int, vec[i]->Nelements + invec[i]->Nelements);450 for (j = 0; j < invec[i]->Nelements; j++) {451 vec[i]->elements.Int[N+j] = invec[i]->elements.Int[j];452 }453 }454 vec[i]->Nelements += invec[i]->Nelements;455 }456 return vec;457 }458 459 int HostTableParallelOps (int argc, char **argv, char *ResultFile) {460 461 int i;462 463 // load the list of hosts464 SkyTable *sky = GetSkyTable();465 if (!sky) {466 gprint (GP_ERR, "failed to load sky table for database\n");467 return FALSE;468 }469 470 char *tmppath = GetCATDIR ();471 if (!tmppath) {472 gprint (GP_ERR, "failed to get CATDIR for database\n");473 return FALSE;474 }475 476 char *CATDIR = abspath (tmppath, MAX_PATH_LENGTH);477 if (!CATDIR) {478 gprint (GP_ERR, "failed to make an absolute path from %s (too long)\n", tmppath);479 return FALSE;480 }481 482 HostTable *table = HostTableLoad (CATDIR, sky->hosts);483 if (!table) {484 gprint (GP_ERR, "ERROR: failure reading Host Table %s for database %s\n", sky->hosts, CATDIR);485 return FALSE;486 }487 488 // other things I need to append?489 char *basecmd = paste_args (argc, argv);490 491 // determine the sky region492 double Rmin, Rmax, Dmin, Dmax;493 get_skyregion (&Rmin, &Rmax, &Dmin, &Dmax);494 495 // determine time reference and format496 char *TimeRef = get_variable ("TIMEREF");497 if (!TimeRef) {498 gprint (GP_ERR, "failed to find TIMEREF variable\n");499 return FALSE;500 }501 502 char *TimeFormat = get_variable ("TIMEFORMAT");503 if (!TimeFormat) {504 gprint (GP_ERR, "failed to find TIMEFORMAT variable\n");505 return FALSE;506 }507 508 char tmp;509 char *command = NULL;510 int length = snprintf (&tmp, 0, "%s -D CATDIR %s -time %s %s -skyregion %f %f %f %f", basecmd, CATDIR, TimeRef, TimeFormat, Rmin, Rmax, Dmin, Dmax);511 512 ALLOCATE (command, char, length);513 snprintf (command, length, "%s -D CATDIR %s -time %s %s -skyregion %f %f %f %f", basecmd, CATDIR, TimeRef, TimeFormat, Rmin, Rmax, Dmin, Dmax);514 515 // launch this command remotely516 HostTableLaunchJobs (table, command);517 free (command);518 519 if (PARALLEL_MANUAL) {520 gprint (GP_ERR, "run the relphot_client commands above. when these are done, hit return\n");521 getchar();522 }523 if (!PARALLEL_MANUAL && !PARALLEL_SERIAL) {524 HostTableWaitJobsGetIO (table, __FILE__, __LINE__);525 }526 527 // load fields from file528 int Nvec = 0;529 Vector **vec = NULL;530 for (i = 0; i < table->Nhosts; i++) {531 if (table->hosts[i].status) continue;532 533 char resultFile[MAX_PATH_LENGTH];534 snprintf (resultFile, MAX_PATH_LENGTH, "%s/dvo.results.fits", table->hosts[i].pathname);535 536 int Ninvec = 0;537 Vector **invec = ReadVectorTableFITS (resultFile, "RESULT", &Ninvec);538 539 vec = MergeVectors (vec, &Nvec, invec, Ninvec);540 if (vec != invec) {541 FreeVectorArray (invec, Ninvec);542 }543 }544 545 // write vectors to a table (this is used by parallel dvo operations, but can be used elsewhere)546 if (ResultFile) {547 int status = WriteVectorTableFITS (ResultFile, "RESULT", vec, Nvec, FALSE, NULL);548 if (!status) {549 gprint (GP_ERR, "failed to write result file %s\n", ResultFile);550 return FALSE;551 }552 }553 554 for (i = 0; i < Nvec; i++) {555 AssignVector (vec[i], vec[i]->name, ANYVECTOR, TRUE);556 }557 free (vec);558 559 return TRUE;560 }
Note:
See TracChangeset
for help on using the changeset viewer.
