IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Feb 18, 2012, 8:44:13 PM (14 years ago)
Author:
eugene
Message:

some support functions for dvo_client; mextract example nearly complete

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20111122/Ohana/src/opihi/dvo/mextract.c

    r33305 r33308  
    11# include "dvoshell.h"
     2
     3# define DEBUG 1
     4# define PARALLEL_MANUAL 1
     5# define PARALLEL_SERIAL 0
     6# define MAX_PATH_LENGTH 1024
    27
    38int mextract (int argc, char **argv) {
     
    3439  }
    3540
     41  int PARALLEL = FALSE;
     42  if ((N = get_argument (argc, argv, "-parallel"))) {
     43    remove_argument (N, &argc, argv);
     44    PARALLEL = TRUE;
     45  }
     46
     47  // dump results directly to fits file (esp for parallel dvo)
     48  char *ResultFile = NULL;
     49  if ((N = get_argument (argc, argv, "-result"))) {
     50    remove_argument (N, &argc, argv);
     51    ResultFile = strcreate(argv[N]);
     52    remove_argument (N, &argc, argv);
     53  }
     54
    3655  // XXX not yet thought through (where are these set?)
    3756  if (PARALLEL && !HOST_ID) {
    38     HostTableLaunchJobs (CATDIR, argc, argv);
    39     HostTableWaitJobs (table, __FILE__, __LINE__);
     57    // load the list of hosts
     58    SkyTable *sky = GetSkyTable();
     59    if (!sky) return FALSE;
     60
     61    char *CATDIR = GetCATDIR ();
     62    if (!CATDIR) return FALSE;
     63
     64    HostTable *table = HostTableLoad (CATDIR, sky->hosts);
     65    if (!table) {
     66      fprintf (stderr, "ERROR: failure reading Host Table %s for database %s\n", sky->hosts, CATDIR);
     67      return FALSE;
     68    }   
     69
     70    // other things I need to append?
     71    char *basecmd = paste_args (argc, argv);
     72    double Rmin, Rmax, Dmin, Dmax;
     73    get_skyregion (&Rmin, &Rmax, &Dmin, &Dmax);
     74
     75    char tmp;
     76    char *command = NULL;
     77    int length = snprintf (&tmp, 0, "%s -D CATDIR %s -skyregion %f %f %f %f", basecmd, CATDIR, Rmin, Rmax, Dmin, Dmax);
     78
     79    ALLOCATE (command, char, length);
     80    snprintf (command, length, "%s -D CATDIR %s -skyregion %f %f %f %f", basecmd, CATDIR, Rmin, Rmax, Dmin, Dmax);
     81
     82    // launch this command remotely
     83    HostTableLaunchJobs (table, command);
     84    free (command);
     85
     86    if (PARALLEL_MANUAL) {
     87      fprintf (stderr, "run the relphot_client commands above.  when these are done, hit return\n");
     88      getchar();
     89    }
     90    if (!PARALLEL_MANUAL && !PARALLEL_SERIAL) {
     91      HostTableWaitJobs (table, __FILE__, __LINE__);
     92    }
    4093
    4194    // load fields from file
    42     ReadVectorTables
     95    // ReadVectorTables
    4396    return TRUE;
    4497  }
     
    132185  for (i = 0; (i < skylist[0].Nregions) && !interrupt; i++) {
    133186
    134     // XXX parallel case, wrong client
     187    // parallel case, wrong client
    135188    if (HOST_ID && (HOST_ID != skylist[0].regions[i]->hostID)) continue;
    136189
    137190    /* lock, load, unlock catalog */
    138     catalog.filename = skylist[0].filename[i];
     191    char hostfile[1024];
     192    snprintf (hostfile, 1024, "%s/%s.cpt", HOSTDIR, skylist[0].regions[i]->name);
     193    catalog.filename = HOST_ID ? hostfile : skylist[0].filename[i];
    139194    catalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_SECF;
    140195    catalog.Nsecfilt = Nsecfilt;
     
    205260  }
    206261
    207   if (HOST_ID) {
    208     // write table
    209     WriteVectorTable (vec);
    210     return TRUE;
     262  if (ResultFile) {
     263    // write vectors to a table
     264    // char *resultFile?
     265    int status = WriteVectorTableFITS (ResultFile, "MEXTRACT", vec, Nreturn, FALSE, NULL);
     266    if (!status) goto escape;
    211267  }
    212268
     
    222278
    223279escape:
     280  if (ResultFile) free (ResultFile);
    224281  if (vec) free (vec);
    225282  free (values);
     
    349406  return (FALSE);
    350407}
     408
     409int HostTableLaunchJobs (HostTable *table, char *basecmd) {
     410
     411  int i;
     412  for (i = 0; i < table->Nhosts; i++) {
     413
     414    // ensure that the paths are absolute path names
     415    char *tmppath = abspath (table->hosts[i].pathname, MAX_PATH_LENGTH);
     416    free (table->hosts[i].pathname);
     417    table->hosts[i].pathname = tmppath;
     418
     419    char resultFile[MAX_PATH_LENGTH];
     420    snprintf (resultFile, MAX_PATH_LENGTH, "%s/dvo.results.fits", table->hosts[i].pathname);
     421
     422    char command[1024];
     423    snprintf (command, 1024, "%s -result %s -hostID %d -hostdir %s", basecmd, resultFile, table->hosts[i].hostID, table->hosts[i].pathname);
     424
     425    fprintf (stderr, "command: %s\n", command);
     426
     427    if (PARALLEL_MANUAL) {
     428      continue;
     429    }
     430
     431    if (PARALLEL_SERIAL) {
     432      int status = system (command);
     433      if (status) {
     434        fprintf (stderr, "ERROR running relphot_client\n");
     435        exit (2);
     436      }
     437    } else {
     438      // launch the job on the remote machine (no handshake)
     439      int errorInfo = 0;
     440      int pid = rconnect ("ssh", table->hosts[i].hostname, command, table->hosts[i].stdio, &errorInfo, FALSE);
     441      if (!pid) {
     442        if (DEBUG) fprintf (stderr, "failure to start %s (error %d)\n", table->hosts[i].hostname, errorInfo);
     443        exit (1);
     444      }
     445      table->hosts[i].pid = pid; // save for future reference
     446    }
     447  }
     448  return TRUE;
     449}
     450
Note: See TracChangeset for help on using the changeset viewer.