Ejemplo n.º 1
0
int main(int argc, char **argv) {
  int n,i,j;
  double **a;
  double *b, count=1.0;
  unsigned int t1,t2;
  MAIN_INITENV
  if (argc!=2) {
     printf("Usage: bksb <size>\nAborting...\n");
     exit(0);
  }
  n = atoi(argv[1]);
  a = (double**)G_MALLOC(n*sizeof(double*));
  for(i = 0; i < n; i++) {
    a[i] = (double*)G_MALLOC(n*sizeof(double));
    for(j = i;j < n;j++) {
       a[i][j] = count;
       count++;
    }
  }
  b = (double*)G_MALLOC(n*sizeof(double));
  for(i = 0; i < n; i++) {
    b[i] = count;
    count++;
  }
  CLOCK(t1)
  bksb(a,b,n);
  CLOCK(t2)
  printf("Elapsed: %u microseconds\n",t2-t1);
  for(i = 0; i < n; i++) printf("%lf ", b[i]);
  printf("\n");
  MAIN_END
  return 0;
}
Ejemplo n.º 2
0
/*
 *  InitGlobalMemory ()
 *
 *  Args : none.
 *
 *  Returns : nothing.
 *
 *  Side Effects : Allocates all the global storage for G_Memory.
 *
 */
void
InitGlobalMemory ()
{
   int i;

   G_Memory = (g_mem *) G_MALLOC(sizeof(g_mem));
   G_Memory->i_array = (int *) G_MALLOC(Number_Of_Processors * sizeof(int));
   G_Memory->d_array = (double *) G_MALLOC(Number_Of_Processors
					 * sizeof(double));
   if (G_Memory == NULL) {
      printf("Ran out of global memory in InitGlobalMemory\n");
      exit(-1);
   }
   G_Memory->count = 0;
   G_Memory->id = 0;
   LOCKINIT(G_Memory->io_lock);
   LOCKINIT(G_Memory->mal_lock);
   LOCKINIT(G_Memory->single_lock);
   LOCKINIT(G_Memory->count_lock);
   ALOCKINIT(G_Memory->lock_array, MAX_LOCKS);
   BARINIT(G_Memory->synch);
   BARINIT(G_Memory->done_barrier);
   G_Memory->max_x = -MAX_REAL;
   G_Memory->min_x = MAX_REAL;
   G_Memory->max_y = -MAX_REAL;
   G_Memory->min_y = MAX_REAL;
}
Ejemplo n.º 3
0
void nqueens(int i, char **currentBoard, int currentProfit, int numQ, int maxProfit[], int maxProfIndex) {
  register int j;
  int n = gm->n;
  char ** maxBoard = gm->maxBoard;

  if (i < n) {
    for (j = 0; j < n; j++) {
      if (canPlace(i, j, currentBoard)) {
        // Creating a new board
        register int x,y;
        char **newBoard;
        newBoard = (char**)G_MALLOC(n*sizeof(char*));
        for (x = 0; x < n; x++) {
          newBoard[x] = (char*)G_MALLOC(n*sizeof(char*));
          for (y = 0; y < n; y++) newBoard[x][y] = currentBoard[x][y];
        }

        newBoard[i][j] = 1;
        int profitAdd = abs(i - j);
        nqueens(i + 1, newBoard, currentProfit + profitAdd, numQ + 1, maxProfit, maxProfIndex);
      }
    }
  }
  else {
    gm->total = gm->total + 1;
    if (currentProfit > maxProfit[maxProfIndex]) {
      maxProfit[maxProfIndex] = currentProfit;
      gm->global_max_profit = currentProfit;
      for (i = 0; i < n; i++)
        for (j = 0; j < n; j++)
          gm->maxBoard[i][j] = currentBoard[i][j];
    }
  }
}
Ejemplo n.º 4
0
void
CreateParticleList (int my_id, int length)
{
    int cluster_no;

    LOCK(G_Memory->mal_lock);
    Local[my_id].Particles = (particle **) G_MALLOC(length
                             * sizeof(particle *));

    /* POSSIBLE ENHANCEMENT:  Here is where one might distribute the
       Particles data across physically distributed memories as desired.

       One way to do this is as follows:

       char *starting_address;
       char *ending_address;

       starting_address = (char *) Local[my_id].Particles;
       ending_address = (((char *) Local[my_id].Particles)
    		     + (length * sizeof(particle *)) - 1);

       Place all addresses x such that (starting_address <= x < ending_address)
       on node my_id

    */

    UNLOCK(G_Memory->mal_lock);
    Local[my_id].Max_Particles = length;
    Local[my_id].Num_Particles = 0;
}
Ejemplo n.º 5
0
int main (int argc, char **argv) {
  int i, j, p, n;
  int total;
  char **maxBoard;
  char **initialBoard;
  unsigned int t1, t2, t3;

  MAIN_INITENV
  //Enforce arguments

  if (argc != 2) {
    printf("Usage: nqueens-seq <N>\nAborting.\n");
    exit(0);
  }
  gm = (GM*)G_MALLOC(sizeof(GM)); 
  gm->p = 8;
  gm->n = atoi(argv[1]); 
  n = gm->n;
  gm->total = 0;
  gm->maxBoard = (char**)G_MALLOC(n*sizeof(char*));
  gm->initialBoard = (char**)G_MALLOC(n*sizeof(char*));
  gm->global_max_profit = 0;

  for (i = 0; i < n; i++) {
    gm->maxBoard[i] = (char*)G_MALLOC(n*sizeof(char));
    gm->initialBoard[i] = (char*)G_MALLOC(n*sizeof(char));
    for (j = i; j < n; j++) {
      gm->maxBoard[i][j] = 0;
      gm->initialBoard[i][j] = 0;
    }
  }

  CLOCK(t1)
  for(i = 0; i < n; i++)
    CREATE(nqueens_wrapper)
  WAIT_FOR_END(n);
  CLOCK(t2)
  
  printf("Printing maximum profit board\n");
  printBoard(gm->maxBoard, gm->global_max_profit);
  CLOCK(t3)
  
  printf("Computation time: %u microseconds\n", t2-t1);
  printf("Printing time:    %u microseconds\n", t3-t2);
  MAIN_END
  return 0;
}
Ejemplo n.º 6
0
PlaceInfoContainer* cap_psnewpl(PlacementSetContainer *placements, int *iret)
/*****************************************************************************
 * cap_psnewpl
 *
 * Returns a PlaceInfoContainer.  If there is an unused container in the 
 * set, that is returned, otherwise a new one is allocated from memory.
 *
 * Input parameters:
 *  *placements PlacementSetContainer   PlacmentInfoContainer to add to
 *
 * Output parameters:
 *  *iret    int    Return code
 *                      0 = Function successful
 *                     -1 = Invalid pointer in argument list
 *                     -3 = Could not allocate memory
 **
 * Log:
 * S.Danz/AWC            2/06   Created
 ****************************************************************************/
{
    int	one=1;
    PlaceInfoContainer  *newplace = (PlaceInfoContainer*)NULL;
/*---------------------------------------------------------------------*/

    if (!placements) {
        *iret = -1;
        return newplace;
    }

    *iret = 0;
    if (placements->places && 
        placements->used < placements->total && 
        placements->places[placements->used] != NULL) {
        newplace = placements->places[placements->used];
        cap_plclear(newplace);
    } else {
        G_MALLOC(newplace, PlaceInfoContainer, one,
                "creating new placement container");

        if (newplace) {
            cap_plclear(newplace);
        } else {
            *iret = -3;
        }
    }

    return newplace;
}
Ejemplo n.º 7
0
int main(int argc,char **argv) {
  int i,j,p,n;
  double **a,*b, count=1.0;
  unsigned int t1,t2;
  MAIN_INITENV
  if (argc!=3) {
     printf("Usage: pbksb P N\nAborting...\n");
     exit(0);
  }
  gm = (GM*)G_MALLOC(sizeof(GM));
  p = gm->p = atoi(argv[1]);
  gm->n = atoi(argv[2]);
  assert(p > 0);
  assert(p <= 8);
  n = gm->n;
  a = gm->a = (double**)G_MALLOC(n*sizeof(double*));
  for(i = 0; i < n; i++) {
    a[i] = (double*)G_MALLOC(n*sizeof(double));
    for(j = i;j < n;j++){
       a[i][j] = count;
       count++;
    }
  }

  //-----------------------------------------------
  // Create 1D array a_prime and map a to a_prime
  //-----------------------------------------------
  gm->a_prime = (double*)G_MALLOC((n+1)*n/2*sizeof(double))
  mapping();

  b = gm->b = (double*)G_MALLOC(n*sizeof(double));
  for(i = 0; i < n; i++) {
    b[i] = count;
    count++;
  }
  gm->pse = (char*)G_MALLOC(n*sizeof(char));
  for(i = 0; i < n; i++)
    CLEARPAUSE(gm->pse[i])
  for(i = 0; i < p-1; i++)
    CREATE(pbksb)
  CLOCK(t1)
  pbksb();
  WAIT_FOR_END(p-1)
  CLOCK(t2)
  printf("Elapsed: %u us\n",t2-t1);
  for(i = 0; i < n; i++) printf("%lf ", gm->b[i]);
  printf("\n");
  for(i = 0; i < n; i++)
    G_FREE(a[i],n*sizeof(double))
  G_FREE(a,n*sizeof(double*))
  G_FREE(b,n*sizeof(double))
  G_FREE(gm->a_prime, (n+1)*n/2*sizeof(double))
  MAIN_END
  return 0;
}
Ejemplo n.º 8
0
void cmd_osnew(CMDObjectSet *objects, int *iret)
/*****************************************************************************
 * cmd_osnew
 *
 * Creates an empty CMDObjectSet and any associated structures
 *
 * Input parameters:
 *
 * Output parameters:
 *  *placements  PlacementSet    Placement set to create
 *  *iret       int     Return code
 *                      0 = Function successful
 *                     -1 = Invalid pointer to store result
 *                     -2 = Could not allocate memory
 **
 * Log:
 * S.Danz/AWC            2/06   Created
 ****************************************************************************/
{
    int	one=1;
    CMDObjectSetContainer   *o;
/*---------------------------------------------------------------------*/

    if (objects) {
        G_MALLOC(o, CMDObjectSetContainer, one, "creating new object set");
        *objects = (CMDObjectSet*)o;
        if (o) {
            *iret = 0;
            memset(o, 0, sizeof(CMDObjectSetContainer));
        } else {
            *iret = -2;
        }
    } else {
        *iret = -1;
    }
}
Ejemplo n.º 9
0
void
CreateBoxes (long my_id, long num_boxes)
{
   long i;

   LOCK(G_Memory->mal_lock);
   Local[my_id].B_Heap = (box *) G_MALLOC(num_boxes * sizeof(box));

/* POSSIBLE ENHANCEMENT:  Here is where one might distribute the
   B_Heap data across physically distributed memories as desired.

   One way to do this is as follows:

   char *starting_address;
   char *ending_address;

   starting_address = (char *) Local[my_id].B_Heap;
   ending_address = (((char *) Local[my_id].B_Heap)
		     + (num_boxes * sizeof(particle *)) - 1);

   Place all addresses x such that (starting_address <= x < ending_address)
   on node my_id

*/

   UNLOCK(G_Memory->mal_lock);
   Local[my_id].Max_B_Heap = num_boxes;
   Local[my_id].Index_B_Heap = 0;

   for (i = 0; i < num_boxes; i++) {
      Local[my_id].B_Heap[i].exp_lock_index = i % (MAX_LOCKS - 1);
      Local[my_id].B_Heap[i].particle_lock_index = i % (MAX_LOCKS - 1);
      Local[my_id].B_Heap[i].id = i + ((double) my_id / ID_LIMIT);
      ZeroBox(my_id, &Local[my_id].B_Heap[i]);
   }
}
Ejemplo n.º 10
0
	  Global->treebuildtime - Global->forcecalctime,
	  ((float)(Global->tracktime-Global->partitiontime-
		   Global->treebuildtime-Global->forcecalctime))/
	  Global->tracktime);
   MAIN_END;
}

/*
 * ANLINIT : initialize ANL macros
 */
void ANLinit()
{
   MAIN_INITENV(,70000000,);
   /* Allocate global, shared memory */

   Global = (struct GlobalMemory *) G_MALLOC(sizeof(struct GlobalMemory));

   if (Global==NULL) error("No initialization for Global\n");

   BARINIT(Global->Barrier, NPROC);

   LOCKINIT(Global->CountLock);
   LOCKINIT(Global->io_lock);
}

/*
 * INIT_ROOT: Processor 0 reinitialize the global root at each time step
 */
void init_root()
{
   long i;
Ejemplo n.º 11
0
void
CreateDistribution (cluster_type cluster, model_type model)
{
    particle *particle_array;
    int global_num_particles;
    particle *new_particle;
    char particle_state[RANDOM_SIZE];
    real charge;
    real r_scale;
    real v_scale;
    vector r_sum;
    vector v_sum;
    int end_limit;
    int i;
    int j;
    real temp_r;
    real radius;
    real x_vel;
    real y_vel;
    real vel;
    real offset;
    particle *twin_particle;

    particle_array = (particle *) G_MALLOC(Total_Particles * sizeof(particle));

    Particle_List = (particle **) G_MALLOC(Total_Particles * sizeof(particle *));
    for (i = 0; i < Total_Particles; i++)
        Particle_List[i] = &particle_array[i];

    r_scale = 3 * M_PI / 16;
    v_scale = (real) sqrt(1.0 / (double) r_scale);
    r_sum.x = (real) 0.0;
    r_sum.y = (real) 0.0;
    v_sum.x = (real) 0.0;
    v_sum.y = (real) 0.0;
    initstate(0, particle_state, RANDOM_SIZE);

    switch (cluster) {
    case ONE_CLUSTER:
        end_limit = Total_Particles;
        switch (model) {
        case UNIFORM:
            printf("Creating a one cluster, uniform distribution for %d ",
                   Total_Particles);
            printf("particles\n");
            break;
        case PLUMMER:
            printf("Creating a one cluster, non uniform distribution for %d ",
                   Total_Particles);
            printf("particles\n");
            break;
        }
        break;
    case TWO_CLUSTER:
        end_limit = (Total_Particles / 2) + (Total_Particles & 0x1);
        switch (model) {
        case UNIFORM:
            printf("Creating a two cluster, uniform distribution for %d ",
                   Total_Particles);
            printf("particles\n");
            break;
        case PLUMMER:
            printf("Creating a two cluster, non uniform distribution for %d ",
                   Total_Particles);
            printf("particles\n");
            break;
        }
        break;
    }
    setstate(particle_state);
    global_num_particles = 0;
    charge = 1.0 / Total_Particles;
    charge /= Total_Particles;
    for (i = 0; i < end_limit; i++) {
        new_particle = InitParticle(charge, charge);
        switch (model) {
        case UNIFORM:
            do {
                new_particle->pos.x = XRand(-1.0, 1.0);
                new_particle->pos.y = XRand(-1.0, 1.0);
                temp_r = DOT_PRODUCT((new_particle->pos), (new_particle->pos));
            }
            while (temp_r > (real) 1.0);
            radius = sqrt(temp_r);
            break;
        case PLUMMER:
            do
                radius = (real) 1.0 / (real) sqrt(pow(XRand(0.0, MAX_FRAC),
                                                      -2.0/3.0) - 1);
            while (radius > 9.0);
            PickShell(&(new_particle->pos), r_scale * radius);
            break;
        }
        VECTOR_ADD(r_sum, r_sum, (new_particle->pos));

        do {
            x_vel = XRand(0.0, 1.0);
            y_vel = XRand(0.0, 0.1);
        }
        while (y_vel > x_vel * x_vel * (real) pow(1.0 - (x_vel * x_vel), 3.5));
        vel = (real) sqrt(2.0) * x_vel / pow(1.0 + (radius * radius), 0.25);
        PickShell(&(new_particle->vel), v_scale * vel);
        VECTOR_ADD(v_sum, v_sum, (new_particle->vel));
    }

    if (cluster == TWO_CLUSTER) {
        switch (model) {
        case UNIFORM:
            offset = 1.5;
            break;
        case PLUMMER:
            offset = 2.0;
            break;
        }
        for (i = end_limit; i < Total_Particles; i++) {
            new_particle = InitParticle(charge, charge);
            twin_particle = Particle_List[i - end_limit];
            new_particle->pos.x = twin_particle->pos.x + offset;
            new_particle->pos.y = twin_particle->pos.y + offset;
            VECTOR_ADD(r_sum, r_sum, (new_particle->pos));
            new_particle->vel.x = twin_particle->vel.x;
            new_particle->vel.y = twin_particle->vel.y;
            VECTOR_ADD(v_sum, v_sum, (new_particle->vel));
        }
    }

    VECTOR_DIV(r_sum, r_sum, (real) Total_Particles);
    VECTOR_DIV(v_sum, v_sum, (real) Total_Particles);
    for (i = 0; i < Total_Particles; i++) {
        new_particle = Particle_List[i];
        VECTOR_SUB((new_particle->pos), (new_particle->pos), r_sum);
        VECTOR_SUB((new_particle->vel), (new_particle->vel), v_sum);
    }
}
Ejemplo n.º 12
0
int main(int argc, char *argv[])
{
   long i;
   long j;
   long k;
   long x_part;
   long y_part;
   long d_size;
   long itemp;
   long jtemp;
   double procsqrt;
   long temp = 0;
   double min_total;
   double max_total;
   double avg_total;
   double min_multi;
   double max_multi;
   double avg_multi;
   double min_frac;
   double max_frac;
   double avg_frac;
   long ch;
   extern char *optarg;
   unsigned long computeend;
   unsigned long start;

   CLOCK(start)

   while ((ch = getopt(argc, argv, "n:p:e:r:t:soh")) != -1) {
     switch(ch) {
     case 'n': im = atoi(optarg);
               if (log_2(im-2) == -1) {
                 printerr("Grid must be ((power of 2)+2) in each dimension\n");
                 exit(-1);
               }
               break;
     case 'p': nprocs = atoi(optarg);
               if (nprocs < 1) {
                 printerr("P must be >= 1\n");
                 exit(-1);
               }
               if (log_2(nprocs) == -1) {
                 printerr("P must be a power of 2\n");
                 exit(-1);
               }
               break;
     case 'e': tolerance = atof(optarg); break;
     case 'r': res = atof(optarg); break;
     case 't': dtau = atof(optarg); break;
     case 's': do_stats = !do_stats; break;
     case 'o': do_output = !do_output; break;
     case 'h': printf("Usage: OCEAN <options>\n\n");
               printf("options:\n");
               printf("  -nN : Simulate NxN ocean.  N must be (power of 2)+2.\n");
               printf("  -pP : P = number of processors.  P must be power of 2.\n");
               printf("  -eE : E = error tolerance for iterative relaxation.\n");
               printf("  -rR : R = distance between grid points in meters.\n");
               printf("  -tT : T = timestep in seconds.\n");
               printf("  -s  : Print timing statistics.\n");
               printf("  -o  : Print out relaxation residual values.\n");
               printf("  -h  : Print out command line options.\n\n");
               printf("Default: OCEAN -n%1d -p%1d -e%1g -r%1g -t%1g\n",
                       DEFAULT_N,DEFAULT_P,DEFAULT_E,DEFAULT_R,DEFAULT_T);
               exit(0);
               break;
     }
   }

   MAIN_INITENV(,60000000)
   THREAD_INIT_FREE();    

   jm = im;
   printf("\n");
   printf("Ocean simulation with W-cycle multigrid solver\n");
   printf("    Processors                         : %1ld\n",nprocs);
   printf("    Grid size                          : %1ld x %1ld\n",im,jm);
   printf("    Grid resolution (meters)           : %0.2f\n",res);
   printf("    Time between relaxations (seconds) : %0.0f\n",dtau);
   printf("    Error tolerance                    : %0.7g\n",tolerance);
   printf("\n");

   xprocs = 0;
   yprocs = 0;
   procsqrt = sqrt((double) nprocs);
   j = (long) procsqrt;
   while ((xprocs == 0) && (j > 0)) {
     k = nprocs / j;
     if (k * j == nprocs) {
       if (k > j) {
         xprocs = j;
         yprocs = k;
       } else {
         xprocs = k;
         yprocs = j;
       }
     }
     j--;
   }
   if (xprocs == 0) {
     printerr("Could not find factors for subblocking\n");
     exit(-1);
   }

   minlevel = 0;
   itemp = 1;
   jtemp = 1;
   numlev = 0;
   minlevel = 0;
   while (itemp < (im-2)) {
     itemp = itemp*2;
     jtemp = jtemp*2;
     if ((itemp/yprocs > 1) && (jtemp/xprocs > 1)) {
       numlev++;
     }
   }

   if (numlev == 0) {
     printerr("Must have at least 2 grid points per processor in each dimension\n");
     exit(-1);
   }

   imx = (long *) G_MALLOC(numlev*sizeof(long));
   jmx = (long *) G_MALLOC(numlev*sizeof(long));
   lev_res = (double *) G_MALLOC(numlev*sizeof(double));
   lev_tol = (double *) G_MALLOC(numlev*sizeof(double));
   i_int_coeff = (double *) G_MALLOC(numlev*sizeof(double));
   j_int_coeff = (double *) G_MALLOC(numlev*sizeof(double));
   xpts_per_proc = (long *) G_MALLOC(numlev*sizeof(long));
   ypts_per_proc = (long *) G_MALLOC(numlev*sizeof(long));

   imx[numlev-1] = im;
   jmx[numlev-1] = jm;
   lev_res[numlev-1] = res;
   lev_tol[numlev-1] = tolerance;

   for (i=numlev-2;i>=0;i--) {
     imx[i] = ((imx[i+1] - 2) / 2) + 2;
     jmx[i] = ((jmx[i+1] - 2) / 2) + 2;
     lev_res[i] = lev_res[i+1] * 2;
   }

   for (i=0;i<numlev;i++) {
     xpts_per_proc[i] = (jmx[i]-2) / xprocs;
     ypts_per_proc[i] = (imx[i]-2) / yprocs;
   }
   for (i=numlev-1;i>=0;i--) {
     if ((xpts_per_proc[i] < 2) || (ypts_per_proc[i] < 2)) {
       minlevel = i+1;
       break;
     }
   }

   for (i=0;i<numlev;i++) {
     temp += imx[i];
   }
   temp = 0;
   j = 0;
   for (k=0;k<numlev;k++) {
     for (i=0;i<imx[k];i++) {
       j++;
       temp += jmx[k];
     }
   }

   d_size = nprocs*sizeof(double ***);
   psi = (double ****) G_MALLOC(d_size);
   psim = (double ****) G_MALLOC(d_size);
   work1 = (double ****) G_MALLOC(d_size);
   work4 = (double ****) G_MALLOC(d_size);
   work5 = (double ****) G_MALLOC(d_size);
   work7 = (double ****) G_MALLOC(d_size);
   temparray = (double ****) G_MALLOC(d_size);

   d_size = 2*sizeof(double **);
   for (i=0;i<nprocs;i++) {
     psi[i] = (double ***) G_MALLOC(d_size);
     psim[i] = (double ***) G_MALLOC(d_size);
     work1[i] = (double ***) G_MALLOC(d_size);
     work4[i] = (double ***) G_MALLOC(d_size);
     work5[i] = (double ***) G_MALLOC(d_size);
     work7[i] = (double ***) G_MALLOC(d_size);
     temparray[i] = (double ***) G_MALLOC(d_size);
   }

   d_size = nprocs*sizeof(double **);
   psium = (double ***) G_MALLOC(d_size);
   psilm = (double ***) G_MALLOC(d_size);
   psib = (double ***) G_MALLOC(d_size);
   ga = (double ***) G_MALLOC(d_size);
   gb = (double ***) G_MALLOC(d_size);
   work2 = (double ***) G_MALLOC(d_size);
   work3 = (double ***) G_MALLOC(d_size);
   work6 = (double ***) G_MALLOC(d_size);
   tauz = (double ***) G_MALLOC(d_size);
   oldga = (double ***) G_MALLOC(d_size);
   oldgb = (double ***) G_MALLOC(d_size);

   gp = (struct Global_Private *) G_MALLOC((nprocs+1)*sizeof(struct Global_Private));
   for (i=0;i<nprocs;i++) {
     gp[i].rel_num_x = (long *) G_MALLOC(numlev*sizeof(long));
     gp[i].rel_num_y = (long *) G_MALLOC(numlev*sizeof(long));
     gp[i].eist = (long *) G_MALLOC(numlev*sizeof(long));
     gp[i].ejst = (long *) G_MALLOC(numlev*sizeof(long));
     gp[i].oist = (long *) G_MALLOC(numlev*sizeof(long));
     gp[i].ojst = (long *) G_MALLOC(numlev*sizeof(long));
     gp[i].rlist = (long *) G_MALLOC(numlev*sizeof(long));
     gp[i].rljst = (long *) G_MALLOC(numlev*sizeof(long));
     gp[i].rlien = (long *) G_MALLOC(numlev*sizeof(long));
     gp[i].rljen = (long *) G_MALLOC(numlev*sizeof(long));
     gp[i].multi_time = 0;
     gp[i].total_time = 0;
   }

   subblock();

   x_part = (jm - 2)/xprocs + 2;
   y_part = (im - 2)/yprocs + 2;

   d_size = x_part*y_part*sizeof(double) + y_part*sizeof(double *);

   global = (struct global_struct *) G_MALLOC(sizeof(struct global_struct));
   for (i=0;i<nprocs;i++) {
     psi[i][0] = (double **) G_MALLOC(d_size);
     psi[i][1] = (double **) G_MALLOC(d_size);
     psim[i][0] = (double **) G_MALLOC(d_size);
     psim[i][1] = (double **) G_MALLOC(d_size);
     psium[i] = (double **) G_MALLOC(d_size);
     psilm[i] = (double **) G_MALLOC(d_size);
     psib[i] = (double **) G_MALLOC(d_size);
     ga[i] = (double **) G_MALLOC(d_size);
     gb[i] = (double **) G_MALLOC(d_size);
     work1[i][0] = (double **) G_MALLOC(d_size);
     work1[i][1] = (double **) G_MALLOC(d_size);
     work2[i] = (double **) G_MALLOC(d_size);
     work3[i] = (double **) G_MALLOC(d_size);
     work4[i][0] = (double **) G_MALLOC(d_size);
     work4[i][1] = (double **) G_MALLOC(d_size);
     work5[i][0] = (double **) G_MALLOC(d_size);
     work5[i][1] = (double **) G_MALLOC(d_size);
     work6[i] = (double **) G_MALLOC(d_size);
     work7[i][0] = (double **) G_MALLOC(d_size);
     work7[i][1] = (double **) G_MALLOC(d_size);
     temparray[i][0] = (double **) G_MALLOC(d_size);
     temparray[i][1] = (double **) G_MALLOC(d_size);
     tauz[i] = (double **) G_MALLOC(d_size);
     oldga[i] = (double **) G_MALLOC(d_size);
     oldgb[i] = (double **) G_MALLOC(d_size);
   }
   f = (double *) G_MALLOC(im*sizeof(double));

   multi = (struct multi_struct *) G_MALLOC(sizeof(struct multi_struct));

   d_size = numlev*sizeof(double **);
   if (numlev%2 == 1) {         /* To make sure that the actual data
                                   starts double word aligned, add an extra
                                   pointer */
     d_size += sizeof(double **);
   }
   for (i=0;i<numlev;i++) {
     d_size += ((imx[i]-2)/yprocs+2)*((jmx[i]-2)/xprocs+2)*sizeof(double)+
              ((imx[i]-2)/yprocs+2)*sizeof(double *);
   }

   d_size *= nprocs;

   if (nprocs%2 == 1) {         /* To make sure that the actual data
                                   starts double word aligned, add an extra
                                   pointer */
     d_size += sizeof(double ***);
   }

   d_size += nprocs*sizeof(double ***);
   q_multi = (double ****) G_MALLOC(d_size);
   rhs_multi = (double ****) G_MALLOC(d_size);

   locks = (struct locks_struct *) G_MALLOC(sizeof(struct locks_struct));
   bars = (struct bars_struct *) G_MALLOC(sizeof(struct bars_struct));

   LOCKINIT(locks->idlock)
   LOCKINIT(locks->psiailock)
   LOCKINIT(locks->psibilock)
   LOCKINIT(locks->donelock)
   LOCKINIT(locks->error_lock)
   LOCKINIT(locks->bar_lock)

#if defined(MULTIPLE_BARRIERS)
   BARINIT(bars->iteration, nprocs)
   BARINIT(bars->gsudn, nprocs)
   BARINIT(bars->p_setup, nprocs)
   BARINIT(bars->p_redph, nprocs)
   BARINIT(bars->p_soln, nprocs)
   BARINIT(bars->p_subph, nprocs)
   BARINIT(bars->sl_prini, nprocs)
   BARINIT(bars->sl_psini, nprocs)
   BARINIT(bars->sl_onetime, nprocs)
   BARINIT(bars->sl_phase_1, nprocs)
   BARINIT(bars->sl_phase_2, nprocs)
   BARINIT(bars->sl_phase_3, nprocs)
   BARINIT(bars->sl_phase_4, nprocs)
   BARINIT(bars->sl_phase_5, nprocs)
   BARINIT(bars->sl_phase_6, nprocs)
   BARINIT(bars->sl_phase_7, nprocs)
   BARINIT(bars->sl_phase_8, nprocs)
   BARINIT(bars->sl_phase_9, nprocs)
   BARINIT(bars->sl_phase_10, nprocs)
   BARINIT(bars->error_barrier, nprocs)
#else
   BARINIT(bars->barrier, nprocs)
#endif

   link_all();

   multi->err_multi = 0.0;
   i_int_coeff[0] = 0.0;
   j_int_coeff[0] = 0.0;
   for (i=0;i<numlev;i++) {
     i_int_coeff[i] = 1.0/(imx[i]-1);
     j_int_coeff[i] = 1.0/(jmx[i]-1);
   }

/* initialize constants and variables

   id is a global shared variable that has fetch-and-add operations
   performed on it by processes to obtain their pids.   */

   global->id = 0;
   global->psibi = 0.0;
   pi = atan(1.0);
   pi = 4.*pi;

   factjacob = -1./(12.*res*res);
   factlap = 1./(res*res);
   eig2 = -h*f0*f0/(h1*h3*gpr);

   jmm1 = jm-1 ;
   ysca = ((double) jmm1)*res ;

   im = (imx[numlev-1]-2)/yprocs + 2;
   jm = (jmx[numlev-1]-2)/xprocs + 2;

   if (do_output) {
     printf("                       MULTIGRID OUTPUTS\n");
   }

   CREATE(slave, nprocs);
   WAIT_FOR_END(nprocs);
   CLOCK(computeend)

   printf("\n");
   printf("                       PROCESS STATISTICS\n");
   printf("                  Total          Multigrid         Multigrid\n");
   printf(" Proc             Time             Time            Fraction\n");
   printf("    0   %15.0f    %15.0f        %10.3f\n", gp[0].total_time,gp[0].multi_time, gp[0].multi_time/gp[0].total_time);

   if (do_stats) {
     min_total = max_total = avg_total = gp[0].total_time;
     min_multi = max_multi = avg_multi = gp[0].multi_time;
     min_frac = max_frac = avg_frac = gp[0].multi_time/gp[0].total_time;
     for (i=1;i<nprocs;i++) {
       if (gp[i].total_time > max_total) {
         max_total = gp[i].total_time;
       }
       if (gp[i].total_time < min_total) {
         min_total = gp[i].total_time;
       }
       if (gp[i].multi_time > max_multi) {
         max_multi = gp[i].multi_time;
       }
       if (gp[i].multi_time < min_multi) {
         min_multi = gp[i].multi_time;
       }
       if (gp[i].multi_time/gp[i].total_time > max_frac) {
         max_frac = gp[i].multi_time/gp[i].total_time;
       }
       if (gp[i].multi_time/gp[i].total_time < min_frac) {
         min_frac = gp[i].multi_time/gp[i].total_time;
       }
       avg_total += gp[i].total_time;
       avg_multi += gp[i].multi_time;
       avg_frac += gp[i].multi_time/gp[i].total_time;
     }
     avg_total = avg_total / nprocs;
     avg_multi = avg_multi / nprocs;
     avg_frac = avg_frac / nprocs;
     for (i=1;i<nprocs;i++) {
       printf("  %3ld   %15.0f    %15.0f        %10.3f\n", i,gp[i].total_time,gp[i].multi_time, gp[i].multi_time/gp[i].total_time);
     }
     printf("  Avg   %15.0f    %15.0f        %10.3f\n", avg_total,avg_multi,avg_frac);
     printf("  Min   %15.0f    %15.0f        %10.3f\n", min_total,min_multi,min_frac);
     printf("  Max   %15.0f    %15.0f        %10.3f\n", max_total,max_multi,max_frac);
   }
   printf("\n");

   global->starttime = start;
   printf("                       TIMING INFORMATION\n");
   printf("Start time                        : %16lu\n", global->starttime);
   printf("Initialization finish time        : %16lu\n", global->trackstart);
   printf("Overall finish time               : %16lu\n", computeend);
   printf("Total time with initialization    : %16lu\n", computeend-global->starttime);
   printf("Total time without initialization : %16lu\n", computeend-global->trackstart);
   printf("    (excludes first timestep)\n");
   printf("\n");

   MAIN_END
}
Ejemplo n.º 13
0
void pgconn_start ( VG_DBStruct *el, float currx, float curry )
/************************************************************************
 * pgconn_start								*
 *									*
 * Initial setup and original selection					*
 *									*
 * void pgconn_start (el, currx, curry)					*
 *									*
 * Input parameters:							*
 *	*el		VG_DBStruct	selected element		*
 *	currx		float		current x coordinate		*
 *	curry		float		current y coordinate		*
 *									*
 * Output parameters:							*
 *			NONE						*
 *									*
 **									*
 * Log:									*
 *  S. Law/GSC		09/98	Initial coding				*
 *  G. Krueger/EAI	09/98	Added ghost veiling			*
 *  G. Krueger/EAI	10/98	Using table for mouse hints		*
 *  S. Law/GSC		09/99	added parameter to mcanvw_set* functions*
 *  H. Zeng/EAI         04/00   changed cursor name                     *
 *  H. Zeng/EAI         11/00   added _primaryLoc                       *
 *  J. Wu/GSC		02/01	Modified 'unused1' in VG to 'smooth'	*
 *  J. Wu/SAIC		06/07	connect GFAs with same hazard type &	*
 *				forecast hour				*
 ***********************************************************************/
{
    float	*dcx, *dcy;
    int		dcn, near, ii, jj, ier;
    char	hazard[32];
/*---------------------------------------------------------------------*/
    
    _primaryEl  = *el;
    _primaryLoc = pgactv_getElmLoc();
    
/*
 *  Check the type of first selected element - GFAs (except open
 *  FZLVL) are handle differently than other types of VG elements.
 */
    _isGFA = (_primaryEl.hdr.vg_type == GFA_ELM) ? True:False;

    _isOpenFzlvl = False;	           
    if ( _isGFA ) {
           
       _primaryEl.elem.gfa.info.nblocks = el->elem.gfa.info.nblocks;

       G_MALLOC ( _primaryEl.elem.gfa.info.blockPtr[ 0 ],
	          gfaBlock_t, el->elem.gfa.info.nblocks, 
	          "pgconn_start: _primaryEl.blockPtr" );

       memcpy ( _primaryEl.elem.gfa.info.blockPtr[ 0 ], 
	        el->elem.gfa.info.blockPtr[ 0 ], 
	        el->elem.gfa.info.nblocks * STD_STRLEN * sizeof ( char ) );      
       
       cvg_getFld ( el, TAG_GFA_AREATYPE, hazard, &ier );
       
       if ( strcasecmp( hazard, "FZLVL" ) == 0 ) {
           if ( _primaryEl.hdr.closed == 0 ) {
               _isOpenFzlvl = True;	           	   
	   }
       }
       
    }
    
    _drawGhost = True;
    if ( _isGFA && !_isOpenFzlvl ) {
        _drawGhost = False;    
    }

/*
 *  Start another mouse click.
 */
    pggst_veilGhost ( FALSE );    
    mcanvw_setPressFunc((XtEventHandler)&pgconn_select, CURS_DEFAULT);

/*
 *  No drag function for closed GFAs - except open FZLVLs.
 */
    if ( _drawGhost ) {
        mcanvw_setDragFunc((XtEventHandler)&pgconn_ghost, CURS_DEFAULT);
    }
          
    pgactv_getDevPts (&dcn, &dcx, &dcy);
    
/*
 *  Ghost only for non-GFAs and open FZLVLs.
 */
    if ( _drawGhost ) {
        near = pgactv_getNearPt ();
        _ghostN = (dcn < 3) ? dcn : 3;
        if (FindNearEnd (0, near, (dcn - 1))) {	/* ghost last 2 or 3 points */
	    jj = 0;
	    for (ii = (dcn - _ghostN); ii < dcn; ii++) {
	        _ghostX[jj] = *(dcx + ii);
	        _ghostY[jj] = *(dcy + ii);
	        jj++;
	    }
        }
        else {					/* ghost first 2 or 3 points */
	    jj = 0;
	    for (ii = (_ghostN - 1); ii > -1; ii--) {
	        _ghostX[jj] = *(dcx + ii);
	        _ghostY[jj] = *(dcy + ii);
	        jj++;
	    }
        }

        _ghostX[jj] = currx;
        _ghostY[jj] = curry;
    
        pggst_clearGhost (TRUE);
        pggst_setLineAttr (_primaryEl.hdr.smooth, 
		       (Boolean) _primaryEl.hdr.closed);
        pggst_addGhostPts ( (_ghostN+1), _ghostX, _ghostY, &ier );

        pggst_drawGhost (GST_NORMAL);
    }
    
    mbotw_mouseSet(LMHINT_NEXT, MMHINT_DONE);
}
Ejemplo n.º 14
0
int main(int argc, char *argv[])
{
  long i; 
  long c;
  extern char *optarg;
  long m1;
  long factor;
  long pages;
  unsigned long start;

  CLOCK(start);

  while ((c = getopt(argc, argv, "p:m:n:l:stoh")) != -1) {
    switch(c) {
      case 'p': P = atoi(optarg); 
                if (P < 1) {
                  printerr("P must be >= 1\n");
                  exit(-1);
                }
                if (log_2(P) == -1) {
                  printerr("P must be a power of 2\n");
                  exit(-1);
                }
	        break;  
      case 'm': M = atoi(optarg); 
                m1 = M/2;
                if (2*m1 != M) {
                  printerr("M must be even\n");
                  exit(-1);
                }
	        break;  
      case 'n': num_cache_lines = atoi(optarg); 
                orig_num_lines = num_cache_lines;
                if (num_cache_lines < 1) {
                  printerr("Number of cache lines must be >= 1\n");
                  exit(-1);
                }
	        break;  
      case 'l': log2_line_size = atoi(optarg); 
                if (log2_line_size < 0) {
                  printerr("Log base 2 of cache line length in bytes must be >= 0\n");
                  exit(-1);
                }
	        break;  
      case 's': dostats = !dostats; 
	        break;
      case 't': test_result = !test_result; 
	        break;
      case 'o': doprint = !doprint; 
	        break;
      case 'h': printf("Usage: FFT <options>\n\n");
                printf("options:\n");
                printf("  -mM : M = even integer; 2**M total complex data points transformed.\n");
                printf("  -pP : P = number of processors; Must be a power of 2.\n");
                printf("  -nN : N = number of cache lines.\n");
                printf("  -lL : L = Log base 2 of cache line length in bytes.\n");
                printf("  -s  : Print individual processor timing statistics.\n");
                printf("  -t  : Perform FFT and inverse FFT.  Test output by comparing the\n");
                printf("        integral of the original data to the integral of the data that\n");
                printf("        results from performing the FFT and inverse FFT.\n");
                printf("  -o  : Print out complex data points.\n");
                printf("  -h  : Print out command line options.\n\n");
                printf("Default: FFT -m%1d -p%1d -n%1d -l%1d\n",
                       DEFAULT_M,DEFAULT_P,NUM_CACHE_LINES,LOG2_LINE_SIZE);
		exit(0);
	        break;
    }
  }

  MAIN_INITENV(,80000000);

  N = 1<<M;
  rootN = 1<<(M/2);
  rowsperproc = rootN/P;
  if (rowsperproc == 0) {
    printerr("Matrix not large enough. 2**(M/2) must be >= P\n");
    exit(-1);
  }

  line_size = 1 << log2_line_size;
  if (line_size < 2*sizeof(double)) {
    printf("WARNING: Each element is a complex double (%ld bytes)\n",2*sizeof(double));
    printf("  => Less than one element per cache line\n");
    printf("     Computing transpose blocking factor\n");
    factor = (2*sizeof(double)) / line_size;
    num_cache_lines = orig_num_lines / factor;
  }  
  if (line_size <= 2*sizeof(double)) {
    pad_length = 1;
  } else {
    pad_length = line_size / (2*sizeof(double));
  }

  if (rowsperproc * rootN * 2 * sizeof(double) >= PAGE_SIZE) {
    pages = (2 * pad_length * sizeof(double) * rowsperproc) / PAGE_SIZE;
    if (pages * PAGE_SIZE != 2 * pad_length * sizeof(double) * rowsperproc) {
      pages ++;
    }
    pad_length = (pages * PAGE_SIZE) / (2 * sizeof(double) * rowsperproc);
  } else {
    pad_length = (PAGE_SIZE - (rowsperproc * rootN * 2 * sizeof(double))) /

                 (2 * sizeof(double) * rowsperproc);
    if (pad_length * (2 * sizeof(double) * rowsperproc) !=
        (PAGE_SIZE - (rowsperproc * rootN * 2 * sizeof(double)))) {
      printerr("Padding algorithm unsuccessful\n");
      exit(-1);
    }
  }

  Global = (struct GlobalMemory *) G_MALLOC(sizeof(struct GlobalMemory));
  x = (double *) G_MALLOC(2*(N+rootN*pad_length)*sizeof(double)+PAGE_SIZE);
  trans = (double *) G_MALLOC(2*(N+rootN*pad_length)*sizeof(double)+PAGE_SIZE);
  umain = (double *) G_MALLOC(2*rootN*sizeof(double));  
  umain2 = (double *) G_MALLOC(2*(N+rootN*pad_length)*sizeof(double)+PAGE_SIZE);

  Global->transtimes = (long *) G_MALLOC(P*sizeof(long));  
  Global->totaltimes = (long *) G_MALLOC(P*sizeof(long));  
  if (Global == NULL) {
    printerr("Could not malloc memory for Global\n");
    exit(-1);
  } else if (x == NULL) {
    printerr("Could not malloc memory for x\n");
    exit(-1);
  } else if (trans == NULL) {
    printerr("Could not malloc memory for trans\n");
    exit(-1);
  } else if (umain == NULL) {
    printerr("Could not malloc memory for umain\n");
    exit(-1);
  } else if (umain2 == NULL) {
    printerr("Could not malloc memory for umain2\n");
    exit(-1);
  }

  x = (double *) (((unsigned long) x) + PAGE_SIZE - ((unsigned long) x) % PAGE_SIZE);
  trans = (double *) (((unsigned long) trans) + PAGE_SIZE - ((unsigned long) trans) % PAGE_SIZE);
  umain2 = (double *) (((unsigned long) umain2) + PAGE_SIZE - ((unsigned long) umain2) % PAGE_SIZE);

/* In order to optimize data distribution, the data structures x, trans, 
   and umain2 have been aligned so that each begins on a page boundary. 
   This ensures that the amount of padding calculated by the program is 
   such that each processor's partition ends on a page boundary, thus 
   ensuring that all data from these structures that are needed by a 
   processor can be allocated to its local memory */

/* POSSIBLE ENHANCEMENT:  Here is where one might distribute the x,
   trans, and umain2 data structures across physically distributed 
   memories as desired.
   
   One way to place data is as follows:

   double *base;
   long i;

   i = ((N/P)+(rootN/P)*pad_length)*2;
   base = &(x[0]);
   for (j=0;j<P;j++) {
    Place all addresses x such that (base <= x < base+i) on node j
    base += i;
   }

   The trans and umain2 data structures can be placed in a similar manner.

   */

  printf("\n");
  printf("FFT with Blocking Transpose\n");
  printf("   %ld Complex Doubles\n",N);
  printf("   %ld Processors\n",P);
  if (num_cache_lines != orig_num_lines) {
    printf("   %ld Cache lines\n",orig_num_lines);
    printf("   %ld Cache lines for blocking transpose\n",num_cache_lines);
  } else {
    printf("   %ld Cache lines\n",num_cache_lines);
  }
  printf("   %d Byte line size\n",(1 << log2_line_size));
  printf("   %d Bytes per page\n",PAGE_SIZE);
  printf("\n");

  BARINIT(Global->start, P);
  LOCKINIT(Global->idlock);
  Global->id = 0;
  InitX(x);                  /* place random values in x */

  if (test_result) {
    ck1 = CheckSum(x);
  }
  if (doprint) {
    printf("Original data values:\n");
    PrintArray(N, x);
  }

  InitU(N,umain);               /* initialize u arrays*/
  InitU2(N,umain2,rootN);

  /* fire off P processes */

  CREATE(SlaveStart, P);
  WAIT_FOR_END(P);

  if (doprint) {
    if (test_result) {
      printf("Data values after inverse FFT:\n");
    } else {
      printf("Data values after FFT:\n");
    }
    PrintArray(N, x);
  }

  transtime = Global->transtimes[0];
  printf("\n");
  printf("                 PROCESS STATISTICS\n");
  printf("            Computation      Transpose     Transpose\n");
  printf(" Proc          Time            Time        Fraction\n");
  printf("    0        %10ld     %10ld      %8.5f\n",
         Global->totaltimes[0],Global->transtimes[0],
         ((double)Global->transtimes[0])/Global->totaltimes[0]);
  if (dostats) {
    transtime2 = Global->transtimes[0];
    avgtranstime = Global->transtimes[0];
    avgcomptime = Global->totaltimes[0];
    maxtotal = Global->totaltimes[0];
    mintotal = Global->totaltimes[0];
    maxfrac = ((double)Global->transtimes[0])/Global->totaltimes[0];
    minfrac = ((double)Global->transtimes[0])/Global->totaltimes[0];
    avgfractime = ((double)Global->transtimes[0])/Global->totaltimes[0];
    for (i=1;i<P;i++) {
      if (Global->transtimes[i] > transtime) {
        transtime = Global->transtimes[i];
      }
      if (Global->transtimes[i] < transtime2) {
        transtime2 = Global->transtimes[i];
      }
      if (Global->totaltimes[i] > maxtotal) {
        maxtotal = Global->totaltimes[i];
      }
      if (Global->totaltimes[i] < mintotal) {
        mintotal = Global->totaltimes[i];
      }
      if (((double)Global->transtimes[i])/Global->totaltimes[i] > maxfrac) {
        maxfrac = ((double)Global->transtimes[i])/Global->totaltimes[i];
      }
      if (((double)Global->transtimes[i])/Global->totaltimes[i] < minfrac) {
        minfrac = ((double)Global->transtimes[i])/Global->totaltimes[i];
      }
      printf("  %3ld        %10ld     %10ld      %8.5f\n",
             i,Global->totaltimes[i],Global->transtimes[i],
             ((double)Global->transtimes[i])/Global->totaltimes[i]);
      avgtranstime += Global->transtimes[i];
      avgcomptime += Global->totaltimes[i];
      avgfractime += ((double)Global->transtimes[i])/Global->totaltimes[i];
    }
    printf("  Avg        %10.0f     %10.0f      %8.5f\n",
           ((double) avgcomptime)/P,((double) avgtranstime)/P,avgfractime/P);
    printf("  Max        %10ld     %10ld      %8.5f\n",
	   maxtotal,transtime,maxfrac);
    printf("  Min        %10ld     %10ld      %8.5f\n",
	   mintotal,transtime2,minfrac);
  }
  Global->starttime = start;
  printf("\n");
  printf("                 TIMING INFORMATION\n");
  printf("Start time                        : %16lu\n",
	  Global->starttime);
  printf("Initialization finish time        : %16lu\n",
	  Global->initdonetime);
  printf("Overall finish time               : %16lu\n",
	  Global->finishtime);
  printf("Total time with initialization    : %16lu\n",
	  Global->finishtime-Global->starttime);
  printf("Total time without initialization : %16lu\n",
	  Global->finishtime-Global->initdonetime);
  printf("Overall transpose time            : %16ld\n",
         transtime);
  printf("Overall transpose fraction        : %16.5f\n",
         ((double) transtime)/(Global->finishtime-Global->initdonetime));
  printf("\n");

  if (test_result) {
    ck3 = CheckSum(x);
    printf("              INVERSE FFT TEST RESULTS\n");
    printf("Checksum difference is %.3f (%.3f, %.3f)\n",
	   ck1-ck3, ck1, ck3);
    if (fabs(ck1-ck3) < 0.001) {
      printf("TEST PASSED\n");
    } else {
      printf("TEST FAILED\n");
    }
  }

  MAIN_END;
}
Ejemplo n.º 15
0
EXTERN_ENV

#include <stdio.h>

#include "parameters.h"
#include "mdvar.h"
#include "water.h"
#include "wwpot.h"
#include "cnst.h"
#include "mddata.h"
#include "fileio.h"
#include "split.h"
#include "global.h"

/************************************************************************/

double MDMAIN(long NSTEP, long NPRINT, long NSAVE, long NORD1, long ProcID)
{
    double TVIR = 0.0;
    double TTMV = 0.0;
    double TKIN = 0.0;
    double XTT;
    long i,j,k;
    double POTA,POTR,POTRF;
    double XVIR,AVGT,TEN;
    struct list_of_boxes *new_box, *curr_box;

    for (i=start_end[ProcID]->box[XDIR][FIRST]; i<=start_end[ProcID]->box[XDIR][LAST]; i++) {
        for (j=start_end[ProcID]->box[YDIR][FIRST]; j<=start_end[ProcID]->box[YDIR][LAST]; j++) {
            for (k=start_end[ProcID]->box[ZDIR][FIRST]; k<=start_end[ProcID]->box[ZDIR][LAST]; k++) {
                new_box = (box_list *) G_MALLOC(sizeof(box_list));
                new_box->coord[XDIR] = i;
                new_box->coord[YDIR] = j;
                new_box->coord[ZDIR] = k;
                new_box->next_box = NULL;
                curr_box = my_boxes[ProcID];
                if (curr_box == NULL)
                    my_boxes[ProcID] = new_box;
                else {
                    while (curr_box->next_box != NULL)
                        curr_box = curr_box->next_box;
                    curr_box->next_box = new_box;
                } /* else */
            }
        }
    }

    /* calculate initial value for acceleration */

    INTRAF(&gl->VIR,ProcID);

    BARRIER(gl->start,NumProcs);

    INTERF(ACC,&gl->VIR,ProcID);

    BARRIER(gl->start, NumProcs);

    /* MOLECULAR DYNAMICS LOOP */

    for (i=1;i <= NSTEP; i++) {
        TTMV=TTMV+1.00;

        /* POSSIBLE ENHANCEMENT:  Here's where one start measurements to avoid
           cold-start effects.  Recommended to do this at the beginning of the
           second timestep; i.e. if (i == 2).
           */

        /* initialize various shared sums */
        if (ProcID == 0) {
            long dir;
            if (i >= 2) {
                CLOCK(gl->trackstart);
            }
            gl->VIR = 0.0;
            gl->POTA = 0.0;
            gl->POTR = 0.0;
            gl->POTRF = 0.0;
            for (dir = XDIR; dir <= ZDIR; dir++)
                gl->SUM[dir] = 0.0;
        }

        if ((ProcID == 0) && (i >= 2)) {
            CLOCK(gl->intrastart);
        }

        BARRIER(gl->start, NumProcs);

        PREDIC(TLC,NORD1,ProcID);
        INTRAF(&gl->VIR,ProcID);

        BARRIER(gl->start, NumProcs);

        if ((ProcID == 0) && (i >= 2)) {
            CLOCK(gl->intraend);
            gl->intratime += gl->intraend - gl->intrastart;
        }

        if ((ProcID == 0) && (i >= 2)) {
            CLOCK(gl->interstart);
        }

        INTERF(FORCES,&gl->VIR,ProcID);

        if ((ProcID == 0) && (i >= 2)) {
            CLOCK(gl->interend);
            gl->intertime += gl->interend - gl->interstart;
        }

        CORREC(PCC,NORD1,ProcID);

        BNDRY(ProcID);

        KINETI(gl->SUM,HMAS,OMAS,ProcID);

        BARRIER(gl->start, NumProcs);

        if ((ProcID == 0) && (i >= 2)) {
            CLOCK(gl->intraend);
            gl->intratime += gl->intraend - gl->interend;
        }

        TKIN=TKIN+gl->SUM[0]+gl->SUM[1]+gl->SUM[2];
        TVIR=TVIR-gl->VIR;

        /* CHECK if  PRINTING AND/OR SAVING IS TO BE DONE */

        if ( ((i % NPRINT) == 0) || ((NSAVE > 0) && ((i % NSAVE) == 0))) {

            /* if so, call poteng to compute potential energy.  Note
               that we are attributing all the time in poteng to intermolecular
               computation although some of it is intramolecular (see poteng.C) */

            if ((ProcID == 0) && (i >= 2)) {
                CLOCK(gl->interstart);
            }

            POTENG(&gl->POTA,&gl->POTR,&gl->POTRF,ProcID);

            BARRIER(gl->start, NumProcs);

            if ((ProcID == 0) && (i >= 2)) {
                CLOCK(gl->interend);
                gl->intertime += gl->interend - gl->interstart;
            }

            POTA=gl->POTA*FPOT;
            POTR=gl->POTR*FPOT;
            POTRF=gl->POTRF*FPOT;
            XVIR=TVIR*FPOT*0.50/TTMV;
            AVGT=TKIN*FKIN*TEMP*2.00/(3.00*TTMV);
            TEN=(gl->SUM[0]+gl->SUM[1]+gl->SUM[2])*FKIN;
            XTT=POTA+POTR+POTRF+TEN;

            /* if it is time to print output as well ... */
            if ((i % NPRINT) == 0 && ProcID == 0) {
                LOCK(gl->IOLock);
                fprintf(six,"     %5ld %14.5lf %12.5lf %12.5lf %12.5lf \n"
                        ,i,TEN,POTA,POTR,POTRF);
                fprintf(six," %16.3lf %16.5lf %16.5lf\n",XTT,AVGT,XVIR);
                fflush(six);
                UNLOCK(gl->IOLock);
            }

        }

        BARRIER(gl->start, NumProcs);

        if ((ProcID == 0) && (i >= 2)) {
            CLOCK(gl->trackend);
            gl->tracktime += gl->trackend - gl->trackstart;
        }

    } /* for i */
   
    return(XTT);

} /* mdmain.c */
Ejemplo n.º 16
0
void ctb_hfread ( int *iret )
/************************************************************************
 * ctb_pfread								*
 *									*
 * This function reads the info from the Hershey Fonts tables.		*
 * 									*
 * The Hershey Font coordinates are encoded using the ASCII characters.	*
 * Each character pair represents a coordinate in the drawing system	*
 * with 'R,R' as the origin. To get the coordinate values, subtract	*
 * 'R' from the given character. For example, the pair 'SB' corresponds	*
 * to (+1,-16).								*
 *									*
 * ctb_hfread ( iret )							*
 *									*
 * Input parameters:							*
 *									*
 * Output parameters:							*
 *	*iret		int		Return code			*
 *				  	  -1 = cannot open or read table*
 *				  	 -12 = cannot allocate memory	*
 **									*
 * Log:									*
 * S. Jacobs/NCEP	10/07	Created					*
 * T. Piper/SAIC	03/08	Replaced cmm functions with Macros	*
 ***********************************************************************/
{
    FILE	*fp;
    char	buffer[256], av[6];
    int		ii, nr, ier, ifont, ier2, jj, kk, nf, one = 1;

    font_tbl_name_t   tbl[] = {	{"hfont03.tbl",  3},
				{"hfont23.tbl", 23},
				{"hfont04.tbl",  4},
				{"hfont14.tbl", 14},
				{"hfont24.tbl", 24},
				{"hfont34.tbl", 34} };
/*---------------------------------------------------------------------*/

  *iret = G_NORMAL;

/*
 * Allocate space for all of the font structures.
 */
  nf = sizeof(tbl)/sizeof(tbl[0]);
  G_MALLOC ( _hfontTbl, HF_font_t, nf, "ctb_hfread - _hfontTbl");
  if ( _hfontTbl == NULL ) {
    *iret = -12;
    return;
  }

  _nhfont = 0;
  for ( ifont = 0; ifont < nf; ifont++ )  {
/*
 *  Read the font table and add entries into the structure. 
 */
    nr = 0;
    fp = cfl_tbop ( tbl[ifont].table_name, "hershey", &ier );
    if ( ier == 0 ) { 
	cfl_tbnr ( fp, &nr, &ier);
    }
	    
    if ( nr == 0 ) {
	cfl_clos ( fp, &ier );
        *iret = -1;
        return;
    }
    _hfontTbl[ifont].font_code = tbl[ifont].font_num;

/*
 *  Allocate space for the characters.
 */
    G_MALLOC ( _hfontTbl[ifont].character, HF_char_t, nr, "ctb_hfread - _hfontTbl[ifont].character");
    if ( _hfontTbl[ifont].character == NULL ) {
	cfl_clos ( fp, &ier );
	*iret = -12;
	return;
    }
  
/*
 * Read table entries into the structure.
 */
    ii = 0;

/* Read the next line from the file */
    cfl_trln ( fp, 256, buffer, &ier );

/*
 * Process the file while there is no error and
 * the end of the file has not been reached.
 */
    while ( ier >= 0 && ier != 4 ) {

        if ( ier == 0 ) {

	    G_MALLOC ( _hfontTbl[ifont].character[ii].point_code, char,  
		    strlen(buffer)+1, " ctb_hfread - _hfontTbl[ifont].character[ii].point_code");
	    if ( _hfontTbl[ifont].character[ii].point_code == NULL ) {
		cfl_clos ( fp, &ier );
		*iret = -12;
		return;
	    }
	    strcpy ( _hfontTbl[ifont].character[ii].point_code, buffer );

/* Get the character ASCII code */
	    cst_ncpy ( av, &(buffer[0]), 5, &ier2 );
	    cst_numb ( av, &(_hfontTbl[ifont].character[ii].ascii_val),
		       &ier2 );

/*
 * Get the number of points for the character
 * (The number in the file includes the X min and max,
 *  so subtract one)
 */
	    cst_ncpy ( av, &(buffer[5]), 3, &ier2 );
	    cst_numb ( av, &(_hfontTbl[ifont].character[ii].npts),
			&ier2 );
	    (_hfontTbl[ifont].character[ii].npts)--;

/* Get the X min and max */
	    _hfontTbl[ifont].character[ii].xmin = buffer[8] - 'R';
	    _hfontTbl[ifont].character[ii].xmax = buffer[9] - 'R';

/* Get the coordinates, if the number of points is > 0 */
	    if ( _hfontTbl[ifont].character[ii].npts > 0 ) {
		G_MALLOC ( _hfontTbl[ifont].character[ii].point, HF_point_t,
			_hfontTbl[ifont].character[ii].npts, 
			" ctb_hfread - _hfontTbl[ifont].character[ii].point");
                if ( _hfontTbl[ifont].character[ii].point == NULL ) {
		    cfl_clos ( fp, &ier );
		    *iret = -12;
		    return;
		}

/*
 * Check for " R", which denotes a "pen up".
 * If there is a pen up code, set the points to missing.
 * Otherwise, decode the coordinate values.
 */
		kk = 10;
		for ( jj = 0;
		      jj < _hfontTbl[ifont].character[ii].npts;
		      jj++ ) {
		    if ( strncmp ( &(buffer[kk]), " R", 2 ) == 0 ) {
			_hfontTbl[ifont].character[ii].point[jj].x = -99;
			_hfontTbl[ifont].character[ii].point[jj].y = -99;
			kk += 2;
		    }
		    else {
			_hfontTbl[ifont].character[ii].point[jj].x =
						buffer[kk] - 'R'; kk++;
			_hfontTbl[ifont].character[ii].point[jj].y =
						buffer[kk] - 'R'; kk++;
		    }
		}

	    }
/*
 * If there are no character codes,
 * set one point at the origin
 */
	    else {
		G_MALLOC ( _hfontTbl[ifont].character[ii].point, HF_point_t,
				one, " ctb_hfread - _hfontTbl[ifont].character[ii].point");
		if ( _hfontTbl[ifont].character[ii].point == NULL ) {
		    cfl_clos ( fp, &ier );
		    *iret = -12;
		    return;
		}
		_hfontTbl[ifont].character[ii].point[0].x = 0;
		_hfontTbl[ifont].character[ii].point[0].y = 0;
	    }
	    ii++;
        }

/* Read the next line from the file */
	cfl_trln ( fp, 256, buffer, &ier );

    }

/* Set the number of characters for the font */
    _hfontTbl[ifont].numchr = ii;

/* Close the font table */
    cfl_clos ( fp, &ier );

/* Increase the count for the number of fonts */
    _nhfont++;
  }  
Ejemplo n.º 17
0
int main(int argc, char *argv[])
{
   long i;
   long j;
   long xextra;
   long xportion;
   long yextra;
   long yportion;
   long lower;
   double procsqrt;
   long k;
   long logtest;
   long my_num;
   unsigned long computeend;
   double min_total;
   double max_total;
   double avg_total;
   double min_multi;
   double max_multi;
   double avg_multi;
   double min_frac;
   double max_frac;
   double avg_frac;
   extern char *optarg;
   long ch;
   unsigned long start;

   CLOCK(start)

   while ((ch = getopt(argc, argv, "n:p:e:r:t:soh")) != -1) {
     switch(ch) {
     case 'n': im = atoi(optarg);
               if (im > IMAX) {
                 printerr("Max grid size exceeded\n");
                 exit(-1);
               }
               if (log_2(im-2) == -1) {
                 printerr("Grid must be ((power of 2)+2) in each dimension\n");
                 exit(-1);
               }
               break;
     case 'p': nprocs = atoi(optarg);
               if (nprocs < 1) {
                 printerr("P must be >= 1\n");
                 exit(-1);
               }
               if (log_2(nprocs) == -1) {
                 printerr("P must be a power of 2\n");
                 exit(-1);
               }
               break;
     case 'e': tolerance = atof(optarg); break;
     case 'r': res = atof(optarg); break;
     case 't': dtau = atof(optarg); break;
     case 's': do_stats = !do_stats; break;
     case 'o': do_output = !do_output; break;
     case 'h': printf("Usage: OCEAN <options>\n\n");
               printf("options:\n");
               printf("  -nN : Simulate NxN ocean.  N must be (power of 2)+2.\n");
               printf("  -pP : P = number of processors.  P must be power of 2.\n");
               printf("  -eE : E = error tolerance for iterative relaxation.\n");
               printf("  -rR : R = distance between grid points in meters.\n");
               printf("  -tT : T = timestep in seconds.\n");
               printf("  -s  : Print timing statistics.\n");
               printf("  -o  : Print out relaxation residual values.\n");
               printf("  -h  : Print out command line options.\n\n");
               printf("Default: OCEAN -n%1d -p%1d -e%1g -r%1g -t%1g\n",
                       DEFAULT_N,DEFAULT_P,DEFAULT_E,DEFAULT_R,DEFAULT_T);
               exit(0);
               break;
     }
   }

   MAIN_INITENV(,60000000)

   logtest = im-2;
   numlev = 1;
   while (logtest != 1) {
     if (logtest%2 != 0) {
       printerr("Cannot determine number of multigrid levels\n");
       exit(-1);
     }
     logtest = logtest / 2;
     numlev++;
   }

   if (numlev > MAX_LEVELS) {
     printerr("Max grid levels exceeded for multigrid\n");
     exit(-1);
   }

   jm = im;
   printf("\n");
   printf("Ocean simulation with W-cycle multigrid solver\n");
   printf("    Processors                         : %1ld\n",nprocs);
   printf("    Grid size                          : %1ld x %1ld\n",im,jm);
   printf("    Grid resolution (meters)           : %0.2f\n",res);
   printf("    Time between relaxations (seconds) : %0.0f\n",dtau);
   printf("    Error tolerance                    : %0.7g\n",tolerance);
   printf("\n");

   gp = (struct Global_Private *) G_MALLOC((nprocs+1)*sizeof(struct Global_Private));
   for (i=0;i<nprocs;i++) {
     gp[i].multi_time = 0;
     gp[i].total_time = 0;
   }
   global = (struct global_struct *) G_MALLOC(sizeof(struct global_struct));
   fields = (struct fields_struct *) G_MALLOC(sizeof(struct fields_struct));
   fields2 = (struct fields2_struct *) G_MALLOC(sizeof(struct fields2_struct));
   wrk1 = (struct wrk1_struct *) G_MALLOC(sizeof(struct wrk1_struct));
   wrk3 = (struct wrk3_struct *) G_MALLOC(sizeof(struct wrk3_struct));
   wrk2 = (struct wrk2_struct *) G_MALLOC(sizeof(struct wrk2_struct));
   wrk4 = (struct wrk4_struct *) G_MALLOC(sizeof(struct wrk4_struct));
   wrk6 = (struct wrk6_struct *) G_MALLOC(sizeof(struct wrk6_struct));
   wrk5 = (struct wrk5_struct *) G_MALLOC(sizeof(struct wrk5_struct));
   frcng = (struct frcng_struct *) G_MALLOC(sizeof(struct frcng_struct));
   iter = (struct iter_struct *) G_MALLOC(sizeof(struct iter_struct));
   guess = (struct guess_struct *) G_MALLOC(sizeof(struct guess_struct));
   multi = (struct multi_struct *) G_MALLOC(sizeof(struct multi_struct));
   locks = (struct locks_struct *) G_MALLOC(sizeof(struct locks_struct));
   bars = (struct bars_struct *) G_MALLOC(sizeof(struct bars_struct));

   LOCKINIT(locks->idlock)
   LOCKINIT(locks->psiailock)
   LOCKINIT(locks->psibilock)
   LOCKINIT(locks->donelock)
   LOCKINIT(locks->error_lock)
   LOCKINIT(locks->bar_lock)

   BARINIT(bars->iteration)
   BARINIT(bars->gsudn)
   BARINIT(bars->p_setup) 
   BARINIT(bars->p_redph) 
   BARINIT(bars->p_soln) 
   BARINIT(bars->p_subph) 
   BARINIT(bars->sl_prini)
   BARINIT(bars->sl_psini)
   BARINIT(bars->sl_onetime)
   BARINIT(bars->sl_phase_1)
   BARINIT(bars->sl_phase_2)
   BARINIT(bars->sl_phase_3)
   BARINIT(bars->sl_phase_4)
   BARINIT(bars->sl_phase_5)
   BARINIT(bars->sl_phase_6)
   BARINIT(bars->sl_phase_7)
   BARINIT(bars->sl_phase_8)
   BARINIT(bars->sl_phase_9)
   BARINIT(bars->sl_phase_10)
   BARINIT(bars->error_barrier)

   imx[numlev-1] = im;
   jmx[numlev-1] = jm;
   lev_res[numlev-1] = res;
   lev_tol[numlev-1] = tolerance;
   multi->err_multi = 0.0;
   multi->numspin = 0;
   for (i=0;i<nprocs;i++) {
     multi->spinflag[i] = 0;
   }

   for (i=numlev-2;i>=0;i--) {
     imx[i] = ((imx[i+1] - 2) / 2) + 2;
     jmx[i] = ((jmx[i+1] - 2) / 2) + 2;
     lev_res[i] = lev_res[i+1] * 2;
   }

   xprocs = 0;
   yprocs = 0;
   procsqrt = sqrt((double) nprocs);
   j = (long) procsqrt;
   while ((xprocs == 0) && (j > 0)) {
     k = nprocs / j;
     if (k * j == nprocs) {
       if (k > j) {
         xprocs = j;
         yprocs = k;
       } else {
         xprocs = k;
         yprocs = j;
       }
     }
     j--;
   }
   if (xprocs == 0) {
     printerr("Could not find factors for subblocking\n");
     exit(-1);
   }

/* Determine starting coord and number of points to process in     */
/* each direction                                                  */

   for (i=0;i<numlev;i++) {
     xportion = (jmx[i] - 2) / xprocs;
     xextra = (jmx[i] - 2) % xprocs;
     for (j=0;j<xprocs;j++) {
       if (xextra == 0) {
         for (k=0;k<yprocs;k++) {
           gp[k*xprocs+j].rel_start_x[i] = j * xportion + 1;
           gp[k*xprocs+j].rel_num_x[i] = xportion;
         }
       } else {
         if (j + 1 > xextra) {
           for (k=0;k<yprocs;k++) {
             lower = xextra * (xportion + 1);
             gp[k*xprocs+j].rel_start_x[i] = lower + (j - xextra) * xportion + 1;
             gp[k*xprocs+j].rel_num_x[i] = xportion;
           }
         } else {
           for (k=0;k<yprocs;k++) {
             gp[k*xprocs+j].rel_start_x[i] = j * (xportion + 1) + 1;
             gp[k*xprocs+j].rel_num_x[i] = xportion + 1;
           }
         }
       }
     }
     yportion = (imx[i] - 2) / yprocs;
     yextra = (imx[i] - 2) % yprocs;
     for (j=0;j<yprocs;j++) {
       if (yextra == 0) {
         for (k=0;k<xprocs;k++) {
           gp[j*xprocs+k].rel_start_y[i] = j * yportion + 1;
           gp[j*xprocs+k].rel_num_y[i] = yportion;
         }
       } else {
         if (j + 1 > yextra) {
           for (k=0;k<xprocs;k++) {
             lower = yextra * (yportion + 1);
             gp[j*xprocs+k].rel_start_y[i] = lower + (j - yextra) * yportion + 1;
             gp[j*xprocs+k].rel_num_y[i] = yportion;
           }
         } else {
           for (k=0;k<xprocs;k++) {
             gp[j*xprocs+k].rel_start_y[i] = j * (yportion + 1) + 1;
             gp[j*xprocs+k].rel_num_y[i] = yportion + 1;
           }
         }
       }
     }
   }

   i_int_coeff[0] = 0.0;
   j_int_coeff[0] = 0.0;
   for (i=0;i<numlev;i++) {
     i_int_coeff[i] = 1.0/(imx[i]-1);
     j_int_coeff[i] = 1.0/(jmx[i]-1);
   }

   for (my_num=0;my_num<nprocs;my_num++) {
     for (i=0;i<numlev;i++) {
       gp[my_num].rlist[i] = gp[my_num].rel_start_y[i];
       gp[my_num].rljst[i] = gp[my_num].rel_start_x[i];
       gp[my_num].rlien[i] = gp[my_num].rlist[i] + gp[my_num].rel_num_y[i] - 1;
       gp[my_num].rljen[i] = gp[my_num].rljst[i] + gp[my_num].rel_num_x[i] - 1;
       gp[my_num].iist[i] = gp[my_num].rel_start_y[i];
       gp[my_num].ijst[i] = gp[my_num].rel_start_x[i];
       gp[my_num].iien[i] = gp[my_num].iist[i] + gp[my_num].rel_num_y[i] - 1;
       gp[my_num].ijen[i] = gp[my_num].ijst[i] + gp[my_num].rel_num_x[i] - 1;
       gp[my_num].pist[i] = gp[my_num].rel_start_y[i];
       gp[my_num].pjst[i] = gp[my_num].rel_start_x[i];
       gp[my_num].pien[i] = gp[my_num].pist[i] + gp[my_num].rel_num_y[i] - 1;
       gp[my_num].pjen[i] = gp[my_num].pjst[i] + gp[my_num].rel_num_x[i] - 1;

       if (gp[my_num].pist[i] == 1) {
         gp[my_num].pist[i] = 0;
       }
       if (gp[my_num].pjst[i] == 1) {
         gp[my_num].pjst[i] = 0;
       }
       if (gp[my_num].pien[i] == imx[i] - 2) {
         gp[my_num].pien[i] = imx[i]-1;
       }
       if (gp[my_num].pjen[i] == jmx[i] - 2) {
         gp[my_num].pjen[i] = jmx[i]-1;
       }

       if (gp[my_num].rlist[i] % 2 == 0) {
         gp[my_num].eist[i] = gp[my_num].rlist[i];
         gp[my_num].oist[i] = gp[my_num].rlist[i] + 1;
       } else {
         gp[my_num].eist[i] = gp[my_num].rlist[i] + 1;
         gp[my_num].oist[i] = gp[my_num].rlist[i];
       }
       if (gp[my_num].rljst[i] % 2 == 0) {
         gp[my_num].ejst[i] = gp[my_num].rljst[i];
         gp[my_num].ojst[i] = gp[my_num].rljst[i] + 1;
       } else {
         gp[my_num].ejst[i] = gp[my_num].rljst[i] + 1;
         gp[my_num].ojst[i] = gp[my_num].rljst[i];
       }
       if (gp[my_num].rlien[i] == imx[i]-2) {
         gp[my_num].rlien[i] = gp[my_num].rlien[i] - 1;
         if (gp[my_num].rlien[i] % 2 == 0) {
           gp[my_num].ojest[i] = gp[my_num].ojst[i];
           gp[my_num].ejest[i] = gp[my_num].ejst[i];
         } else {
           gp[my_num].ojest[i] = gp[my_num].ejst[i];
           gp[my_num].ejest[i] = gp[my_num].ojst[i];
         }
       }
       if (gp[my_num].rljen[i] == jmx[i]-2) {
         gp[my_num].rljen[i] = gp[my_num].rljen[i] - 1;
         if (gp[my_num].rljen[i] % 2 == 0) {
           gp[my_num].oiest[i] = gp[my_num].oist[i];
           gp[my_num].eiest[i] = gp[my_num].eist[i];
         } else {
           gp[my_num].oiest[i] = gp[my_num].eist[i];
           gp[my_num].eiest[i] = gp[my_num].oist[i];
         }
       }
     }
   }

/* initialize constants and variables

   id is a global shared variable that has fetch-and-add operations
   performed on it by processes to obtain their pids.   */

   global->id = 0;
   global->psibi = 0.0;
   pi = atan(1.0);
   pi = 4.*pi;

   factjacob = -1./(12.*res*res);
   factlap = 1./(res*res);
   eig2 = -h*f0*f0/(h1*h3*gpr);
   jmm1 = jm-1 ;
   ysca = ((double) jmm1)*res ;
   for (i=0;i<im;i++) {
     for (j=0;j<jm;j++) {
       guess->oldga[i][j] = 0.0;
       guess->oldgb[i][j] = 0.0;
     }
   }

   if (do_output) {
     printf("                       MULTIGRID OUTPUTS\n");
   }

   CREATE(slave, nprocs);
   WAIT_FOR_END(nprocs);
   CLOCK(computeend)

   printf("\n");
   printf("                       PROCESS STATISTICS\n");
   printf("                  Total          Multigrid         Multigrid\n");
   printf(" Proc             Time             Time            Fraction\n");
   printf("    0   %15.0f    %15.0f        %10.3f\n", gp[0].total_time,gp[0].multi_time, gp[0].multi_time/gp[0].total_time);

   if (do_stats) {
     min_total = max_total = avg_total = gp[0].total_time;
     min_multi = max_multi = avg_multi = gp[0].multi_time;
     min_frac = max_frac = avg_frac = gp[0].multi_time/gp[0].total_time;
     for (i=1;i<nprocs;i++) {
       if (gp[i].total_time > max_total) {
         max_total = gp[i].total_time;
       }
       if (gp[i].total_time < min_total) {
         min_total = gp[i].total_time;
       }
       if (gp[i].multi_time > max_multi) {
         max_multi = gp[i].multi_time;
       }
       if (gp[i].multi_time < min_multi) {
         min_multi = gp[i].multi_time;
       }
       if (gp[i].multi_time/gp[i].total_time > max_frac) {
         max_frac = gp[i].multi_time/gp[i].total_time;
       }
       if (gp[i].multi_time/gp[i].total_time < min_frac) {
         min_frac = gp[i].multi_time/gp[i].total_time;
       }
       avg_total += gp[i].total_time;
       avg_multi += gp[i].multi_time;
       avg_frac += gp[i].multi_time/gp[i].total_time;
     }
     avg_total = avg_total / nprocs;
     avg_multi = avg_multi / nprocs;
     avg_frac = avg_frac / nprocs;
     for (i=1;i<nprocs;i++) {
       printf("  %3ld   %15.0f    %15.0f        %10.3f\n", i, gp[i].total_time, gp[i].multi_time, gp[i].multi_time/gp[i].total_time);
     }
     printf("  Avg   %15.0f    %15.0f        %10.3f\n", avg_total,avg_multi,avg_frac);
     printf("  Min   %15.0f    %15.0f        %10.3f\n", min_total,min_multi,min_frac);
     printf("  Max   %15.0f    %15.0f        %10.3f\n", max_total,max_multi,max_frac);
   }
   printf("\n");

   global->starttime = start;
   printf("                       TIMING INFORMATION\n");
   printf("Start time                        : %16lu\n", global->starttime);
   printf("Initialization finish time        : %16lu\n", global->trackstart);
   printf("Overall finish time               : %16lu\n", computeend);
   printf("Total time with initialization    : %16lu\n", computeend-global->starttime);
   printf("Total time without initialization : %16lu\n", computeend-global->trackstart);
   printf("    (excludes first timestep)\n");
   printf("\n");

   MAIN_END
}
Ejemplo n.º 18
0
int main(int argc, char *argv[])
{
    long i;
    long total_rad_time, max_rad_time, min_rad_time;
    long total_refine_time, max_refine_time, min_refine_time;
    long total_wait_time, max_wait_time, min_wait_time;
    long total_vertex_time, max_vertex_time, min_vertex_time;

    /* Parse arguments */
    parse_args(argc, argv) ;
    choices[2].init_value = model_selector ;

    /* Initialize graphic device */
    if( batch_mode == 0 )
        {
            g_init(argc, argv) ;
            setup_view( DFLT_VIEW_ROT_X, DFLT_VIEW_ROT_Y,
                       DFLT_VIEW_DIST, DFLT_VIEW_ZOOM,0 ) ;
        }

    /* Initialize ANL macro */
    MAIN_INITENV(,60000000) ;

    THREAD_INIT_FREE();

    /* Allocate global shared memory and initialize */
    global = (Global *) G_MALLOC(sizeof(Global)) ;
    if( global == 0 )
        {
            printf( "Can't allocate memory\n" ) ;
            exit(1) ;
        }
    init_global(0) ;

    timing = (Timing **) G_MALLOC(n_processors * sizeof(Timing *));
    for (i = 0; i < n_processors; i++)
        timing[i] = (Timing *) G_MALLOC(sizeof(Timing));

    /* Initialize shared lock */
    init_sharedlock(0) ;

    /* Initial random testing rays array for visibility test. */
    init_visibility_module(0) ;

/* POSSIBLE ENHANCEMENT:  Here is where one might distribute the
   sobj_struct, task_struct, and vis_struct data structures across
   physically distributed memories as desired.

   One way to place data is as follows:

   long i;

   for (i=0;i<n_processors;i++) {
     Place all addresses x such that
       &(sobj_struct[i]) <= x < &(sobj_struct[i+1]) on node i
     Place all addresses x such that
       &(task_struct[i]) <= x < &(task_struct[i+1]) on node i
     Place all addresses x such that
       &(vis_struct[i]) <= x < &(vis_struct[i+1]) on node i
   }

*/

    if( batch_mode )
        {
            /* In batch mode, create child processes and start immediately */

            /* Time stamp */
            CLOCK( time_rad_start );

            global->index = 0;
            for( i = 0 ; i < n_processors ; i++ )
                {
                    taskqueue_id[i] = assign_taskq(0) ;
                }

            /* And start processing */
            CREATE(radiosity, n_processors);
            WAIT_FOR_END(n_processors);

            /* Time stamp */
            CLOCK( time_rad_end );

            /* Print out running time */
            printf("TIMING STATISTICS MEASURED BY MAIN PROCESS:\n");

            print_running_time(0);

            if (dostats) {
                printf("\n\n\nPER-PROCESS STATISTICS:\n");

                printf("%8s%20s%20s%12s%12s\n","Proc","Total","Refine","Wait","Smooth");
                printf("%8s%20s%20s%12s%12s\n\n","","Time","Time","Time","Time");
                for (i = 0; i < n_processors; i++)
                    printf("%8ld%20lu%20lu%12lu%12lu\n",i,timing[i]->rad_time, timing[i]->refine_time, timing[i]->wait_time, timing[i]->vertex_time);

                total_rad_time = timing[0]->rad_time;
                max_rad_time = timing[0]->rad_time;
                min_rad_time = timing[0]->rad_time;

                total_refine_time = timing[0]->refine_time;
                max_refine_time = timing[0]->refine_time;
                min_refine_time = timing[0]->refine_time;

                total_wait_time = timing[0]->wait_time;
                max_wait_time = timing[0]->wait_time;
                min_wait_time = timing[0]->wait_time;

                total_vertex_time = timing[0]->vertex_time;
                max_vertex_time = timing[0]->vertex_time;
                min_vertex_time = timing[0]->vertex_time;

                for (i = 1; i < n_processors; i++) {
                    total_rad_time += timing[i]->rad_time;
                    if (timing[i]->rad_time > max_rad_time)
                        max_rad_time = timing[i]->rad_time;
                    if (timing[i]->rad_time < min_rad_time)
                        min_rad_time = timing[i]->rad_time;

                    total_refine_time += timing[i]->refine_time;
                    if (timing[i]->refine_time > max_refine_time)
                        max_refine_time = timing[i]->refine_time;
                    if (timing[i]->refine_time < min_refine_time)
                        min_refine_time = timing[i]->refine_time;

                    total_wait_time += timing[i]->wait_time;
                    if (timing[i]->wait_time > max_wait_time)
                        max_wait_time = timing[i]->wait_time;
                    if (timing[i]->wait_time < min_wait_time)
                        min_wait_time = timing[i]->wait_time;

                    total_vertex_time += timing[i]->vertex_time;
                    if (timing[i]->vertex_time > max_vertex_time)
                        max_vertex_time = timing[i]->vertex_time;
                    if (timing[i]->vertex_time < min_vertex_time)
                        min_vertex_time = timing[i]->vertex_time;
                }

                printf("\n\n%8s%20lu%20lu%12lu%12lu\n","Max", max_rad_time, max_refine_time, max_wait_time, max_vertex_time);
                printf("\n%8s%20lu%20lu%12lu%12lu\n","Min", min_rad_time, min_refine_time, min_wait_time, min_vertex_time);
                printf("\n%8s%20lu%20lu%12lu%12lu\n","Avg", (long) (((double) total_rad_time) / ((double) (1.0 * n_processors))), (long) (((double) total_refine_time) / ((double) (1.0 * n_processors))), (long) (((double) total_wait_time) / ((double) (1.0 * n_processors))), (long) (((double) total_vertex_time) / ((double) (1.0 * n_processors))));
                printf("\n\n");

            }

            /*	print_fork_time(0) ; */

            print_statistics( stdout, 0 ) ;
        }
    else
        {
            /* In interactive mode, start workers, and the master starts
               notification loop */

            /* Start notification loop */
            g_start( expose_callback,
                    N_SLIDERS, sliders, N_CHOICES, choices ) ;
        }
    MAIN_END;
    exit(0) ;
}
Ejemplo n.º 19
0
void tb_nidsdb ( char *prdnam, char *res, int *iprod, int *iret )
/************************************************************************
 * tb_nidsdb								*
 *									*
 * This subroutine returns information about the radar image from the	*
 * NIDS product table file.						*
 *									*
 * void tb_nidsdb (  prdnam, res, iprod, iret )				*
 *									*
 * Input parameters:							*
 *	*prdnam		char		Product name			*
 *	*res		char		Data resolution in km		*
 *									*
 * Output parameters:							*
 *	*iprod		int		NIDS product ID                 *
 *	*iret		int		Return code			*
 *					  0 = normal return		*
 *					 +3 = No entry found for image	*
 *					 -7 = Could not open imtyp table*
 **									*
 * Log:									*
 * m.gamazaychikov/CWS	01/10	Created					*
 ***********************************************************************/
{
    int			found, ier, ier1, loglev=2;
    float               ares;
    char		*grp="TB", line[128];
    size_t		ii;
    static int		nr;
    static FILE		*fptr=NULL;
    static Radtbl_t	*radtbl=NULL;
/*---------------------------------------------------------------------*/
/*
 *  Initialize output variables.
 */
    *iprod = 0;
    *iret = 33;  /*  Not found  */
    cst_crnm ( res, &ares, &ier );

/*
 *  If table not yet read into memory; open the image type table file.
 */
    if ( fptr == NULL ) {
	fptr = cfl_tbop ( NIDPRD_TBL, "rad", &ier );
	if ( ier != 0 ) { 
	    *iret = -7;
	    er_lmsg (&loglev, grp, iret, NIDPRD_TBL, &ier1, strlen(grp), strlen(NIDPRD_TBL));
	    return;
	}

/*
 *  Load the structure.
 */
	cfl_tbnr (fptr, &nr, &ier );
	if ( ier != 0 || nr == 0 ) {
	    *iret = -7;
	    er_lmsg (&loglev, grp, iret, NIDPRD_TBL, &ier1, strlen(grp), strlen(NIDPRD_TBL));
	    cfl_clos(fptr, &ier);
	    return;
	}
	G_MALLOC(radtbl, Radtbl_t, nr, "tb_nidsdb:  radtbl");
	for (ii = 0; ii < (size_t)nr; ii++ ) {

/*
 *  Read the next record.
 */
	    cfl_trln ( fptr, 127, line, &ier );
	    if ( ier == 0 ) {
		sscanf(line,"%s %s %i %i %s %f %s",
			radtbl[ii].type, radtbl[ii].name, &radtbl[ii].prod,
			&radtbl[ii].lvls, radtbl[ii].units,
			&radtbl[ii].res, radtbl[ii].desc);
	    }
	}  /*  end of 'for (ii = 0; ii < nr; ii++ )'  */
	cfl_clos(fptr, &ier);
    }  /*  end of 'if ( *fptr == NULL )'  */

    ii = 0;
    found = G_FALSE;

/*
 *  Retrieve the product ID for the specified 
 *  product name and the resolution.
 */
    while ( !found && ii < (size_t)nr ) {
      //if ( strstr (radtbl[ii].name, prdnam) != NULL ) {
      if ( strcmp (prdnam, radtbl[ii].name) == 0 ) {
         if ( G_DIFF(ares, radtbl[ii].res) ) {
	    found = G_TRUE; 
	    *iprod = radtbl[ii].prod;
	    *iret = G_NORMAL;
         }
      }
      ii++;
    }
}
Ejemplo n.º 20
0
int main(int argc, char **argv)
{
    /* default values for the control parameters of the driver */
    /* are in parameters.h */

    if ((argc == 2) && ((strncmp(argv[1],"-h",strlen("-h")) == 0) || (strncmp(argv[1],"-H",strlen("-H")) == 0))) {
        printf("Usage:  WATER-SPATIAL < infile, where the contents of infile can be\nobtained from the comments at the top of water.C and the first scanf \nin main() in water.C\n\n");
        exit(0);
    }
#else

int main(void)
{
#endif

        /*  POSSIBLE ENHANCEMENT:  One might bind the first process to a processor
            here, even before the other (child) processes are bound later in mdmain().
            */

    six = stdout;

    TEMP  =298.0;
    RHO   =0.9980;

    /* read input */

#ifndef SIM_SOCLIB
    if (scanf("%lf%ld%ld%ld%ld%ld%ld%ld%ld%lf",&TSTEP, &NMOL, &NSTEP, &NORDER, &NSAVE, &NRST, &NPRINT, &NFMC,&NumProcs, &CUTOFF) != 10)
        fprintf(stderr,"ERROR: Usage: water < infile, which must have 10 fields, see SPLASH documentation or comment at top of water.C\n");
#else
    TSTEP = 1.5e-16;
    NMOL  =  NMOLS;
    NSTEP =  3;
    NORDER  =	6;
    NSAVE   = -1 ;
    NRST    = 3000 ;
    NPRINT = 3 ;
    NFMC   = 0;
    NumProcs = NB_P;
    CUTOFF = 6.212752;
#endif

    printf("Using %ld procs on %ld steps of %ld mols\n", NumProcs, NSTEP, NMOL);
    printf("Other parameters:\n\tTSTEP = %8.2e\n\tNORDER = %ld\n\tNSAVE = %ld\n",TSTEP,NORDER,NSAVE);
    printf("\tNRST = %ld\n\tNPRINT = %ld\n\tNFMC = %ld\n\tCUTOFF = %lf\n\n",NRST,NPRINT,NFMC,CUTOFF);

    /* set up scaling factors and constants */

    NORD1=NORDER+1;

    CNSTNT(NORD1,TLC);  /* sub. call to set up constants */

    SYSCNS();    /* sub. call to initialize system constants  */

    printf("%ld boxes with %ld processors\n\n",
           BOX_PER_SIDE * BOX_PER_SIDE * BOX_PER_SIDE, NumProcs);

    if (NumProcs > (BOX_PER_SIDE * BOX_PER_SIDE * BOX_PER_SIDE)) {
        fprintf(stderr,"ERROR: less boxes (%ld) than processors (%ld)\n",
                BOX_PER_SIDE * BOX_PER_SIDE * BOX_PER_SIDE, NumProcs);
        fflush(stderr);
        exit(-1);
    }

    fprintf(six,"\nTEMPERATURE                = %8.2f K\n",TEMP);
    fprintf(six,"DENSITY                    = %8.5f G/C.C.\n",RHO);
    fprintf(six,"NUMBER OF MOLECULES        = %8ld\n",NMOL);
    fprintf(six,"NUMBER OF PROCESSORS       = %8ld\n",NumProcs);
    fprintf(six,"TIME STEP                  = %8.2e SEC\n",TSTEP);
    fprintf(six,"ORDER USED TO SOLVE F=MA   = %8ld \n",NORDER);
    fprintf(six,"NO. OF TIME STEPS          = %8ld \n",NSTEP);
    fprintf(six,"FREQUENCY OF DATA SAVING   = %8ld \n",NSAVE);
    fprintf(six,"FREQUENCY TO WRITE RST FILE= %8ld \n",NRST);
    fflush(six);

    { /* do memory initializations */

        long procnum, i, j, k, l;
        struct list_of_boxes *temp_box;
        long xprocs, yprocs, zprocs;
        long x_inc, y_inc, z_inc;
        long x_ct, y_ct, z_ct;
        long x_left, y_left, z_left;
        long x_first, y_first, z_first;
        long x_last, y_last, z_last;
        double proccbrt;
        long gmem_size = sizeof(struct GlobalMemory);

        MAIN_INITENV((NumProcs),40000000,);  /* macro call to initialize
                                      shared memory etc. */


        /* Allocate space for main (BOX) data structure as well as
         * synchronization variables
         */

        start_end = (first_last_array **)
            G_MALLOC(sizeof(first_last_array *) * NumProcs);
        for (i=0; i < NumProcs; i++) {
            start_end[i] = (first_last_array *)
                G_MALLOC(sizeof(first_last_array));
        }

        /* Calculate start and finish box numbers for processors */

        xprocs = 0;
        yprocs = 0;
        proccbrt = (double) pow((double) NumProcs, 1.0/3.0) + 0.00000000000001;
        j = (long) proccbrt;
        if (j<1) j = 1;
        while ((xprocs == 0) && (j>0)) {
            k = (long) sqrt((double) (NumProcs / j));
            if (k<1) k=1;
            while ((yprocs == 0) && (k>0)) {
                l = NumProcs/(j*k);
                if ((j*k*l) == NumProcs) {
                    xprocs = j;
                    yprocs = k;
                    zprocs = l;
                } /* if */
                k--;
            } /* while yprocs && k */
            j--;
        } /* while xprocs && j */

        printf("xprocs = %ld\typrocs = %ld\tzprocs = %ld\n",
               xprocs, yprocs, zprocs);
        fflush(stdout);

        /* Fill in start_end array values */

        procnum = 0;
        x_inc = BOX_PER_SIDE/xprocs;
        y_inc = BOX_PER_SIDE/yprocs;
        z_inc = BOX_PER_SIDE/zprocs;

        x_left = BOX_PER_SIDE - (xprocs*x_inc);
        y_left = BOX_PER_SIDE - (yprocs*y_inc);
        z_left = BOX_PER_SIDE - (zprocs*z_inc);
        printf("x_inc = %ld\t y_inc = %ld\t z_inc = %ld\n",x_inc,y_inc,z_inc);
        printf("x_left = %ld\t y_left = %ld\t z_left = %ld\n",x_left,y_left,z_left);
        fflush(stdout);


        x_first = 0;
        x_ct = x_left;
        x_last = -1;
        x_inc++;
        for (i=0; i<xprocs; i++) {
            y_ct = y_left;
            if (x_ct == 0) x_inc--;
            x_last += x_inc;
            y_first = 0;
            y_last = -1;
            y_inc++;
            for (j=0; j<yprocs; j++) {
                z_ct = z_left;
                if (y_ct == 0) y_inc--;
                y_last += y_inc;
                z_first = 0;
                z_last = -1;
                z_inc++;
                for (k=0; k<zprocs; k++) {
                    if (z_ct == 0) z_inc--;
                    z_last += z_inc;
                    start_end[procnum]->box[XDIR][FIRST] = x_first;
                    start_end[procnum]->box[XDIR][LAST] =
                        min(x_last, BOX_PER_SIDE - 1);
                    start_end[procnum]->box[YDIR][FIRST] = y_first;
                    start_end[procnum]->box[YDIR][LAST] =
                        min(y_last, BOX_PER_SIDE - 1);
                    start_end[procnum]->box[ZDIR][FIRST] = z_first;
                    start_end[procnum]->box[ZDIR][LAST] =
                        min(z_last, BOX_PER_SIDE - 1);
                    z_first = z_last + 1;
                    z_ct--;
                    procnum++;
                }
                y_first = y_last + 1;
                y_ct--;
            }
            x_first = x_last + 1;
            x_ct--;
        }

        /* Allocate space for my_boxes array */

        my_boxes = (box_list **) G_MALLOC(NumProcs * sizeof(box_list *));

        /* Set all box ptrs to null */

        for (i=0; i<NumProcs; i++) my_boxes[i] = NULL;

        /* Set up links for all boxes for initial interf and intraf */

        temp_box = my_boxes[0];
        while (temp_box) {
            temp_box = temp_box->next_box;
        }

        /* Allocate space for BOX array */

        BOX = (box_type ***) G_MALLOC(BOX_PER_SIDE * sizeof(box_type **));
        for (i=0; i < BOX_PER_SIDE; i++) {
            BOX[i] = (box_type **) G_MALLOC( BOX_PER_SIDE * sizeof(box_type *));
            for (j=0; j < BOX_PER_SIDE; j++) {
                BOX[i][j] = (box_type *) G_MALLOC(BOX_PER_SIDE * sizeof(box_type));
                for (k=0; k < BOX_PER_SIDE; k++) {
                    BOX[i][j][k].list = NULL;
                    LOCKINIT(BOX[i][j][k].boxlock);
                }
            }
        } /* for i */

        gl = (struct GlobalMemory *) G_MALLOC(gmem_size);

        /* macro calls to initialize synch variables  */

        BARINIT(gl->start, NumProcs);
        BARINIT(gl->InterfBar, NumProcs);
        BARINIT(gl->PotengBar, NumProcs);
        LOCKINIT(gl->IOLock);
        LOCKINIT(gl->IndexLock);
        LOCKINIT(gl->IntrafVirLock);
        LOCKINIT(gl->InterfVirLock);
        LOCKINIT(gl->KinetiSumLock);
        LOCKINIT(gl->PotengSumLock);
    }

    fprintf(six,"SPHERICAL CUTOFF RADIUS    = %8.4f ANGSTROM\n",CUTOFF);
    fflush(six);

    IRST=0;

    /* call initialization routine */

    INITIA();

    gl->tracktime = 0;
    gl->intratime = 0;
    gl->intertime = 0;

    /* initialize Index to 1 so that the first created child gets
       id 1, not 0 */

    gl->Index = 1;

    if (NSAVE > 0) {  /* not true for input decks provided */
        fprintf(six,"COLLECTING X AND V DATA AT EVERY %4ld TIME STEPS \n",NSAVE);
    }

    /* spawn helper processes */
    CLOCK(gl->computestart);
    CREATE(WorkStart, NumProcs);

    /* macro to make main process wait for all others to finish */
    WAIT_FOR_END(NumProcs);
    CLOCK(gl->computeend);

    printf("COMPUTESTART (after initialization) = %lu\n",gl->computestart);
    printf("COMPUTEEND = %lu\n",gl->computeend);
    printf("COMPUTETIME (after initialization) = %lu\n",gl->computeend-gl->computestart);
    printf("Measured Time (2nd timestep onward) = %lu\n",gl->tracktime);
    printf("Intramolecular time only (2nd timestep onward) = %lu\n",gl->intratime);
    printf("Intermolecular time only (2nd timestep onward) = %lu\n",gl->intertime);
    printf("Other time (2nd timestep onward) = %lu\n",gl->tracktime - gl->intratime - gl->intertime);

    printf("\nExited Happily with XTT = %g (note: XTT value is garbage if NPRINT > NSTEP)\n", XTT);

    MAIN_END;
} /* main.c */
Ejemplo n.º 21
0
int main(int argc, char **argv)
{
    /* default values for the control parameters of the driver */
    /* are in parameters.h */

    if ((argc == 2) &&((strncmp(argv[1],"-h",strlen("-h")) == 0) || (strncmp(argv[1],"-H",strlen("-H")) == 0))) {
        printf("Usage:  WATER-NSQUARED < infile, where the contents of infile can be\nobtained from the comments at the top of water.C and the first scanf \nin main() in water.C\n\n");
        exit(0);
    }

    /*  POSSIBLE ENHANCEMENT:  Here's where one might bind the main process
        (process 0) to a processor if one wanted to. Others can be bound in
        the WorkStart routine.
        */

    six = stdout;   /* output file */

    TEMP  =298.0;
    RHO   =0.9980;
    CUTOFF=0.0;

    /* read input */

    if (scanf("%lf%ld%ld%ld%ld%ld%ld%ld%ld%lf",&TSTEP, &NMOL, &NSTEP, &NORDER,
              &NSAVE, &NRST, &NPRINT, &NFMC,&NumProcs, &CUTOFF) != 10)
        fprintf(stderr,"ERROR: Usage: water < infile, which must have 10 fields, see SPLASH documentation or comment at top of water.C\n");

    if (NMOL > MAXLCKS) {
        fprintf(stderr, "Just so you know ... Lock array in global.H has size %ld < %ld (NMOL)\n code will still run correctly but there may be lock contention\n\n", MAXLCKS, NMOL);
    }

    printf("Using %ld procs on %ld steps of %ld mols\n", NumProcs, NSTEP, NMOL);
    printf("Other parameters:\n\tTSTEP = %8.2e\n\tNORDER = %ld\n\tNSAVE = %ld\n",TSTEP,NORDER,NSAVE);
    printf("\tNRST = %ld\n\tNPRINT = %ld\n\tNFMC = %ld\n\tCUTOFF = %lf\n\n",NRST,NPRINT,NFMC,CUTOFF);


    /* SET UP SCALING FACTORS AND CONSTANTS */

    NORD1=NORDER+1;

    CNSTNT(NORD1,TLC);  /* sub. call to set up constants */


    { /* Do memory initializations */
        long pid;
        long mol_size = sizeof(molecule_type) * NMOL;
        long gmem_size = sizeof(struct GlobalMemory);

        /*  POSSIBLE ENHANCEMENT:  One might bind the first process to
            a processor here, even before the other (child) processes are
            bound later in mdmain().
            */

        MAIN_INITENV(,70000000,);  /* macro call to initialize
                                      shared memory etc. */
        THREAD_INIT_FREE();

        /* allocate space for main (VAR) data structure as well as
           synchronization variables */

        /*  POSSIBLE ENHANCEMENT: One might want to allocate a process's
            portion of the VAR array and what it points to in its local
            memory */

        VAR = (molecule_type *) G_MALLOC(mol_size);
        gl = (struct GlobalMemory *) G_MALLOC(gmem_size);

        /*  POSSIBLE ENHANCEMENT: One might want to allocate  process i's
            PFORCES[i] array in its local memory */

        PFORCES = (double ****) G_MALLOC(NumProcs * sizeof (double ***));
        { long i,j,k;

          for (i = 0; i < NumProcs; i++) {
              PFORCES[i] = (double ***) G_MALLOC(NMOL * sizeof (double **));
              for (j = 0; j < NMOL; j++) {
                  PFORCES[i][j] = (double **) G_MALLOC(NDIR * sizeof (double *));
                  for (k = 0; k < NDIR; k++) {
                      PFORCES[i][j][k] = (double *) G_MALLOC(NATOM * sizeof (double));
                  }
              }
          }
      }
        /* macro calls to initialize synch varibles  */

        BARINIT(gl->start, NumProcs);
	BARINIT(gl->InterfBar, NumProcs);
	BARINIT(gl->PotengBar, NumProcs);
        LOCKINIT(gl->IOLock);
        LOCKINIT(gl->IndexLock);
        LOCKINIT(gl->IntrafVirLock);
        LOCKINIT(gl->InterfVirLock);
        LOCKINIT(gl->FXLock);
        LOCKINIT(gl->FYLock);
        LOCKINIT(gl->FZLock);
        if (NMOL < MAXLCKS) {
            ALOCKINIT(gl->MolLock, NMOL);
        }
        else {
            ALOCKINIT(gl->MolLock, MAXLCKS);
        }
        LOCKINIT(gl->KinetiSumLock);
        LOCKINIT(gl->PotengSumLock);

        /* set up control for static scheduling */

        MolsPerProc = NMOL/NumProcs;
        StartMol[0] = 0;
        for (pid = 1; pid < NumProcs; pid += 1) {
            StartMol[pid] = StartMol[pid-1] + MolsPerProc;
        }
        StartMol[NumProcs] = NMOL;
    }

    SYSCNS();    /* sub. call to initialize system constants  */

    fprintf(six,"\nTEMPERATURE                = %8.2f K\n",TEMP);
    fprintf(six,"DENSITY                    = %8.5f G/C.C.\n",RHO);
    fprintf(six,"NUMBER OF MOLECULES        = %8ld\n",NMOL);
    fprintf(six,"NUMBER OF PROCESSORS       = %8ld\n",NumProcs);
    fprintf(six,"TIME STEP                  = %8.2e SEC\n",TSTEP);
    fprintf(six,"ORDER USED TO SOLVE F=MA   = %8ld \n",NORDER);
    fprintf(six,"NO. OF TIME STEPS          = %8ld \n",NSTEP);
    fprintf(six,"FREQUENCY OF DATA SAVING   = %8ld \n",NSAVE);
    fprintf(six,"FREQUENCY TO WRITE RST FILE= %8ld \n",NRST);
    fprintf(six,"SPHERICAL CUTOFF RADIUS    = %8.4f ANGSTROM\n",CUTOFF);
    fflush(six);


    /* initialization routine; also reads displacements and
       sets up random velocities*/
    INITIA();

    /*.....start molecular dynamic loop */

    gl->tracktime = 0;
    gl->intratime = 0;
    gl->intertime = 0;

    /* initialize Index to 1 so that the first created child gets
       id 1, not 0 */

    gl->Index = 1;

    if (NSAVE > 0)  /* not true for input decks provided */
	fprintf(six,"COLLECTING X AND V DATA AT EVERY %4ld TIME STEPS \n",NSAVE);

    /* spawn helper processes, each getting its unique process id */
    CLOCK(gl->computestart);
    CREATE(WorkStart, NumProcs);

    /* macro to make main process wait for all others to finish */
    WAIT_FOR_END(NumProcs);
    CLOCK(gl->computeend);

    printf("COMPUTESTART (after initialization) = %lu\n",gl->computestart);
    printf("COMPUTEEND = %lu\n",gl->computeend);
    printf("COMPUTETIME (after initialization) = %lu\n",gl->computeend-gl->computestart);
    printf("Measured Time (2nd timestep onward) = %lu\n",gl->tracktime);
    printf("Intramolecular time only (2nd timestep onward) = %lu\n",gl->intratime);
    printf("Intermolecular time only (2nd timestep onward) = %lu\n",gl->intertime);
    printf("Other time (2nd timestep onward) = %lu\n",gl->tracktime - gl->intratime - gl->intertime);

    printf("\nExited Happily with XTT = %g (note: XTT value is garbage if NPRINT > NSTEP)\n", XTT);

    MAIN_END;
} /* main.c */
Ejemplo n.º 22
0
int	main(int argc, CHAR *argv[])
	{
	INT	i;
	UINT	begin;
	UINT	end;
	UINT	lapsed;
	MATRIX	vtrans, Vinv;		/*  View transformation and inverse. */


	/*
	 *	First, process command line arguments.
	 */
	i = 1;
	while ((i < argc) && (argv[i][0] == '-')) {
		switch (argv[i][1]) {
			case '?':
			case 'h':
			case 'H':
				Usage();
				exit(1);

			case 'a':
			case 'A':
				AntiAlias = TRUE;
				if (argv[i][2] != '\0') {
					NumSubRays = atoi(&argv[i][2]);
				} else {
					NumSubRays = atoi(&argv[++i][0]);
				}
				break;

			case 'm':
				if (argv[i][2] != '\0') {
					MaxGlobMem = atoi(&argv[i][2]);
				} else {
					MaxGlobMem = atoi(&argv[++i][0]);
				}
				break;

			case 'p':
				if (argv[i][2] != '\0') {
					nprocs = atoi(&argv[i][2]);
				} else {
					nprocs = atoi(&argv[++i][0]);
				}
				break;

			case 's':
			case 'S':
				dostats = TRUE;
				break;

			default:
				fprintf(stderr, "%s: Invalid option \'%c\'.\n", ProgName, argv[i][0]);
				exit(1);
		}
		i++;
	}

	if (i == argc) {
		Usage();
		exit(1);
	}


	/*
	 *	Make sure nprocs is within valid range.
	 */

	if (nprocs < 1 || nprocs > MAX_PROCS)
		{
		fprintf(stderr, "%s: Valid range for #processors is [1, %d].\n", ProgName, MAX_PROCS);
		exit(1);
		}


	/*
	 *	Print command line parameters.
	 */

	printf("\n");
	printf("Number of processors:     \t%ld\n", nprocs);
	printf("Global shared memory size:\t%ld MB\n", MaxGlobMem);
	printf("Samples per pixel:        \t%ld\n", NumSubRays);
	printf("\n");


	/*
	 *	Initialize the shared memory environment and request the total
	 *	amount of amount of shared memory we might need.  This
	 *	includes memory for the database, grid, and framebuffer.
	 */

	MaxGlobMem <<= 20;			/* Convert MB to bytes.      */
	MAIN_INITENV(,MaxGlobMem + 512*1024)
   THREAD_INIT_FREE();
	gm = (GMEM *)G_MALLOC(sizeof(GMEM));


	/*
	 *	Perform shared environment initializations.
	 */

	gm->nprocs = nprocs;
	gm->pid    = 0;
	gm->rid    = 1;

	BARINIT(gm->start, nprocs)
	LOCKINIT(gm->pidlock)
	LOCKINIT(gm->ridlock)
	LOCKINIT(gm->memlock)
	ALOCKINIT(gm->wplock, nprocs)

/* POSSIBLE ENHANCEMENT:  Here is where one might distribute the
   raystruct data structure across physically distributed memories as
   desired.  */

	if (!GlobalHeapInit(MaxGlobMem))
		{
		fprintf(stderr, "%s: Cannot initialize global heap.\n", ProgName);
		exit(1);
		}


	/*
	 *	Initialize HUG parameters, read environment and geometry files.
	 */

	Huniform_defaults();
	ReadEnvFile(/* *argv*/argv[i]);
	ReadGeoFile(GeoFileName);
	OpenFrameBuffer();


	/*
	 *	Compute view transform and its inverse.
	 */

	CreateViewMatrix();
	MatrixCopy(vtrans, View.vtrans);
	MatrixInverse(Vinv, vtrans);
	MatrixCopy(View.vtransInv, Vinv);


	/*
	 *	Print out what we have so far.
	 */

	printf("Number of primitive objects: \t%ld\n", prim_obj_cnt);
	printf("Number of primitive elements:\t%ld\n", prim_elem_cnt);

	/*
	 *	Preprocess database into hierarchical uniform grid.
	 */

	if (TraversalType == TT_HUG)
		BuildHierarchy_Uniform();



	/*
	 *	Now create slave processes.
	 */

	CLOCK(begin)
	CREATE(StartRayTrace, gm->nprocs);
	WAIT_FOR_END(gm->nprocs);
	CLOCK(end)



	/*
	 *	We are finished.  Clean up, print statistics and run time.
	 */

	CloseFrameBuffer(PicFileName);
	PrintStatistics();

	lapsed = (end - begin) & 0x7FFFFFFF;



	printf("TIMING STATISTICS MEASURED BY MAIN PROCESS:\n");
	printf("        Overall start time     %20lu\n", begin);
	printf("        Overall end time   %20lu\n", end);
	printf("        Total time with initialization  %20lu\n", lapsed);
	printf("        Total time without initialization  %20lu\n", end - gm->par_start_time);

    if (dostats) {
        unsigned totalproctime, maxproctime, minproctime;

        printf("\n\n\nPER-PROCESS STATISTICS:\n");

        printf("%20s%20s\n","Proc","Time");
        printf("%20s%20s\n\n","","Tracing Rays");
        for (i = 0; i < gm->nprocs; i++)
            printf("%20ld%20ld\n",i,gm->partime[i]);

        totalproctime = gm->partime[0];
        minproctime = gm->partime[0];
        maxproctime = gm->partime[0];

        for (i = 1; i < gm->nprocs; i++) {
            totalproctime += gm->partime[i];
            if (gm->partime[i] > maxproctime)
                maxproctime = gm->partime[i];
            if (gm->partime[i] < minproctime)
                minproctime = gm->partime[i];
        }
        printf("\n\n%20s%20d\n","Max = ",maxproctime);
        printf("%20s%20d\n","Min = ",minproctime);
        printf("%20s%20d\n","Avg = ",(int) (((double) totalproctime) / ((double) (1.0 * gm->nprocs))));
    }

	MAIN_END
	}
Ejemplo n.º 23
0
//Entry point for all threads (except main)
//  waiting allocs and inits of main then copy read-only tabs in ldata segment (replicated)
//  some read-write tabs are also replicated, but not entirely : only pointers
__attribute__ ((constructor)) void thread()
{
    unsigned long size;
    long id = (long) giet_thread_id();

    unsigned int cx, cy, lp;

    giet_proc_xyp(&cx, &cy, &lp);
    giet_tty_printf("Thread %d (%d:%d.%d) waiting\n", id, cx, cy, lp);

    if (lp == 0) {
        
        giet_procs_number(&nclusters_x, &nclusters_y, &procs_per_cluster);
        heap_init(cx, cy);

        while (heap_inited != id) {
            asm volatile ("nop\r\n");
        }
        heap_inited += procs_per_cluster;
        
        
        size = nprocs * sizeof(double ***);
        rhs_multi = (double ****) G_MALLOC(size, id);
        q_multi = (double ****) G_MALLOC(size, id);
        psi = (double ****) G_MALLOC(size, id);
        psim = (double ****) G_MALLOC(size, id);
        work1 = (double ****) G_MALLOC(size, id);
        work4 = (double ****) G_MALLOC(size, id);
        work5 = (double ****) G_MALLOC(size, id);
        work7 = (double ****) G_MALLOC(size, id);
        
        size = nprocs * sizeof(double **);
        psium = (double ***) G_MALLOC(size, id);
        psilm = (double ***) G_MALLOC(size, id);
        psib = (double ***) G_MALLOC(size, id);
        ga = (double ***) G_MALLOC(size, id);
        gb = (double ***) G_MALLOC(size, id);
        oldga = (double ***) G_MALLOC(size, id);
        oldgb = (double ***) G_MALLOC(size, id);
        work2 = (double ***) G_MALLOC(size, id);
        work3 = (double ***) G_MALLOC(size, id);
        work6 = (double ***) G_MALLOC(size, id);
    }
Ejemplo n.º 24
0
void ces_rtbl ( int *iret )
/************************************************************************
 * ces_rtbl								*
 *									*
 * This function reads the setting table and loads the settings		*
 * structure.								*
 *									*
 * ces_rtbl ( iret )							*
 *									*
 * Input parameters:							*
 *									*
 * Output parameters:							*
 *	*iret		int		Return code			*
 *					  2 = Bad read.  Ignore record. *
 *					  1 = Setting array siz exceeded*
 *					 -1 = No setting table		*
 **									*
 * Log:									*
 * D. Keiser/GSC	 7/97	Rewrote using union structure		*
 * E. Wehner/EAi	 8/97	Adopted from cpg_rstng			*
 * C. Lin/EAi		 9/97	Change default table name		*
 * G. Krueger/EAI	10/97	CST_xLST: Removed RSPTB; Add str limit	*
 * C. Lin/EAi		10/97	modify to remove cst_clst(), cleanup	*
 * C. Lin/EAi	 	10/97	modify WBOX_ELM				*
 * M. Linda/GSC		10/97	Corrected the prologue format		*
 * C. Lin/EAi	 	11/97	use CLASS_WATCHES for WBOX_ELM		*
 * C. Lin/EAi	 	11/97	add front strength and wind line width	*
 * S. Law/GSC		03/98	Changed scanned values for CLASS_WINDS  *
 * F. J. Yen/NCEP	 4/98	Renamed from ces_rstng.  Cleaned up.	*
 * F. J. Yen/NCEP	 4/98	Set hdsiz for BARB_ELM to 1.		*
 * W. Li/EAI		04/98	Add darr and hash in CLASS_WINDS	*
 * S. Jacobs/NCEP	 6/98	Changed front pip size to type float	*
 * W. Li/EAI		07/98	Added txt_attrib's text value setting	*
 * C. Lin/EAI		09/98	Add smoothing level for line/front	*
 * A. Hardy/GSC		10/98	Added CMBSY_ELM                         *
 * S. Jacobs/NCEP	12/98	Fixed typo				*
 * A. Hardy/GSC		12/98	Added CIRCLE_ELM                        *
 * E. Safford/GSC	02/99	set default for wndtyp to 114 (cleared) *
 * W. Li/EAI		03/99	added latitude/longitude for symbols	*
 * S. Law/GSC		03/99	added filled/closed = 0			*
 * W. Li/EAI		04/99	added MARK_ELM, removed lat/long symbol *
 * S. Law/GSC		05/99	Added CLASS_TRACKS			*
 * S. Law/GSC		07/99	Added CLASS_SIGMETS			*
 * S. Law/GSC		08/99	added remaining SIGMETs			*
 * S. Law/GSC		02/00	added CCF				*
 * H. Zeng/EAI		02/01	added group type info.			*
 * E. Safford/SAIC	02/02	added initialization for new_subtyp	*
 * J. Wu/SAIC		11/02	add class LIST				*
 * M. Li/SAIC		01/03	delete vgstruct.h			*
 * H. Zeng/XTRIA	01/03	added marker info. for Watch		*
 * H. Zeng/XTRIA	03/03	added layer_flag			*
 * D.W.Plummer/NCEP	06/03	added ASHCLD_ELM and VOLC_ELM		*
 * J. Wu/SAIC		09/03	add CLASS_MET -> JET_ELM		*
 * J. Wu/SAIC		01/04	add CLASS_MET -> GFA_ELM		*
 * B. Yin/SAIC		02/04	added CLASS_MET -> TCA_ELM		*
 * J. Wu/SAIC		05/04	add barb/hash color into JET_ELM	*
 * J. Wu/SAIC		05/04	add initialization for "ppid"		*
 * H. Zeng/SAIC		07/04	added check for ialign value		*
 * J. Wu/SAIC		09/04	add text type for jet barb text		*
 * J. Wu/SAIC		10/04   remove line width from GFA_ELM		*
 * T. Piper/SAIC	12/05	redone with new Setting_t structure	*
 * B. Yin/SAIC		12/05	added line width for GFA		*
 * S. Jacobs		03/06	add initialization of special text (bug)*
 * S. Danz/AWC		04/06	initialized jet->barb[]spt.text		*
 * B. Yin/SAIC		07/06	added line type and line elem for GFA	*
 * L. Hinson/AWC        12/06   added text color, size, font, hw, width *
 *                              alignment, and text Layout for GFA      *
 * L. Hinson/AWC        06/07   added arrow size for GFA                *
 * L. Hinson/AWC        07/09   Add color, fills, linetype, szarrow,    *
 *                              text size, font, hw, width, alignment,  *
 *                              and text Layout to CCF                  *
 * L. Hinson/AWC        01/12   Add CLASS_MET -> SGWX_ELM               *
 ***********************************************************************/
{
    char	tstr[256], vg_classstr[64], vg_typestr[64], tmpstr[256];
    int		one=1, smooth, loglev, quit, ier1, ier, jj, align_val;
    int		ii, tmpwid[3], tmpclr[3], ityp, ifnt, ithw, ialign, nn;
    char	grp[4], *ptr;
    float	tmpsiz, tmpsz[3];
    FILE	*fp;
/*---------------------------------------------------------------------*/

    *iret = G_NORMAL;

    /*
     * Open the setting table.  If not found, return an error.
     */

    if ( (fp = (FILE * )cfl_tbop(SETTING_TBL, "pgen", &ier)) == NULL) {
        *iret = -1;
	loglev = 2;
	strcpy(grp, "CES");
	er_lmsg (&loglev, grp, iret, SETTING_TBL, &ier1, strlen(grp),
		 strlen(SETTING_TBL));
        return;
    }

    /* 
     * For every line in the setting table list, read in the record,
     * parse out the fields, and compare to input type.
     */
    jj = num_set = 0;
    quit = G_FALSE;
    while ( ( !quit ) && ( jj < MAX_SET ) ) {

	cfl_trln ( fp, sizeof(tstr), tstr, &ier );

	if ( ier == 4 ) {
	    /*
	     * Here for end of file.
	     */
	    quit = G_TRUE;
	}

	else if ( ier != 0 ) {
	    /*
	     * Here for a bad read; record is ignored.
	     */
	    loglev = 2;
	    strcpy(grp, "CES");
	    ier = 2;
	    er_lmsg ( &loglev, grp, &ier, SETTING_TBL, &ier1,
		      strlen(grp), strlen(SETTING_TBL) );
	}

	else {
	    /*
	     * Here to process a good record.
	     */
	    sscanf(tstr, "%s %s", vg_classstr, vg_typestr);
	    num_set++;
	    G_REALLOC(set, Setting_t, num_set, "set");
	    set[jj].smooth = 0;
	    set[jj].filled = 0;
	    set[jj].closed = 0;

    /*
     * +++++++++++++++++++++++++++++++++++++++++++
     *    HANDLE FRONTS CLASS 
     * +++++++++++++++++++++++++++++++++++++++++++
     */

	    if ( strcmp(vg_classstr, "CLASS_FRONTS" ) == 0 ) {
		set[jj].vg_class = CLASS_FRONTS;
		G_MALLOC(set[jj].info.frt, FrontInfo, one, "set[jj].info.frt");

		sscanf(tstr, "%*s %*s %d %d %d %d %f %d %d %s",
			 &(set[jj].subtyp), &(set[jj].maj_col),
			 &(set[jj].min_col), &smooth, &tmpsiz,
			 &(set[jj].info.frt->fpipdr),
			 &(set[jj].info.frt->fwidth),
			   set[jj].grp_typ );
		
		set[jj].info.frt->fpipsz = (int)(tmpsiz * 100.0F);
		set[jj].info.frt->fcode = set[jj].subtyp;
		set[jj].info.frt->fpipst = 1;
	
		if ( smooth < 0 || smooth > 2 )
		    smooth = 0;
		set[jj].smooth = smooth;

		if ( strcmp(vg_typestr, "FRONT_ELM" ) == 0 ) {
		    set[jj].vg_type = FRONT_ELM;
		}
		else if ( strcmp(vg_typestr, "-99" ) == 0 ) {
		    set[jj].vg_type = DEFLTSET;
		}

	    }
    /*
     * +++++++++++++++++++++++++++++++++++++++++++
     *    HANDLE CIRCLE CLASS 
     * +++++++++++++++++++++++++++++++++++++++++++
     */
	    else if ( strcmp(vg_classstr, "CLASS_CIRCLE") == 0 ) {
		set[jj].vg_class = CLASS_CIRCLE;
		G_MALLOC(set[jj].info.cir, LineInfo, one, "set[jj].info.cir");

		if (strcmp(vg_typestr, "CIRCLE_ELM") == 0) {
		   set[jj].vg_type = CIRCLE_ELM;

		   sscanf(tstr, "%*s %*s %d %d %d %d %d %d %d %s", 
			 &(set[jj].subtyp), 
			 &(set[jj].maj_col), &(set[jj].min_col),
			 &(set[jj].info.cir->lintyp), 
			 &(set[jj].info.cir->lthw),
			 &(set[jj].info.cir->width), 
			 &(set[jj].info.cir->lwhw),
			   set[jj].grp_typ );

		}

	    }
    /*
     * +++++++++++++++++++++++++++++++++++++++++++
     *    HANDLE LINES CLASS 
     * +++++++++++++++++++++++++++++++++++++++++++
     */
	    else if ( strcmp(vg_classstr, "CLASS_LINES") == 0 ) {
		set[jj].vg_class = CLASS_LINES;

		if (strcmp(vg_typestr, "LINE_ELM") == 0) {
		    set[jj].vg_type = LINE_ELM;
		    G_MALLOC(set[jj].info.lin, LineInfo, one, "set[jj].info.lin");
		    sscanf(tstr, "%*s %*s %d %d %d %d %d %d %d %d %s",
			 &(set[jj].subtyp),
			 &(set[jj].maj_col), &(set[jj].min_col),
			 &smooth,
			 &(set[jj].info.lin->lintyp),
			 &(set[jj].info.lin->lthw),
			 &(set[jj].info.lin->width),
			 &(set[jj].info.lin->lwhw),
			   set[jj].grp_typ );

	        }
		else if (strcmp(vg_typestr, "SPLN_ELM") == 0) {
		    set[jj].vg_type = SPLN_ELM;
		    G_MALLOC(set[jj].info.spl, SpLineInfo, one, "set[jj].info.spl");
		    set[jj].info.spl->splstr = 1;

			sscanf(tstr, "%*s %*s %d %d %d %d %d %d %f %d %s",
			&(set[jj].subtyp), 
			&(set[jj].maj_col), &(set[jj].min_col),
			&smooth,
			&(set[jj].info.spl->spltyp), 
			&(set[jj].info.spl->spldir),
			&(set[jj].info.spl->splsiz), 
			&(set[jj].info.spl->splwid),
			set[jj].grp_typ );

		}

		if (smooth < 0 || smooth > 2)
			smooth = 0;
		set[jj].smooth = smooth;

	    }
    /*
     * +++++++++++++++++++++++++++++++++++++++++++
     *    HANDLE SYMBOLS CLASS 
     * +++++++++++++++++++++++++++++++++++++++++++
     */
	    else if ( strcmp(vg_classstr, "CLASS_SYMBOLS") == 0 ) {
		set[jj].vg_class = CLASS_SYMBOLS;
		G_MALLOC(set[jj].info.sym, SymType, one, "set[jj].info.sym");

		if ( strcmp(vg_typestr, "WXSYM_ELM") == 0) {
		    set[jj].vg_type = WXSYM_ELM;
		}
		else if ( strcmp(vg_typestr, "CTSYM_ELM") == 0) {
		    set[jj].vg_type = CTSYM_ELM;
		}
		else if ( strcmp(vg_typestr, "ICSYM_ELM") == 0) {
		    set[jj].vg_type = ICSYM_ELM;
		}
		else if ( strcmp(vg_typestr, "PTSYM_ELM") == 0) {
		    set[jj].vg_type = PTSYM_ELM;
		}
		else if ( strcmp(vg_typestr, "PWSYM_ELM") == 0) {
		    set[jj].vg_type = PWSYM_ELM;
		}
		else if ( strcmp(vg_typestr, "SKSYM_ELM") == 0) {
		    set[jj].vg_type = SKSYM_ELM;
		}
		else if ( strcmp(vg_typestr, "SPSYM_ELM") == 0) {
		    set[jj].vg_type = SPSYM_ELM;
		}
		else if ( strcmp(vg_typestr, "TBSYM_ELM") == 0) {
		    set[jj].vg_type = TBSYM_ELM;
		}
		else if ( strcmp(vg_typestr, "CMBSY_ELM") == 0) {
		    set[jj].vg_type = CMBSY_ELM;
		}
		else if ( strcmp(vg_typestr, "MARK_ELM" ) == 0 ) {
		    set[jj].vg_type = MARK_ELM;
		}
		else if (strcmp(vg_typestr, "-99" ) == 0 ) {
		    set[jj].vg_type = DEFLTSET;
		}
		sscanf(tstr, "%*s %*s %d %d %d %d %f %s", 
			&(set[jj].subtyp),
			&(set[jj].maj_col),
			&(set[jj].min_col),
			&(set[jj].info.sym->info.width),
			&(set[jj].info.sym->info.size),
			 set[jj].grp_typ );

	    }
    /*
     * +++++++++++++++++++++++++++++++++++++++++++
     *    HANDLE WINDS CLASS 
     * +++++++++++++++++++++++++++++++++++++++++++
     */
	    else if ( strcmp(vg_classstr, "CLASS_WINDS") == 0 ) {
		set[jj].vg_class = CLASS_WINDS;
		G_MALLOC(set[jj].info.wnd, WindInfo, one, "set[jj].info.wnd");

		if ( strcmp(vg_typestr, "ARROW_ELM") == 0 ) {
		    set[jj].vg_type = ARROW_ELM;
		    sscanf(tstr, "%*s %*s %d %d %d %d %f %f %s",
			&(set[jj].subtyp),
			&(set[jj].maj_col), &(set[jj].min_col),
			&(set[jj].info.wnd->width),
			&(set[jj].info.wnd->size),
			&(set[jj].info.wnd->hdsiz), set[jj].grp_typ );
		    set[jj].info.wnd->wndtyp = 114;
		}
		else if ( strcmp(vg_typestr, "BARB_ELM") == 0 ) {
		    set[jj].vg_type = BARB_ELM;
		    sscanf(tstr, "%*s %*s %d %d %d %d %f %s",
			 &(set[jj].subtyp), &(set[jj].maj_col),
			 &(set[jj].min_col), &(set[jj].info.wnd->width),
			 &(set[jj].info.wnd->size), set[jj].grp_typ );
		    set[jj].info.wnd->hdsiz = 1.0F;
		    set[jj].info.wnd->wndtyp = 114;

		}
		else if ( strcmp(vg_typestr, "DARR_ELM") == 0 ) {
		    set[jj].vg_type = DARR_ELM;
		    sscanf(tstr, "%*s %*s %d %d %d %d %f %f %s",
			&(set[jj].subtyp),
			&(set[jj].maj_col), &(set[jj].min_col),
			&(set[jj].info.wnd->width),
			&(set[jj].info.wnd->size),
			&(set[jj].info.wnd->hdsiz), set[jj].grp_typ );
		    set[jj].info.wnd->wndtyp = 114;
		}
		else if ( strcmp(vg_typestr, "HASH_ELM") == 0 ) {
		    set[jj].vg_type = HASH_ELM;
		    sscanf(tstr, "%*s %*s %d %d %d %d %f %s",
			&(set[jj].subtyp),
			&(set[jj].maj_col), &(set[jj].min_col),
			&(set[jj].info.wnd->width),
			&(set[jj].info.wnd->size),
			  set[jj].grp_typ );
		    set[jj].info.wnd->hdsiz = 1.0F;
		    set[jj].info.wnd->wndtyp = 1;
		}

	    }
    /*
     * +++++++++++++++++++++++++++++++++++++++++++
     *    HANDLE WBOX CLASS 
     * +++++++++++++++++++++++++++++++++++++++++++
     */
	    else if ( strcmp(vg_classstr, "CLASS_WATCHES") == 0 ) {
		set[jj].vg_class = CLASS_WATCHES;
		G_MALLOC(set[jj].info.wbx, WboxAttr, one, "set[jj].info.wbx");

		sscanf (tstr, "%*s %*s %d %d %d %d %d %f %d %s",
			&(set[jj].subtyp),
			&(set[jj].maj_col), &(set[jj].min_col),
			&(set[jj].info.wbx->w_type),
			&(set[jj].info.wbx->w_mrktyp),
			&(set[jj].info.wbx->w_mrksiz),
			&(set[jj].info.wbx->w_mrkwid), set[jj].grp_typ );

		set[jj].info.wbx->w_number = -9999;

		if (strcmp(vg_typestr, "WBOX_ELM") == 0) { 
		    set[jj].vg_type = WBOX_ELM;
		}
		else if (strcmp(vg_typestr, "-99") == 0) {
		    set[jj].vg_type = DEFLTSET;
		}

	    }
    /*
     * +++++++++++++++++++++++++++++++++++++++++++
     *    HANDLE TEXT CLASS 
     * +++++++++++++++++++++++++++++++++++++++++++
     */
	    else if ( strcmp(vg_classstr, "CLASS_TEXT") == 0 ) {
		set[jj].vg_class = CLASS_TEXT;

		if (strcmp(vg_typestr, "TEXT_ELM") == 0) {
		    set[jj].vg_type = TEXT_ELM;
		    G_MALLOC(set[jj].info.txt, TextType, one, "set[jj].info.txt");

		    sscanf (tstr, "%*s %*s %d %d %d %f %f %d %d %d %s", 
			&(set[jj].subtyp),
			&(set[jj].maj_col), &(set[jj].min_col),
			&(set[jj].info.txt->info.rotn),
			&(set[jj].info.txt->info.sztext),
			&(set[jj].info.txt->info.itxfn),
			&(set[jj].info.txt->info.iwidth), 
			&(set[jj].info.txt->info.ialign),
			  set[jj].grp_typ );

		    set[jj].info.txt->info.ithw = set[jj].subtyp;
		    set[jj].info.txt->text[0] = CHNULL;

		    /*
		     * Make sure ialign value is among (-1, 0, 1).
		     */
		    align_val = set[jj].info.txt->info.ialign;

		    if ( align_val != -1 && align_val != 0 &&
			align_val !=  1			) {

			set[jj].info.txt->info.ialign = 0;
		    }

		}
		else if (strcmp(vg_typestr, "TEXTC_ELM") == 0) {
		    set[jj].vg_type = TEXTC_ELM;
		    G_MALLOC(set[jj].info.txt, TextType, one, "set[jj].info.txt");

		    sscanf (tstr, "%*s %*s %d %d %d %f %f %d %d %d %s",
			&(set[jj].subtyp),
			&(set[jj].maj_col), &(set[jj].min_col),
			&(set[jj].info.txt->info.rotn),
			&(set[jj].info.txt->info.sztext),
			&(set[jj].info.txt->info.itxfn),
			&(set[jj].info.txt->info.iwidth),
			&(set[jj].info.txt->info.ialign),
			  set[jj].grp_typ );
		    set[jj].info.txt->info.ithw = set[jj].subtyp;
		    set[jj].info.txt->text[0] = CHNULL;

		    /*
		     * Make sure ialign value is among (-1, 0, 1).
		     */
		    align_val = set[jj].info.txt->info.ialign;

		    if ( align_val != -1 && align_val != 0 &&
			align_val !=  1			) {

			set[jj].info.txt->info.ialign = 0;
		    }

		}
		else if (strcmp(vg_typestr, "SPTX_ELM") == 0) { 
		    set[jj].vg_type = SPTX_ELM;
		    G_MALLOC(set[jj].info.spt, SpTxtAttr, one, "set[jj].info.spt");

		    sscanf (tstr, "%*s %*s %d %d %d %f %f %d %d %d %d %d %s",
			&(set[jj].subtyp),
			&(set[jj].maj_col), &(set[jj].min_col),
			&(set[jj].info.spt->text.info.rotn),
			&(set[jj].info.spt->text.info.sztext), 
			&(set[jj].info.spt->text.info.turbsym),
			&(set[jj].info.spt->text.info.itxfn), 
			&(set[jj].info.spt->text.info.ithw),
			&(set[jj].info.spt->text.info.iwidth), 
			&(set[jj].info.spt->text.info.ialign),
			  set[jj].grp_typ );
		    set[jj].info.spt->text.info.sptxtyp = set[jj].subtyp;
		    strcpy ( set[jj].info.spt->ppid, DEFLTPPID );
		    set[jj].info.spt->text.text[0] = CHNULL;
		    /*
		     * Make sure ialign value is among (-1, 0, 1).
		     */
		    align_val = set[jj].info.spt->text.info.ialign;

		    if ( align_val != -1 && align_val != 0 &&
			 align_val !=  1			) {

		         set[jj].info.spt->text.info.ialign = 0;
		    }

		}

	    }
    /*
     * +++++++++++++++++++++++++++++++++++++++++++
     *    HANDLE TRACKS CLASS 
     * +++++++++++++++++++++++++++++++++++++++++++
     */
	    else if ( strcmp(vg_classstr, "CLASS_TRACKS") == 0 ) {
		set[jj].vg_class = CLASS_TRACKS;
		G_MALLOC(set[jj].info.trk, TrackInfo, one, "set[jj].info.trk");

		if ( strcmp(vg_typestr, "TRKSTORM_ELM" ) == 0 ) {
		    set[jj].vg_type = TRKSTORM_ELM;
		}
		else if ( strcmp(vg_typestr, "-99" ) == 0 ) {
		    set[jj].vg_type = DEFLTSET;
		}

		sscanf(tstr, "%*s %*s %d %d %d %d %d %d %d %d %d %s",
		    &(set[jj].subtyp),
		    &(set[jj].maj_col), &(set[jj].min_col),
		    &(set[jj].info.trk->ltype1), &(set[jj].info.trk->ltype2),
		    &(set[jj].info.trk->mtype1), &(set[jj].info.trk->mtype2),
		    &(set[jj].info.trk->width), &(set[jj].info.trk->incr),
		    set[jj].grp_typ );
	    }
    /*
     * +++++++++++++++++++++++++++++++++++++++++++
     *    HANDLE SIGMETS CLASS 
     * +++++++++++++++++++++++++++++++++++++++++++
     */
	    else if ( strcmp(vg_classstr, "CLASS_SIGMETS") == 0 ) {
		set[jj].vg_class = CLASS_SIGMETS;

		if ( strcmp(vg_typestr, "SIGAIRM_ELM" ) == 0 ) {
		    set[jj].vg_type = SIGAIRM_ELM;
		}
		else if ( strcmp(vg_typestr, "SIGCONV_ELM" ) == 0 ) {
		    set[jj].vg_type = SIGCONV_ELM;
		}
		else if ( strcmp(vg_typestr, "SIGINTL_ELM" ) == 0 ) {
		    set[jj].vg_type = SIGINTL_ELM;
		}
		else if ( strcmp(vg_typestr, "SIGNCON_ELM" ) == 0 ) {
		    set[jj].vg_type = SIGNCON_ELM;
		}
		else if ( strcmp(vg_typestr, "SIGOUTL_ELM" ) == 0 ) {
		    set[jj].vg_type = SIGOUTL_ELM;
		}
		else if ( strcmp(vg_typestr, "SIGCCF_ELM" ) == 0 ) {
		    set[jj].vg_type = SIGCCF_ELM;
		}
		else if ( strcmp(vg_typestr, "ASHCLD_ELM" ) == 0 ) {
		    set[jj].vg_type = ASHCLD_ELM;
		}
		else if ( strcmp(vg_typestr, "VOLC_ELM" ) == 0 ) {
		    set[jj].vg_type = VOLC_ELM;
		}
		else if ( strcmp(vg_typestr, "-99" ) == 0 ) {
		    set[jj].vg_type = DEFLTSET;
		}

		if (set[jj].vg_type == SIGCCF_ELM) {
                    G_MALLOC(set[jj].info.ccf, CcfAttr, one, "set[jj].info.ccf");		    
                    sscanf(tstr, "%*s %*s %d %d %d %d %d %d %d %d %f %f %d %d %d %d %s %s",
                      &(set[jj].subtyp), &(set[jj].smooth),
                      &(set[jj].maj_col), &(set[jj].min_col),
                      &(set[jj].info.ccf->fillhi),
                      &(set[jj].info.ccf->fillmed),
                      &(set[jj].info.ccf->filllow),
                      &(set[jj].info.ccf->linetype),
                      &(set[jj].info.ccf->szarrow),
                      &(set[jj].info.ccf->info.sztext),
                      &(set[jj].info.ccf->info.itxfn),
                      &(set[jj].info.ccf->info.ithw),
                      &(set[jj].info.ccf->info.iwidth),
                      &(set[jj].info.ccf->info.ialign),
                      set[jj].info.ccf->textLayout,
                      set[jj].grp_typ );
                    /* printf("subtyp = %d, smooth=%d, maj_col=%d, min_col=%d, fillhi=%d, fillmed=%d, filllow=%d\n", 
                      set[jj].subtyp, set[jj].smooth, set[jj].maj_col, set[jj].min_col, 
                      set[jj].info.ccf->fillhi, set[jj].info.ccf->fillmed, set[jj].info.ccf->filllow);
                    printf("linetype=%d, szarrow=%f, sztext=%f, itxfn=%d, ithw=%d, iwidth=%d ialign=%d\n",
                      set[jj].info.ccf->linetype, set[jj].info.ccf->szarrow, 
                      set[jj].info.ccf->info.sztext,
                      set[jj].info.ccf->info.itxfn, set[jj].info.ccf->info.ithw, set[jj].info.ccf->info.iwidth,
                      set[jj].info.ccf->info.ialign);
                    printf("tlayout=%s grptyp=%s\n",set[jj].info.ccf->textLayout, set[jj].grp_typ); */
                      
		}
		else if (set[jj].vg_type == ASHCLD_ELM) {
		    G_MALLOC(set[jj].info.ash, SigAttr, one, "set[jj].info.ash");
		    sscanf(tstr, "%*s %*s %d %d %d %d %s", 
			   &(set[jj].subtyp), &(set[jj].maj_col),
			   &(set[jj].min_col), &(set[jj].smooth),
			   set[jj].grp_typ );
		}
		else if (set[jj].vg_type == VOLC_ELM) {
		    G_MALLOC(set[jj].info.vol, VolAttr, one, "set[jj].info.vol");
		    sscanf(tstr, "%*s %*s %d %d %d %d %f %s",
			   &(set[jj].subtyp), &(set[jj].maj_col),
			   &(set[jj].min_col),&(set[jj].info.vol->width),
			   &(set[jj].info.vol->size), set[jj].grp_typ );
		}
		else {
		    G_MALLOC(set[jj].info.sig, SigAttr, one, "set[jj].info.sig");
		    sscanf(tstr, "%*s %*s %d %d %d %d %d %s",
			   &(set[jj].subtyp),
			   &(set[jj].maj_col), &(set[jj].min_col),
			   &(set[jj].info.sig->lintyp), 
			   &(set[jj].info.sig->linwid),
			     set[jj].grp_typ );
		}
	    }

    /*
     * +++++++++++++++++++++++++++++++++++++++++++
     *    HANDLE LIST CLASS 
     * +++++++++++++++++++++++++++++++++++++++++++
     */
	    else if ( strcmp(vg_classstr, "CLASS_LIST") == 0 ) {
		set[jj].vg_class = CLASS_LIST;
		G_MALLOC(set[jj].info.lst, ListInfo, one, "set[jj].info.lst");

		if ( strcmp(vg_typestr, "LIST_ELM") == 0 ) {
		    set[jj].vg_type = LIST_ELM;
		    sscanf ( tstr, "%*s %*s %d %d %d %d %f %d %s",
			&(set[jj].subtyp),
			&(set[jj].maj_col),
			&(set[jj].min_col),
			&(set[jj].info.lst->mrktyp),
			&(set[jj].info.lst->mrksiz),
			&(set[jj].info.lst->mrkwid),
			  set[jj].grp_typ );

		     set[jj].info.lst->subtyp = set[jj].subtyp;
		}

	    }

    /*
     * +++++++++++++++++++++++++++++++++++++++++++
     *    HANDLE MET CLASS 
     * +++++++++++++++++++++++++++++++++++++++++++
     */
	    else if ( strcmp(vg_classstr, "CLASS_MET") == 0 ) {
		set[jj].vg_class = CLASS_MET;

		if ( strcmp(vg_typestr, "JET_ELM") == 0 ) {
		    set[jj].vg_type = JET_ELM;
 		    G_MALLOC(set[jj].info.jet, JetInfo, one, "set[jj].info.jet");
		    /*
		       *  Check the number of items in setting.tbl.
		       *  ( 22 - version 5.7.4 & later; 21 for earlier versions.
		       */
		    strcpy ( tmpstr, tstr );
		    cst_nocc ( tmpstr, '!', 1, 0, &nn, &ier );

		    if ( ier == 0 ) {
		        tmpstr[nn] = '\0';
		        cst_lstr ( tmpstr, &nn, &ier );
		        tmpstr[nn] = '\0';
		    }

		    nn = 0;
		    ptr = strtok ( tmpstr, " " );
		    while ( (ptr != (char *)NULL) ) {
			ptr = strtok ( NULL, " " );
			nn++;
		    }

		    if ( nn < 22 ) {  /* Version 5.7.3 & before */
			sscanf ( tstr, "%*s %*s %d %d %d %d %d %f %d %d %f %d %f %d %d %d %d %d %f %d %s",
			    &(set[jj].subtyp),
			    &(set[jj].maj_col), &(set[jj].min_col), &smooth,
			    &(set[jj].info.jet->line.spltyp),
			    &(set[jj].info.jet->line.splsiz),
			    &(set[jj].info.jet->line.splwid),
			    &tmpclr[0], &tmpsz[0], &tmpwid[0],			/* Barb */
			    &tmpsz[1], &ifnt, &ithw, &tmpwid[1], &ialign,	/* Text */
			    &tmpclr[1], &tmpsz[2], &tmpwid[2],			/* Hash */
			    set[jj].grp_typ );

			    ityp = 0;
		    }
		    else {  /* Version 5.7.4 and later */
		        sscanf ( tstr, "%*s %*s %d %d %d %d %d %f %d %d %f %d %d %f %d %d %d %d %d %f %d %s",
			    &(set[jj].subtyp),
			    &(set[jj].maj_col), &(set[jj].min_col), &smooth,
			    &(set[jj].info.jet->line.spltyp),
			    &(set[jj].info.jet->line.splsiz),
			    &(set[jj].info.jet->line.splwid),
			    &tmpclr[0], &tmpsz[0], &tmpwid[0],				/* Barb */
			    &ityp, &tmpsz[1], &ifnt, &ithw, &tmpwid[1], &ialign,	/* Text */
			    &tmpclr[1], &tmpsz[2], &tmpwid[2],				/* Hash */
			    set[jj].grp_typ );
		    }
		    
		    if (smooth < 0 || smooth > 2) smooth = 0;
		    set[jj].smooth = smooth;
		    set[jj].info.jet->splcol = set[jj].maj_col;
		    set[jj].info.jet->line.splstr = 1;
		    set[jj].info.jet->line.spldir = 0;


		    for ( ii = 0; ii < MAX_JETPTS; ii++ ) {
		        set[jj].info.jet->barb[ii].wndcol = tmpclr[0];
		        set[jj].info.jet->barb[ii].wnd.info.size = tmpsz[0];
		        set[jj].info.jet->barb[ii].wnd.info.width = tmpwid[0];
		        set[jj].info.jet->barb[ii].wnd.info.wndtyp = 114;
		        set[jj].info.jet->barb[ii].wnd.info.hdsiz = 1.0F;
		        set[jj].info.jet->barb[ii].sptcol = tmpclr[0];
			set[jj].info.jet->barb[ii].spt.info.sztext = tmpsz[1];
		        set[jj].info.jet->barb[ii].spt.info.itxfn = ifnt;
		        set[jj].info.jet->barb[ii].spt.info.ithw = ithw;
		        set[jj].info.jet->barb[ii].spt.info.iwidth = tmpwid[1];
		        set[jj].info.jet->barb[ii].spt.info.ialign = ialign;
		        set[jj].info.jet->barb[ii].spt.info.rotn = 0.0F;
		        set[jj].info.jet->barb[ii].spt.info.sptxtyp = ityp;
		        set[jj].info.jet->barb[ii].spt.info.turbsym = 0;
		        set[jj].info.jet->barb[ii].spt.info.txtcol = tmpclr[0];
		        set[jj].info.jet->barb[ii].spt.info.filcol = tmpclr[0];
		        set[jj].info.jet->barb[ii].spt.info.lincol = tmpclr[0];
			set[jj].info.jet->barb[ii].spt.text[0] = CHNULL;
		        set[jj].info.jet->hash[ii].wndcol = tmpclr[1];
		        set[jj].info.jet->hash[ii].wnd.info.size = tmpsz[2];
		        set[jj].info.jet->hash[ii].wnd.info.width = tmpwid[2];
		        set[jj].info.jet->hash[ii].wnd.info.wndtyp = 1;	
		        set[jj].info.jet->hash[ii].wnd.info.hdsiz = 1.0F;			
		    }

		}

		else if ( strcmp(vg_typestr, "GFA_ELM") == 0 ) {
		    set[jj].vg_type = GFA_ELM;
		    G_MALLOC(set[jj].info.gfa, GfaAttr, one, "set[jj].info.gfa");
          
		    sscanf(tstr, "%*s %*s %d %d %d %d %d %d %f %d %f %d %d %d %d %s %s", 
			   &(set[jj].subtyp), &(set[jj].maj_col), 
			   &(set[jj].min_col), &(set[jj].info.gfa->linelm), 
			   &(set[jj].info.gfa->lintyp),&(set[jj].info.gfa->linwid),
                           &(set[jj].info.gfa->szarrow),
                           &(set[jj].info.gfa->info.txtcol),
                           &(set[jj].info.gfa->info.sztext),
                           &(set[jj].info.gfa->info.itxfn),
                           &(set[jj].info.gfa->info.ithw),
                           &(set[jj].info.gfa->info.iwidth),
                           &(set[jj].info.gfa->info.ialign),
                           set[jj].info.gfa->textLayout,
			   set[jj].grp_typ );
		}
                else if ( strcmp(vg_typestr, "SGWX_ELM") == 0 ) {
                  set[jj].vg_type = SGWX_ELM;
                  G_MALLOC(set[jj].info.sgwx, SgwxAttr, one, "set[jj].info.sgwx");
                  sscanf(tstr, "%*s %*s %d %d %d %d %d %d %d %f %f %d %d %d %d %s",
                    &(set[jj].subtyp), &(set[jj].smooth),
                    &(set[jj].maj_col), &(set[jj].min_col),
                    &(set[jj].info.sgwx->lineelm),
                    &(set[jj].info.sgwx->linetype),
                    &(set[jj].info.sgwx->linewidth),
                    &(set[jj].info.sgwx->szarrow),
                    &(set[jj].info.sgwx->info.sztext),
                    &(set[jj].info.sgwx->info.itxfn),
                    &(set[jj].info.sgwx->info.ithw),
                    &(set[jj].info.sgwx->info.iwidth),
                    &(set[jj].info.sgwx->info.ialign),
                    set[jj].grp_typ );
                }
		else if ( strcmp(vg_typestr, "TCA_ELM") == 0 ) {
		    set[jj].vg_type = TCA_ELM;
		    G_MALLOC(set[jj].info.tca, TcaInfo, one, "set[jj].info.tca");

		    sscanf(tstr, "%*s %*s %d %d %d %d %s",
                           &set[jj].subtyp, &set[jj].maj_col, &set[jj].min_col,
                           &set[jj].info.tca->wwNum, set[jj].grp_typ );
	}

	    }

	    /*
	     * ++++++++++++++++++++++++++++++++++++++++++++++++++++++
	     *    DIDN'T RECOGNIZE THE CLASS; BAD READ, IGNORE RECORD 
	     * ++++++++++++++++++++++++++++++++++++++++++++++++++++++
	     */
	    else {
		*iret = 2;
	        loglev = 2;
		strcpy(grp, "CES");
		er_lmsg (&loglev, grp, iret, SETTING_TBL, &ier1, strlen(grp),
		         strlen(SETTING_TBL));
	    }

        /*
         * Set layer_flag according to set[jj].grp_typ
         */
            cst_lcuc(set[jj].grp_typ, set[jj].grp_typ, &ier1);
	    if ( strstr ( set[jj].grp_typ, "/LAYER" ) != NULL ) {
                 set[jj].cds_or_ces.layer_flag = TRUE;
	    }
	    else {
		set[jj].cds_or_ces.layer_flag = FALSE;
	    }

	    /*
	     * Increment jj
	     */
	    jj++;

	}

    }

    if ( !quit ) {
	/*
	 * Setting array (set) size exceeded.  MAX_SET should
	 * be increased.
	 */
	*iret = 1;
	loglev = 2;
	strcpy(grp, "CES");
	er_lmsg (&loglev, grp, iret, SETTING_TBL, &ier1, strlen(grp),
		 strlen(SETTING_TBL));
    }

    /* close the settings file */
    cfl_clos(fp, &ier);
}
Ejemplo n.º 25
0
void INITIA()
{
    /*   this routine initializes the positions of the molecules along
         a regular cubical lattice, and randomizes the initial velocities of
         the atoms.  The random numbers used in the initialization of velocities
         are read from the file random.in, which must be in the current working
         directory in which the program is run  */

    FILE *random_numbers;       /* points to input file containing
                                   pseudo-random numbers for initializing
                                   velocities */
    double XMAS[4];
    double SUX, SUY, SUZ, SUMX, SUMY, SUMZ, FAC;
    long X_INDEX, Y_INDEX, Z_INDEX;
    long atom=0;
    long i, j, k;
    struct link *link_ptr, *curr_ptr, *last_ptr;
#ifdef RANDOM
    long Part_per_box, Unassigned, m, pid;
#else
    long mol = 0, XT[4], YT[4], Z;
#endif

#ifdef SIM_SOCLIB
	extern int * SOCLIB_STATIC_MEM;
	double * static_var = (double *) SOCLIB_STATIC_MEM ;
	int32_t retval = 0; 
	printf("address de la variable statique : %x\n",static_var);
	random_numbers = fopen ("/devices/fdaccess", "r+");
	vfs_component . operation . ioctl (fileno(random_numbers), FD_OPEN, "random.in", & retval);
	if (retval < 0) printf ("Error opening the random file.\r\n");
#else
	random_numbers = fopen("random.in","r");
#endif
    if (random_numbers == NULL) {
        fprintf(stderr,"Error in opening file random.in\n");
        fflush(stderr);
        exit(-1);
    }

    XMAS[1]=sqrt(OMAS*HMAS);
    XMAS[0]=HMAS;
    XMAS[2]=HMAS;

    /* .....assign positions */

    {
        long deriv;

        double NS = pow((double) NMOL, 1.0/3.0) - 0.00000000000001;
        double XS = BOXL/NS;
        double ZERO = XS * 0.50;
        double WCOS = ROH * cos(ANGLE * 0.5);
        double WSIN = ROH * sin(ANGLE * 0.5);

        printf("\nNS = %.16f\n",NS);
        printf("BOXL = %10f\n",BOXL);
        printf("CUTOFF = %10f\n",CUTOFF);
        printf("BOX_LENGTH = %10f\n",BOX_LENGTH);
        printf("BOX_PER_SIDE = %ld\n",BOX_PER_SIDE);
        printf("XS = %10f\n",XS);
        printf("ZERO = %g\n",ZERO);
        printf("WCOS = %f\n",WCOS);
        printf("WSIN = %f\n",WSIN);
        fflush(stdout);

#ifdef RANDOM
        /* if we want to initialize to a random distribution of displacements
           for the molecules, rather than a distribution along a regular lattice
           spaced according to intermolecular distances in water */

        srand(1023);
#ifndef SIM_SOCLIB
    fscanf(random_numbers,"%lf",static_var);
	SUX = *static_var;
#else
    fscanf(random_numbers,"%lf",&SUX);
#endif

        SUMX=0.0;
        SUMY=0.0;
        SUMZ=0.0;

        Part_per_box = NMOL / (BOX_PER_SIDE * BOX_PER_SIDE * BOX_PER_SIDE);
        Unassigned = NMOL - (Part_per_box * BOX_PER_SIDE * BOX_PER_SIDE * BOX_PER_SIDE);
        printf("Part_per_box = %ld, BOX_PER_SIDE = %ld, Unassigned = %ld\n",Part_per_box, BOX_PER_SIDE, Unassigned);
        for (i = 0; i < BOX_PER_SIDE; i++)
            for (j = 0; j < BOX_PER_SIDE; j++)
                for (k = 0; k < BOX_PER_SIDE; k++)
                    for (m = 0; m < Part_per_box; m++) {
                        link_ptr = (struct link *) G_MALLOC(sizeof(link_type));
                        link_ptr->mol.F[DISP][XDIR][O] = xrand(BOX_LENGTH * i, BOX_LENGTH * (i+1));
                        link_ptr->mol.F[DISP][XDIR][H1] = link_ptr->mol.F[DISP][XDIR][O] + WCOS;
                        link_ptr->mol.F[DISP][XDIR][H2] = link_ptr->mol.F[DISP][XDIR][H1];
                        link_ptr->mol.F[DISP][YDIR][O] = xrand(BOX_LENGTH * j, BOX_LENGTH * (j+1));
                        link_ptr->mol.F[DISP][YDIR][H1] = link_ptr->mol.F[DISP][YDIR][O] + WSIN;
                        link_ptr->mol.F[DISP][YDIR][H2] = link_ptr->mol.F[DISP][YDIR][O] - WSIN;
                        link_ptr->mol.F[DISP][ZDIR][O] = xrand(BOX_LENGTH * k, BOX_LENGTH * (k+1));
                        link_ptr->mol.F[DISP][ZDIR][H1] = link_ptr->mol.F[DISP][ZDIR][O];
                        link_ptr->mol.F[DISP][ZDIR][H2] = link_ptr->mol.F[DISP][ZDIR][O];

                        for (atom = 0; atom < NATOMS; atom++) {
                            /* read random velocities from file random.in */
#ifndef SIM_SOCLIB
			fscanf(random_numbers,"%lf",&link_ptr->mol.F[VEL][XDIR][atom]);
			fscanf(random_numbers,"%lf",&link_ptr->mol.F[VEL][YDIR][atom]);
			fscanf(random_numbers,"%lf",&link_ptr->mol.F[VEL][ZDIR][atom]);
#else
			fscanf(random_numbers,"%lf",static_var);
			link_ptr->mol.F[VEL][XDIR][atom] = *static_var;
			fscanf(random_numbers,"%lf",static_var);
			link_ptr->mol.F[VEL][YDIR][atom] = *static_var;
			fscanf(random_numbers,"%lf",static_var);
			link_ptr->mol.F[VEL][ZDIR][atom] = *static_var;
#endif
                            SUMX = SUMX + link_ptr->mol.F[VEL][XDIR][atom];
                            SUMY = SUMY + link_ptr->mol.F[VEL][YDIR][atom];
                            SUMZ = SUMZ + link_ptr->mol.F[VEL][ZDIR][atom];
                            /* set acceleration and all higher-order derivatives to zero */
                            for (deriv = ACC; deriv < MAXODR; deriv++) {
                                link_ptr->mol.F[deriv][XDIR][atom] = 0.0;
                                link_ptr->mol.F[deriv][YDIR][atom] = 0.0;
                                link_ptr->mol.F[deriv][ZDIR][atom] = 0.0;
                            }
                        }

                        link_ptr->next_mol = NULL;        /* Terminating link */

                        /* update box indices in all three dimensions */
                        X_INDEX = (long) (link_ptr->mol.F[DISP][XDIR][O]/BOX_LENGTH);
                        Y_INDEX = (long) (link_ptr->mol.F[DISP][YDIR][O]/BOX_LENGTH);
                        Z_INDEX = (long) (link_ptr->mol.F[DISP][ZDIR][O]/BOX_LENGTH);

                        /* Put X_, Y_, and Z_INDEX back in box */

                        if (X_INDEX >=BOX_PER_SIDE) X_INDEX -= 1;
                        if (Y_INDEX >=BOX_PER_SIDE) Y_INDEX -= 1;
                        if (Z_INDEX >=BOX_PER_SIDE) Z_INDEX -= 1;

                        /* get list ptr */
                        curr_ptr = BOX[X_INDEX][Y_INDEX][Z_INDEX].list;

                        if (curr_ptr == NULL) {             /* No links in box yet */
                            BOX[X_INDEX][Y_INDEX][Z_INDEX].list = link_ptr;
                        } else {
                            while (curr_ptr) {               /* Scan to end of list */
                                last_ptr = curr_ptr;
                                curr_ptr = curr_ptr->next_mol;
                            } /* while curr_ptr */
                            last_ptr->next_mol = link_ptr;    /* Add to end of list */
                        } /* if curr_ptr */
                    }

        /* distribute the unassigned molecules evenly among processors */
        pid = 0;
        for (i = 0; i < Unassigned; i++) {
            link_ptr = (struct link *) G_MALLOC(sizeof(link_type));
            link_ptr->mol.F[DISP][XDIR][O] = xrand(BOX_LENGTH * start_end[pid]->box[XDIR][FIRST], BOX_LENGTH * (start_end[pid]->box[XDIR][LAST] + 1));
            link_ptr->mol.F[DISP][XDIR][H1] = link_ptr->mol.F[DISP][XDIR][O] + WCOS;
            link_ptr->mol.F[DISP][XDIR][H2] = link_ptr->mol.F[DISP][XDIR][H1];
            link_ptr->mol.F[DISP][YDIR][O] = xrand(BOX_LENGTH * start_end[pid]->box[YDIR][FIRST], BOX_LENGTH * (start_end[pid]->box[YDIR][LAST] + 1));
            link_ptr->mol.F[DISP][YDIR][H1] = link_ptr->mol.F[DISP][YDIR][O] + WSIN;
            link_ptr->mol.F[DISP][YDIR][H2] = link_ptr->mol.F[DISP][YDIR][O] - WSIN;
            link_ptr->mol.F[DISP][ZDIR][O] = xrand(BOX_LENGTH * start_end[pid]->box[ZDIR][FIRST], BOX_LENGTH * (start_end[pid]->box[ZDIR][LAST] + 1));
            link_ptr->mol.F[DISP][ZDIR][H1] = link_ptr->mol.F[DISP][ZDIR][O];
            link_ptr->mol.F[DISP][ZDIR][H2] = link_ptr->mol.F[DISP][ZDIR][O];

            pid = (pid + 1) % NumProcs;

            /* read random velocities from file random.in */
            for (atom = 0; atom < NATOMS; atom++) {
#ifndef SIM_SOCLIB
			fscanf(random_numbers,"%lf",&link_ptr->mol.F[VEL][XDIR][atom]);
			fscanf(random_numbers,"%lf",&link_ptr->mol.F[VEL][YDIR][atom]);
			fscanf(random_numbers,"%lf",&link_ptr->mol.F[VEL][ZDIR][atom]);
#else
			fscanf(random_numbers,"%lf",static_var);
			link_ptr->mol.F[VEL][XDIR][atom] = *static_var;
			fscanf(random_numbers,"%lf",static_var);
			link_ptr->mol.F[VEL][YDIR][atom] = *static_var;
			fscanf(random_numbers,"%lf",static_var);
			link_ptr->mol.F[VEL][ZDIR][atom] = *static_var;
#endif
                SUMX = SUMX + link_ptr->mol.F[VEL][XDIR][atom];
                SUMY = SUMY + link_ptr->mol.F[VEL][YDIR][atom];
                SUMZ = SUMZ + link_ptr->mol.F[VEL][ZDIR][atom];
                /* set acceleration and all higher derivatives to zero */
                for (deriv = ACC; deriv < MAXODR; deriv++) {
                    link_ptr->mol.F[deriv][XDIR][atom] = 0.0;
                    link_ptr->mol.F[deriv][YDIR][atom] = 0.0;
                    link_ptr->mol.F[deriv][ZDIR][atom] = 0.0;
                }
            }

            link_ptr->next_mol = NULL;        /* Terminating link */

            /* updated box indices in all dimensions */

            X_INDEX = (long) (link_ptr->mol.F[DISP][XDIR][O]/BOX_LENGTH);
            Y_INDEX = (long) (link_ptr->mol.F[DISP][YDIR][O]/BOX_LENGTH);
            Z_INDEX = (long) (link_ptr->mol.F[DISP][ZDIR][O]/BOX_LENGTH);

            /* Put X_, Y_, and Z_INDEX back in box */

            if (X_INDEX >=BOX_PER_SIDE) X_INDEX -= 1;
            if (Y_INDEX >=BOX_PER_SIDE) Y_INDEX -= 1;
            if (Z_INDEX >=BOX_PER_SIDE) Z_INDEX -= 1;

            /* get list ptr */
            curr_ptr = BOX[X_INDEX][Y_INDEX][Z_INDEX].list;

            if (curr_ptr == NULL) {             /* No links in box yet */
                BOX[X_INDEX][Y_INDEX][Z_INDEX].list = link_ptr;
            } else {
                while (curr_ptr) {               /* Scan to end of list */
                    last_ptr = curr_ptr;
                    curr_ptr = curr_ptr->next_mol;
                } /* while curr_ptr */
                last_ptr->next_mol = link_ptr;    /* Add to end of list */
            } /* if curr_ptr */
        }

#else
        /* not random initial placement, but rather along a regular
           lattice.  This is the default and the prefered initialization
           since random does not necessarily make sense from the viewpoint
           of preserving bond distances */

        fprintf(six, "***** NEW RUN STARTING FROM REGULAR LATTICE *****\n");
        fflush(six);
        XT[2] = ZERO;
        mol = 0;
#ifdef SIM_SOCLIB
    fscanf(random_numbers,"%lf",static_var);
	SUX = *static_var;
#else
    fscanf(random_numbers,"%lf",&SUX);
#endif

        SUMX=0.0;
        SUMY=0.0;
        SUMZ=0.0;

        /* Generate displacements along a regular lattice */

        for (i=0; i < NS; i++) {
            XT[1]=XT[2]+WCOS;
            XT[3]=XT[1];
            YT[2]=ZERO;
            for (j=0; j < NS; j+=1) {
                YT[1]=YT[2]+WSIN;
                YT[3]=YT[2]-WSIN;
                Z=ZERO;
                for (k = 0; k < NS; k++) {
                    link_ptr = (struct link *) G_MALLOC(sizeof(link_type));
                    for (atom = 0; atom < NATOMS; atom++) {

                        /* displacements for atom */
                        link_ptr->mol.F[DISP][XDIR][atom] = XT[atom+1];
                        link_ptr->mol.F[DISP][YDIR][atom] = YT[atom+1];
                        link_ptr->mol.F[DISP][ZDIR][atom] = Z;

#ifndef SIM_SOCLIB
			fscanf(random_numbers,"%lf",&link_ptr->mol.F[VEL][XDIR][atom]);
			fscanf(random_numbers,"%lf",&link_ptr->mol.F[VEL][YDIR][atom]);
			fscanf(random_numbers,"%lf",&link_ptr->mol.F[VEL][ZDIR][atom]);
#else
			fscanf(random_numbers,"%lf",static_var);
			link_ptr->mol.F[VEL][XDIR][atom] = *static_var;
			fscanf(random_numbers,"%lf",static_var);
			link_ptr->mol.F[VEL][YDIR][atom] = *static_var;
			fscanf(random_numbers,"%lf",static_var);
			link_ptr->mol.F[VEL][ZDIR][atom] = *static_var;
#endif
                        /* read random velocities from file random.in */
                        SUMX = SUMX + link_ptr->mol.F[VEL][XDIR][atom];
                        SUMY = SUMY + link_ptr->mol.F[VEL][YDIR][atom];
                        SUMZ = SUMZ + link_ptr->mol.F[VEL][ZDIR][atom];
                        for (deriv = ACC; deriv < MAXODR; deriv++) {
                            link_ptr->mol.F[deriv][XDIR][atom] = 0.0;
                            link_ptr->mol.F[deriv][YDIR][atom] = 0.0;
                            link_ptr->mol.F[deriv][ZDIR][atom] = 0.0;
                        }
                    }

                    link_ptr->next_mol = NULL;        /* Terminating link */
                    mol++;
                    Z += XS;

                    /* update box numbers in all dimensions */

                    X_INDEX = (long) (link_ptr->mol.F[DISP][XDIR][O]/BOX_LENGTH);
                    Y_INDEX = (long) (link_ptr->mol.F[DISP][YDIR][O]/BOX_LENGTH);
                    Z_INDEX = (long) (link_ptr->mol.F[DISP][ZDIR][O]/BOX_LENGTH);

                    /* Put X_, Y_, and Z_INDEX back in box */

                    if (X_INDEX >=BOX_PER_SIDE) X_INDEX -= 1;
                    if (Y_INDEX >=BOX_PER_SIDE) Y_INDEX -= 1;
                    if (Z_INDEX >=BOX_PER_SIDE) Z_INDEX -= 1;

                    /* get list ptr */
                    curr_ptr = BOX[X_INDEX][Y_INDEX][Z_INDEX].list;

                    if (curr_ptr == NULL) {             /* No links in box yet */
                        BOX[X_INDEX][Y_INDEX][Z_INDEX].list = link_ptr;
                    } else {
                        while (curr_ptr) {               /* Scan to end of list */
                            last_ptr = curr_ptr;
                            curr_ptr = curr_ptr->next_mol;
                        } /* while curr_ptr */
                        last_ptr->next_mol = link_ptr;    /* Add to end of list */
                    } /* if curr_ptr */

                } /* for k */
                YT[2] += XS;
            } /* for j */
            XT[2] += XS;
        } /* for i */

        if (NMOL != mol) {
            printf("Lattice init error: total mol %ld != NMOL %ld\n", mol, NMOL);
            exit(-1);
        }
#endif
    }
    /* assign random momenta */
    /* find average momenta per atom */

    SUMX=SUMX/(NATOMS*NMOL);
    SUMY=SUMY/(NATOMS*NMOL);
    SUMZ=SUMZ/(NATOMS*NMOL);

    /*  find normalization factor so that <k.e.>=KT/2  */

    SUX=0.0;
    SUY=0.0;
    SUZ=0.0;

    for (i=0; i<BOX_PER_SIDE; i++) {
        for (j=0; j<BOX_PER_SIDE; j++) {
            for (k=0; k<BOX_PER_SIDE; k++) {
                curr_ptr = BOX[i][j][k].list;
                while (curr_ptr) {
                    SUX = SUX +
                        (pow( (curr_ptr->mol.F[VEL][XDIR][H1] - SUMX),2.0)
                         +pow( (curr_ptr->mol.F[VEL][XDIR][H2] - SUMX),2.0))/HMAS
                             +pow( (curr_ptr->mol.F[VEL][XDIR][O]  - SUMX),2.0)/OMAS;

                    SUY = SUY +
                        (pow( (curr_ptr->mol.F[VEL][YDIR][H1] - SUMY),2.0)
                         +pow( (curr_ptr->mol.F[VEL][YDIR][H2] - SUMY),2.0))/HMAS
                             +pow( (curr_ptr->mol.F[VEL][YDIR][O]  - SUMY),2.0)/OMAS;

                    SUZ = SUZ +
                        (pow( (curr_ptr->mol.F[VEL][ZDIR][H1] - SUMZ),2.0)
                         + pow( (curr_ptr->mol.F[VEL][ZDIR][H2] - SUMZ),2.0))/HMAS
                             +pow( (curr_ptr->mol.F[VEL][ZDIR][O]  - SUMZ),2.0)/OMAS;

                    curr_ptr = curr_ptr->next_mol;
                } /* while curr_ptr */
            }
        }
    } /* for boxes */

    FAC=BOLTZ*TEMP*NATMO/UNITM * pow((UNITT*TSTEP/UNITL),2.0);
    SUX=sqrt(FAC/SUX);
    SUY=sqrt(FAC/SUY);
    SUZ=sqrt(FAC/SUZ);

    /* normalize individual velocities so that there are no bulk momenta  */

    XMAS[1]=OMAS;
    for (i=0; i<BOX_PER_SIDE; i++) {
        for (j=0; j<BOX_PER_SIDE; j++) {
            for (k=0; k<BOX_PER_SIDE; k++) {
                curr_ptr = BOX[i][j][k].list;
                while (curr_ptr) {
                    for (atom = 0; atom < NATOMS; atom++) {
                        curr_ptr->mol.F[VEL][XDIR][atom] =
                            ( curr_ptr->mol.F[VEL][XDIR][atom] -
                             SUMX) * SUX/XMAS[atom];
                        curr_ptr->mol.F[VEL][YDIR][atom] =
                            ( curr_ptr->mol.F[VEL][YDIR][atom] -
                             SUMY) * SUY/XMAS[atom];
                        curr_ptr->mol.F[VEL][ZDIR][atom] =
                            ( curr_ptr->mol.F[VEL][ZDIR][atom] -
                             SUMZ) * SUZ/XMAS[atom];
                    } /* for atom */
                    curr_ptr = curr_ptr->next_mol;
                } /* while curr_ptr */
            }
        }
    } /* for box */

#ifdef SIM_SOCLIB
	vfs_component . operation . ioctl (fileno(random_numbers), FD_CLOSE, "random.in", & retval);
	if (retval < 0) printf ("Error closing the video file.\r\n");
    //fclose(random_numbers); avoid a call to an unimplemented function : vfs_lseek
#else
    fclose(random_numbers);
#endif
} /* end of subroutine INITIA */