IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 33313


Ignore:
Timestamp:
Feb 20, 2012, 3:07:22 PM (14 years ago)
Author:
eugene
Message:

fixed up mextract -parallel to work correctly; parallel ops now fairly complete

Location:
branches/eam_branches/ipp-20111122/Ohana/src/opihi
Files:
6 edited

Legend:

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

    r33308 r33313  
    3939    remove_argument (N, argc, argv);
    4040    HOSTDIR = strcreate (argv[N]);;
     41    remove_argument (N, argc, argv);
     42  }
     43
     44  // parse -skyregion option (used by most commands)
     45  set_skyregion (0.0, 360.0, -90.0, +90.0);
     46  if ((N = get_argument (*argc, argv, "-skyregion"))) {
     47    if (N + 4 >= *argc) {
     48      gprint (GP_ERR, "USAGE: -skyregion (RA) (RA) (DEC) (DEC)\n");
     49      exit (1);
     50    }
     51    remove_argument (N, argc, argv);
     52    set_skyregion (atof(argv[N]), atof(argv[N+1]), atof(argv[N+2]), atof(argv[N+3]));
     53    remove_argument (N, argc, argv);
     54    remove_argument (N, argc, argv);
     55    remove_argument (N, argc, argv);
     56    remove_argument (N, argc, argv);
     57  }   
     58
     59  // parse -time option
     60  if ((N = get_argument (*argc, argv, "-time"))) {
     61    if (N + 2 >= *argc) {
     62      gprint (GP_ERR, "USAGE: -time (TimeRef) (TimeFormat)\n");
     63      exit (1);
     64    }
     65    remove_argument (N, argc, argv);
     66    set_str_variable ("TIMEREF", argv[N]);
     67    remove_argument (N, argc, argv);
     68    set_str_variable ("TIMEFORMAT", argv[N]);
    4169    remove_argument (N, argc, argv);
    4270  }
  • branches/eam_branches/ipp-20111122/Ohana/src/opihi/dvo/mextract.c

    r33309 r33313  
    22
    33# define DEBUG 1
    4 # define PARALLEL_MANUAL 1
     4# define PARALLEL_MANUAL 0
    55# define PARALLEL_SERIAL 0
    66# define MAX_PATH_LENGTH 1024
     
    88int HostTableLaunchJobs (HostTable *table, char *basecmd);
    99Vector **MergeVectors (Vector **vec, int *Nvec, Vector **invec, int Ninvec);
     10int HostTableParallelOps (int argc, char **argv, char *ResultFile);
    1011
    1112int mextract (int argc, char **argv) {
     
    5657  }
    5758
    58   // XXX not yet thought through (where are these set?)
     59  // init here so free in 'escape' block does not crash
     60  dvo_catalog_init (&catalog, TRUE);
     61
     62  // parse skyregion options.  NOTE: this is stripped off in parallel operation and always
     63  // defined for the client via the -skyregion option.  The dvo_client parses this
     64  // argument in the main program, before it is passed to the command (like mextract)
     65  if ((selection = SetRegionSelection (&argc, argv)) == NULL) goto escape;
     66
     67  // this does all the work of re-packaging the command, calling it on the remote machines, then loading in the results
    5968  if (PARALLEL && !HOST_ID) {
    60     // load the list of hosts
    61     SkyTable *sky = GetSkyTable();
    62     if (!sky) return FALSE;
    63 
    64     char *CATDIR = GetCATDIR ();
    65     if (!CATDIR) return FALSE;
    66 
    67     HostTable *table = HostTableLoad (CATDIR, sky->hosts);
    68     if (!table) {
    69       fprintf (stderr, "ERROR: failure reading Host Table %s for database %s\n", sky->hosts, CATDIR);
    70       return FALSE;
    71     }   
    72 
    73     // other things I need to append?
    74     char *basecmd = paste_args (argc, argv);
    75     double Rmin, Rmax, Dmin, Dmax;
    76     get_skyregion (&Rmin, &Rmax, &Dmin, &Dmax);
    77 
    78     char tmp;
    79     char *command = NULL;
    80     int length = snprintf (&tmp, 0, "%s -D CATDIR %s -skyregion %f %f %f %f", basecmd, CATDIR, Rmin, Rmax, Dmin, Dmax);
    81 
    82     ALLOCATE (command, char, length);
    83     snprintf (command, length, "%s -D CATDIR %s -skyregion %f %f %f %f", basecmd, CATDIR, Rmin, Rmax, Dmin, Dmax);
    84 
    85     // launch this command remotely
    86     HostTableLaunchJobs (table, command);
    87     free (command);
    88 
    89     if (PARALLEL_MANUAL) {
    90       fprintf (stderr, "run the relphot_client commands above.  when these are done, hit return\n");
    91       getchar();
    92     }
    93     if (!PARALLEL_MANUAL && !PARALLEL_SERIAL) {
    94       HostTableWaitJobs (table, __FILE__, __LINE__);
    95     }
    96 
    97     // load fields from file
    98     int    Nvec = 0;
    99     Vector **vec = NULL;
    100     for (i = 0; i < table->Nhosts; i++) {
    101       char resultFile[MAX_PATH_LENGTH];
    102       snprintf (resultFile, MAX_PATH_LENGTH, "%s/dvo.results.fits", table->hosts[i].pathname);
    103        
    104       int    Ninvec = 0;
    105       Vector **invec = ReadVectorTableFITS (resultFile, "MEXTRACT", &Ninvec);
    106 
    107       vec = MergeVectors (vec, &Nvec, invec, Ninvec);
    108       if (vec != invec) {
    109         FreeVectorArray (invec, Ninvec);
    110       }
    111     }
    112 
    113     for (i = 0; i < Nvec; i++) {
    114       AssignVector (vec[i], vec[i]->name, ANYVECTOR, TRUE);
    115     }
    116     free (vec);
    117 
    118     return TRUE;
    119   }
    120 
    121   dvo_catalog_init (&catalog, TRUE);
     69    // not all parallel ops need to set the region selection...
     70    if (!SetSkyRegions (selection)) goto escape;
     71
     72    int status = HostTableParallelOps (argc, argv, ResultFile);
     73    return status;
     74  }
    12275
    12376  /* load photcode information */
     
    12780  // init locally static variables (time refs)
    12881  dbExtractMeasuresInit();
    129 
    130   // parse skyregion options
    131   if ((selection = SetRegionSelection (&argc, argv)) == NULL) goto escape;
    13282
    13383  // command-line is of the form: avextract field,field, field [where (field op value)...]
     
    174124  for (i = 0; !loadImages && (i < Nfields); i++) {
    175125    if (!MEASURE_HAS_XCCD) {
    176       // I'm keeping this code because it gives a way of handing dvo dbs that don't have
     126      // I'm keeping this code because it gives a way of handling dvo dbs that don't have
    177127      // measure.xccd if we need it
    178128      if (fields[i].ID == MEAS_XCCD) loadImages = TRUE;
     
    279229
    280230  for (n = 0; n < Nreturn; n++) {
    281     ResetVector (vec[n], fields[n].type, MAX(0,Npts));
    282   }
    283 
     231    ResetVector (vec[n], fields[n].type, Npts);
     232  }
     233
     234  // write vectors to a table (this is used by parallel dvo operations, but can be used elsewhere)
    284235  if (ResultFile) {
    285     // write vectors to a table
    286     // char *resultFile?
    287     int status = WriteVectorTableFITS (ResultFile, "MEXTRACT", vec, Nreturn, FALSE, NULL);
     236    int status = WriteVectorTableFITS (ResultFile, "RESULT", vec, Nreturn, FALSE, NULL);
    288237    if (!status) goto escape;
    289238  }
     
    443392
    444393    char command[1024];
    445     snprintf (command, 1024, "%s -result %s -hostID %d -hostdir %s", basecmd, resultFile, table->hosts[i].hostID, table->hosts[i].pathname);
    446 
    447     fprintf (stderr, "command: %s\n", command);
     394    snprintf (command, 1024, "dvo_client %s -result %s -hostID %d -hostdir %s", basecmd, resultFile, table->hosts[i].hostID, table->hosts[i].pathname);
     395
     396    if (DEBUG || PARALLEL_MANUAL) fprintf (stderr, "command: %s\n", command);
    448397
    449398    if (PARALLEL_MANUAL) {
     
    488437    myAssert (vec[i]->type == invec[i]->type, "programming error (2)");
    489438
     439    int N = vec[i]->Nelements;
    490440    if (vec[i]->type == OPIHI_FLT) {
    491441      REALLOCATE (vec[i]->elements.Flt, opihi_flt, vec[i]->Nelements + invec[i]->Nelements);
    492442      for (j = 0; j < invec[i]->Nelements; j++) {
    493         vec[i]->elements.Flt[i+j] = vec[i]->elements.Flt[j];
     443        vec[i]->elements.Flt[N+j] = invec[i]->elements.Flt[j];
    494444      }
    495445    } else {
    496446      REALLOCATE (vec[i]->elements.Int, opihi_int, vec[i]->Nelements + invec[i]->Nelements);
    497447      for (j = 0; j < invec[i]->Nelements; j++) {
    498         vec[i]->elements.Int[i+j] = vec[i]->elements.Int[j];
     448        vec[i]->elements.Int[N+j] = invec[i]->elements.Int[j];
    499449      }
    500450    }
     
    503453  return vec;
    504454}
     455
     456int HostTableParallelOps (int argc, char **argv, char *ResultFile) {
     457
     458  int i;
     459
     460  // load the list of hosts
     461  SkyTable *sky = GetSkyTable();
     462  if (!sky) return FALSE;
     463
     464  char *tmppath = GetCATDIR ();
     465  if (!tmppath) return FALSE;
     466
     467  char *CATDIR = abspath (tmppath, MAX_PATH_LENGTH);
     468  if (!CATDIR) return FALSE;
     469
     470  HostTable *table = HostTableLoad (CATDIR, sky->hosts);
     471  if (!table) {
     472    fprintf (stderr, "ERROR: failure reading Host Table %s for database %s\n", sky->hosts, CATDIR);
     473    return FALSE;
     474  }   
     475
     476  // other things I need to append?
     477  char *basecmd = paste_args (argc, argv);
     478
     479  // determine the sky region
     480  double Rmin, Rmax, Dmin, Dmax;
     481  get_skyregion (&Rmin, &Rmax, &Dmin, &Dmax);
     482
     483  // determine time reference and format
     484  char *TimeRef = get_variable ("TIMEREF");
     485  if (!TimeRef) return FALSE;
     486
     487  char *TimeFormat = get_variable ("TIMEFORMAT");
     488  if (!TimeFormat) return FALSE;
     489
     490  char tmp;
     491  char *command = NULL;
     492  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);
     493
     494  ALLOCATE (command, char, length);
     495  snprintf (command, length, "%s -D CATDIR %s -time %s %s -skyregion %f %f %f %f", basecmd, CATDIR, TimeRef, TimeFormat, Rmin, Rmax, Dmin, Dmax);
     496
     497  // launch this command remotely
     498  HostTableLaunchJobs (table, command);
     499  free (command);
     500
     501  if (PARALLEL_MANUAL) {
     502    fprintf (stderr, "run the relphot_client commands above.  when these are done, hit return\n");
     503    getchar();
     504  }
     505  if (!PARALLEL_MANUAL && !PARALLEL_SERIAL) {
     506    HostTableWaitJobs (table, __FILE__, __LINE__);
     507  }
     508
     509  // load fields from file
     510  int    Nvec = 0;
     511  Vector **vec = NULL;
     512  for (i = 0; i < table->Nhosts; i++) {
     513    char resultFile[MAX_PATH_LENGTH];
     514    snprintf (resultFile, MAX_PATH_LENGTH, "%s/dvo.results.fits", table->hosts[i].pathname);
     515       
     516    int    Ninvec = 0;
     517    Vector **invec = ReadVectorTableFITS (resultFile, "RESULT", &Ninvec);
     518
     519    vec = MergeVectors (vec, &Nvec, invec, Ninvec);
     520    if (vec != invec) {
     521      FreeVectorArray (invec, Ninvec);
     522    }
     523  }
     524
     525  // write vectors to a table (this is used by parallel dvo operations, but can be used elsewhere)
     526  if (ResultFile) {
     527    int status = WriteVectorTableFITS (ResultFile, "RESULT", vec, Nvec, FALSE, NULL);
     528    if (!status) return FALSE;
     529  }
     530
     531  for (i = 0; i < Nvec; i++) {
     532    AssignVector (vec[i], vec[i]->name, ANYVECTOR, TRUE);
     533  }
     534  free (vec);
     535
     536  return TRUE;
     537}
  • branches/eam_branches/ipp-20111122/Ohana/src/opihi/dvo/region_list.c

    r33309 r33313  
    131131  selection[0].useSkyregion = TRUE;
    132132  return selection;
     133}
     134
     135/* given possible options (by name, by list, by graph region), select SkyRegions */
     136int SetSkyRegions (SkyRegionSelection *selection) {
     137
     138  if (selection->name != NULL) {
     139    gprint (GP_ERR, "name-based selection not yet implemented (in parallel mode)\n");
     140    return FALSE;
     141  }
     142
     143  if (selection->list != NULL) {
     144    gprint (GP_ERR, "list-based selection not yet implemented (in parallel mode)\n");
     145    return FALSE;
     146  }
     147
     148  if (selection->useDisplay) {
     149    double Rmin, Rmax, Dmin, Dmax, Radius;
     150    Graphdata graphsky;
     151
     152    if (!GetGraphdata (&graphsky, NULL, NULL)) {
     153      gprint (GP_ERR, "region display not available\n");
     154      return FALSE;
     155    }
     156    Radius = MAX (fabs(graphsky.xmax), fabs(graphsky.ymax));
     157    Dmin = graphsky.coords.crval2 - Radius;
     158    Dmax = graphsky.coords.crval2 + Radius;
     159   
     160    if ((Dmin <= -89) || (Dmax >= 89)) {
     161      Rmin = 0;
     162      Rmax = 360;
     163    } else {
     164      double Rmod = MAX (Radius / (cos(Dmin*RAD_DEG)), Radius / (cos(Dmax*RAD_DEG)));
     165      Rmin = graphsky.coords.crval1 - Rmod;
     166      Rmax = graphsky.coords.crval1 + Rmod;
     167    }
     168
     169    set_skyregion (Rmin, Rmax, Dmin, Dmax);
     170    return TRUE;
     171  }
     172  if (selection->useSkyregion) {
     173    return TRUE;
     174  }
     175  return FALSE;
    133176}
    134177
  • branches/eam_branches/ipp-20111122/Ohana/src/opihi/include/dvoshell.h

    r33308 r33313  
    329329int           SelectMags            PROTO((int Nphot, int Tphot, int Ns, Average *average, Measure *measure, SecFilt *secfilt, int UL));
    330330
     331int           SetSkyRegions         PROTO((SkyRegionSelection *selection));
    331332SkyList      *SelectRegions         PROTO((SkyRegionSelection *selection));
    332333SkyList      *SkyListLoadFile       PROTO((char *filename));
  • branches/eam_branches/ipp-20111122/Ohana/src/opihi/lib.shell/VectorIO.c

    r33309 r33313  
    123123 
    124124  Header header;
    125   Header theader;
    126125  FTable ftable;
    127126
     
    186185        snprintf (vec[Nvec + j]->name, OPIHI_NAME_SIZE, "%s:%d", name, j);
    187186      }
    188       ResetVector (vec[Nvec + j], vecType, MAX (Nrows,1));
     187      ResetVector (vec[Nvec + j], vecType, Nrows);
    189188    }
    190189
     
    215214  }
    216215
    217   gfits_free_header (&theader);
     216  gfits_free_header (&header);
    218217  gfits_free_table (&ftable);
    219218
  • branches/eam_branches/ipp-20111122/Ohana/src/opihi/lib.shell/VectorOps.c

    r33309 r33313  
    185185  if (in[0].elements.Ptr) {
    186186    if (in[0].type == OPIHI_FLT) {
    187       ALLOCATE (out[0].elements.Flt, opihi_flt, out[0].Nelements);
     187      ALLOCATE (out[0].elements.Flt, opihi_flt, MAX(1,out[0].Nelements));
    188188      memcpy (out[0].elements.Flt, in[0].elements.Flt, out[0].Nelements*sizeof(opihi_flt));
    189189      out[0].type = OPIHI_FLT;
    190190    } else {
    191       ALLOCATE (out[0].elements.Int, opihi_int, out[0].Nelements);
     191      ALLOCATE (out[0].elements.Int, opihi_int, MAX(1,out[0].Nelements));
    192192      memcpy (out[0].elements.Int, in[0].elements.Int, out[0].Nelements*sizeof(opihi_int));
    193193      out[0].type = OPIHI_INT;
     
    201201  out[0].Nelements = in[0].Nelements;
    202202  if (type == OPIHI_FLT) {
    203     ALLOCATE (out[0].elements.Flt, opihi_flt, out[0].Nelements);
     203    ALLOCATE (out[0].elements.Flt, opihi_flt, MAX(1,out[0].Nelements));
    204204    out[0].type = OPIHI_FLT;
    205205  } else {
    206     ALLOCATE (out[0].elements.Int, opihi_int, out[0].Nelements);
     206    ALLOCATE (out[0].elements.Int, opihi_int, MAX(1,out[0].Nelements));
    207207    out[0].type = OPIHI_INT;
    208208  }
     
    210210}
    211211
    212 // ResetVector (vecx, OPIHI_FLT, MAX (Npts, 1));
    213212int ResetVector (Vector *vec, char type, int Nelements) {
    214213
    215   vec[0].Nelements = Nelements;
     214  // a vector can only have >= 0 elements
     215  vec[0].Nelements = MAX(Nelements,0);
    216216  if (type == OPIHI_FLT) {
    217217    REALLOCATE (vec[0].elements.Flt, opihi_flt, MAX(1, Nelements));
     
    227227int SetVector (Vector *vec, char type, int Nelements) {
    228228
    229   vec[0].Nelements = Nelements;
     229  vec[0].Nelements = MAX(Nelements,0);
    230230  if (type == OPIHI_FLT) {
    231     ALLOCATE (vec[0].elements.Flt, opihi_flt, Nelements);
     231    ALLOCATE (vec[0].elements.Flt, opihi_flt, MAX(1,Nelements));
    232232    vec[0].type = OPIHI_FLT;
    233233  } else {
    234     ALLOCATE (vec[0].elements.Int, opihi_int, Nelements);
     234    ALLOCATE (vec[0].elements.Int, opihi_int, MAX(1,Nelements));
    235235    vec[0].type = OPIHI_INT;
    236236  }
Note: See TracChangeset for help on using the changeset viewer.