예제 #1
0
static int
join_action(char *glb[2],char *epoch[2],setup_params_t *setup, ibeid_t *id, prefls_t *pfixlist)
{
      int rv=0; 
      action_data_t *act_p = NULL;
      
      if(!setup || !id ||!pfixlist ) {
    	  errno = EINVAL;
    	  return -1;
      }

      //join init
      rv = join_init(&act_p,setup,pfixlist);
      if(rv < 0)
            pbgp_die("join initialization failed. Aborting. \n");

      //ids load
      rv = ids_load(glb[0],act_p->glb.act);
      rv -= ids_load(glb[1],act_p->glb.rvk);
      rv -= ids_load(epoch[0],act_p->epoch.act);
      rv -= ids_load(epoch[1],act_p->epoch.rvk);
      if(rv < 0) 
            pbgp_die("init_ids fid_load \n");
      
      //idarray init
      idarray_init(act_p->glb.act,act_p->glb.rvk,setup);
      idarray_init(act_p->epoch.act,act_p->epoch.rvk,setup);
    
      //set prefix list 
      act_p->ibk->id->asnum=id->asnum;

      //do join
      do_join(act_p,setup);
     
      //id_save
      ids_dump(act_p->epoch.act,act_p->epoch.rvk,epoch[0],epoch[1]);
      
      pbgp_info("%d successfully joined\n",act_p->ibk->id->asnum);

      //join clear
      join_clear(act_p);
      //idarray clear
      idarray_clear();
      pfix_clear(pfixlist);

      return 0;
}
static void
um_account_dialog_init (UmAccountDialog *self)
{
        GtkBuilder *builder;
        GtkWidget *widget;
        const gchar *filename;
        GError *error = NULL;
        GtkDialog *dialog;
        GtkWidget *content;
        GtkWidget *actions;
        GtkWidget *box;

        builder = gtk_builder_new ();

        filename = UIDIR "/account-dialog.ui";
        if (!g_file_test (filename, G_FILE_TEST_EXISTS))
                filename = "data/account-dialog.ui";
        if (!gtk_builder_add_from_file (builder, filename, &error)) {
                g_error ("%s", error->message);
                g_error_free (error);
                return;
        }

        dialog = GTK_DIALOG (self);
        actions = gtk_dialog_get_action_area (dialog);
        content = gtk_dialog_get_content_area (dialog);
        gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
        gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
        gtk_window_set_title (GTK_WINDOW (dialog), " ");
        gtk_window_set_icon_name (GTK_WINDOW (dialog), "system-users");

        /* Rearrange the bottom of dialog, so we can have spinner on left */
        g_object_ref (actions);
        box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 10);
        gtk_container_remove (GTK_CONTAINER (content), actions);
        gtk_box_pack_end (GTK_BOX (box), actions, FALSE, TRUE, 0);
        gtk_box_pack_end (GTK_BOX (content), box, TRUE, TRUE, 0);
        gtk_widget_show (box);
        g_object_unref (actions);

        /* Create the spinner, but don't show it yet */
        self->spinner = GTK_SPINNER (gtk_spinner_new ());
        widget = gtk_alignment_new (0.5, 0.5, 1.0, 1.0);
        gtk_alignment_set_padding (GTK_ALIGNMENT (widget), 0, 0, 12, 6);
        gtk_box_pack_start (GTK_BOX (box), widget, FALSE, FALSE, 0);
        gtk_container_add (GTK_CONTAINER (widget), GTK_WIDGET (self->spinner));
        gtk_widget_show (widget);

        gtk_dialog_add_button (dialog, _("Cancel"), GTK_RESPONSE_CANCEL);
        widget = gtk_dialog_add_button (dialog, _("_Add"), GTK_RESPONSE_OK);
        gtk_widget_grab_default (widget);

        widget = (GtkWidget *) gtk_builder_get_object (builder, "account-dialog");
        gtk_container_add (GTK_CONTAINER (content), widget);
        self->container_widget = widget;

        local_init (self, builder);
        enterprise_init (self, builder);
        join_init (self, builder);
        mode_init (self, builder);

        g_object_unref (builder);
}
예제 #3
0
int
main()
{
      int rv = 0,res =0,i = 0,j=0;
      char *ca[] = {"key.pub","key.prv","key.par"};
      char *glb[] = {"gbl.act","gbl.rvk"};
      char *epoch[] = {"epc.act","epc.rvk"};
      char *facc = "last.acc";
      char fname[MAX_ENVEL_NAME];

      setup_params_t *setup = NULL;
      epoch_item_t *ep = NULL;
      id_list_t *actls= NULL, *rvkls = NULL;
      action_data_t *join = NULL;
     
      rv = setup_load (ca[0],ca[1],ca[2],&setup);
      if(rv < 0)
            pbgp_die("Cannot initialize setup\n Aborting. \n");

      //genera epoca
      rv = claim_new_epoch(glb,epoch,facc,"last.epc",setup);
      if(rv < 0) 
            pbgp_die("Cannot claim a new epoch\n");

      rv = newepoch_init(&ep,setup);
      if(rv < 0) {
            pbgp_die("claim_new_init :: Cannot complete initialization process\n");
      }
      rv = ids_init(&ep->epls.act,&ep->epls.rvk);
      if(rv < 0) {
            pbgp_die("ids_init :: Cannot create lists\n");
      }
      rv = newepoch_load("last.epc",ep,setup);
      if(rv < 0) {
            pbgp_die("\n");
      }
     

      //da usare per caricare i nomi dei file
      ids_init(&actls,&rvkls);
      ids_load(glb[0],actls);
      ids_load(glb[1],rvkls);
 
      join_init(&join,setup,NULL);
      if(join == NULL)
            pbgp_die("join is null. Abort.");
      
      printf("ACTIVE USER TEST:\n");
      for(i=0; i < actls->size ; i++) {
            char *idstr = NULL;
            //carica join elem
            sprintf(fname,"id-%d.env",actls->head[i].asnum);
            
            join_load(fname,join);

            id_to_string(&idstr, join->ibk->id); 
            printf("Verifying %s\n",idstr);
            id_to_string_clear(idstr);

            //update the witness
            witness_update(join->witness,join->ibk->id,setup,
             		ep->epls.act,ep->epls.rvk);
            //check the presence of the AS into the accumulator
            rv = revokation_check(ep->acc,join->witness,join->signature,
            		join->ibk->id->asnum,setup);

            //check the prefix list signatures TODO!!!!! aaggiusta sto codice -.-
            for(j=0; j < join->pfixlist->size; j++) {
            	const uint8_t *buf_ina = (const uint8_t *) &join->pfixlist->ina[j];
            	size_t sina[1];
            	char as[40];

        		inet_net_ntop (AF_INET, &join->pfixlist->ina[j], join->pfixlist->netmask[j],as, 40);

            	//sina[0] = sizeof(join->pfixlist->ina[j]);
				uint8_t to_vrfy[1][9];
				uint8_t *p = to_vrfy;

				bzero(p,9);
				SERIALIZE_AUTH(p,&join->pfixlist->ina[j],&join->pfixlist->netmask[j],&join->pfixlist->tsca);
				sina[0] = 9;

				res = ibe_vrfy(join->pfixlist->pf_sign[j],
						setup,(const uint8_t **)&p,sina,NULL);



                if(res == SIGN_VALID) printf("The signature is valid! (%s)\n",as);
                else printf("Invalid signature :( \n");
            }

            if(rv != 0) {
                  pbgp_error("revokation_check :: %d have been revoked!\n",join->ibk->id->asnum);
                  rv = -1;
            } else {
                  printf("SUCCESS: User %d is still into the accumulator\n",join->ibk->id->asnum);
                  join_save(join);
            }

            pfix_clear(join->pfixlist);

      }
      join_clear(join);

      // verifica che i revocati non sono nell'accumulatore
      join_init(&join,setup,NULL);
      if(join == NULL)
            pbgp_die("join is null. Abort.");
      
      printf("REVOKED USER TEST:\n");

      for(i=0; i < rvkls->size ; i++) {
            char *idstr = NULL;
            //carica join elem
            sprintf(fname,"id-%d.env",rvkls->head[i].asnum);
            
            join_load(fname,join);

            id_to_string(&idstr, join->ibk->id); 
            printf("Verifying %s\n",idstr);
            //aggiorna il witness
            witness_update(join->witness,join->ibk->id,setup,
             		ep->epls.act,ep->epls.rvk);

            rv = revokation_check(ep->acc,join->witness,join->signature,
            		join->ibk->id->asnum,setup);

            if(rv != 0) {
                  pbgp_error("revokation_check :: %d have been revoked!\n",join->ibk->id->asnum);
                  rv = -1;
            } else {
                  printf("SUCCESS: User %d is still into the accumulator\n",join->ibk->id->asnum);
                  join_save(join);
            }

            id_to_string_clear(idstr);

      }
      join_clear(join);

      ids_clear(actls,rvkls);
      setup_clear(setup);
      return 0;
}
예제 #4
0
파일: fft.C 프로젝트: ArchC/MPSoCBench
int main0(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);
  test_result=1;
  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));
  trans = (double *) G_MALLOC(2*(N+rootN*pad_length)*sizeof(double)+PAGE_SIZE);
  x = (double *) G_MALLOC(2*(N+rootN*pad_length)*sizeof(double)+PAGE_SIZE);
  
  // printf("%d ",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");


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


  LOCKINIT(Global->idlock);

  Global->id = 0;

  BARINIT(Global->start, P);

  join_init(&myJoinPoint, P);

  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);

  
  pthread_turnOnProcessors(); 
  printf("...\n"); 
  SlaveStart();      
  printf("...\n");


  WAIT_FOR_END(myJoinPoint, P);
  printf("...\n");	

  if (doprint) {
    if (test_result) {
      fprintf(fileout,"Data values after inverse FFT:\n");
    } else {
      fprintf(fileout,"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);
    fprintf(fileout,"              INVERSE FFT TEST RESULTS\n");
    fprintf(fileout,"Checksum difference is %.3f (%.3f, %.3f)\n",
	   ck1-ck3, ck1, ck3);
    if (fabs(ck1-ck3) < 0.001) {
      fprintf(fileout,"TEST PASSED\n");
    } else {
      fprintf(fileout,"TEST FAILED\n");
    }
  }

  /* MAIN_END; */
}
예제 #5
0
파일: water.C 프로젝트: ArchC/MPSoCBench
int main0(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);
    }

        /*  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 */

    TSTEP    = 1e-15;
    NMOL     =  64; //8; //64; //216; //125;	//Number of Molecules must be an integer cube (8, 27, 64, 343, 512 ...)
    NSTEP    = 1;  // originalmente 3
    NORDER   = 6;
    NSAVE    = 0; //-1
    NRST     = 0; //3000;
    NPRINT   = 3;
    NFMC     = 0;
    //NumProcs = NUM_PROC;	//Number of Processors
    CUTOFF   = 6.212752;

    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);

    fprintf(six,"Using %ld procs on %ld steps of %ld mols\n", NumProcs, NSTEP, NMOL);
    fprintf(six,"Other parameters:\n\tTSTEP = %8.2e\n\tNORDER = %ld\n\tNSAVE = %ld\n",TSTEP,NORDER,NSAVE);
    fprintf(six,"\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(,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 */

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

        /* 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);
        fprintf(six,"x_inc = %ld\t y_inc = %ld\t z_inc = %ld\n",x_inc,y_inc,z_inc);
        fprintf(six,"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);
	join_init(&myJoinPoint, NumProcs);
    }

    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);
    
    pthread_turnOnProcessors(); 
    printf("...\n");
    WorkStart();
    printf("...\n");
    /* macro to make main process wait for all others to finish */

    WAIT_FOR_END(myJoinPoint, NumProcs);
    
    CLOCK(gl->computeend);

    //fprintf(six,"COMPUTESTART (after initialization) = %lu\n",gl->computestart);
    //fprintf(six,"COMPUTEEND = %lu\n",gl->computeend);
    //fprintf(six,"COMPUTETIME (after initialization) = %lu\n",gl->computeend-gl->computestart);
    //fprintf(six,"Measured Time (2nd timestep onward) = %lu\n",gl->tracktime);
    //fprintf(six,"Intramolecular time only (2nd timestep onward) = %lu\n",gl->intratime);
    //fprintf(six,"Intermolecular time only (2nd timestep onward) = %lu\n",gl->intertime);
    //fprintf(six,"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.c */