Example #1
0
static void
log_event(kcm_event *event, char *msg)
{
    char fire_time[64], expire_time[64];

    print_times(event->fire_time, fire_time);
    print_times(event->expire_time, expire_time);

    kcm_log(7, "%s event %08x: fire_time %s fire_count %d expire_time %s "
	    "backoff_time %d action %s cache %s",
	    msg, event, fire_time, event->fire_count, expire_time,
	    event->backoff_time, action_strings[event->action],
	    event->ccache->name);
}
Example #2
0
int main(int argc, char *argv[]) {
   double* A = NULL;
   double* x = NULL;
   double* y = NULL;
   long long int size;
   int m, n;

   n= atoi(argv[1]);
   m= n;

   size=m*n*sizeof(double);
   A = malloc(size);
   x = malloc(n*sizeof(double));
   y = malloc(m*sizeof(double));
   
   Read_matrix("A", A, m, n);
   Read_vector("x", x, n);

   gettimeofday(&start_time, NULL);
   Mat_vect_mult(A, x, y, m, n);

   gettimeofday(&end_time, NULL);
   print_times();

   free(A);
   free(x);
   free(y);
   return 0;
}  /* main */
Example #3
0
void A_COLD
jhc_print_profile(void) {
        if(!(_JHC_PROFILE || getenv("AJHC_RTS_PROFILE"))) return;
        fprintf(stderr, "\n-----------------\n");
        fprintf(stderr, "Profiling: %s\n", jhc_progname);
        fprintf(stderr, "Command: %s\n", jhc_command);
        fprintf(stderr, "Complie: %s\n", jhc_c_compile);
        fprintf(stderr, "Version: %s\n\n", jhc_version);
#if HAVE_TIMES
        struct tms tm;
        times(&tm);
        print_times(&tm);
#endif
#if _JHC_PROFILE
        print_times(&gc_gc_time.tm_total);
        print_times(&gc_alloc_time.tm_total);
#endif
        fprintf(stderr, "-----------------\n");
}
Example #4
0
File: test.c Project: frankicia/SA
main () {
	int i,j;
	for(i=0;i<SIZE;i++) {
		for(j=0;j<SIZE;j++) {
			m2[i][j]=2.5;
		}
	}
	gettimeofday(&start_time, NULL);
	
	for (i = 0; i < 10; ++i) foo();
	
	gettimeofday(&end_time, NULL);
	print_times();
}
Example #5
0
int main() {
    // Model, Domain and Boundary
    const auto flow = std::make_unique<Flow>("Couette3D");
    const auto lbmodel = flow->get_lbmodel();
    const auto domain = flow->get_domain();
    const auto boundary = flow->get_boundary();

    // Define problem and its data
    const auto problem = std::make_unique<PLBPD>(lbmodel, domain, boundary);
    auto simdata =
        SimData(domain->get_dimensions(), lbmodel->get_num_directions());

    // Solve problem
    problem->initialize(simdata);
    simdata.write_state("init_state.h5");
    problem->march_in_time(flow->get_num_timesteps(), simdata);
    simdata.write_state("final_state.h5");
    problem->print_times();
}
Example #6
0
int realMain(int argc, char * argv[])
{
  input_number = 0;
  ctu = 0;
  cts = 0;

  TestSetTimerName("Timer title");

  if (argc != 3 && argc != 4)
  {
    printf(
      "Usage: dtest file.txt solve|calc|par|dealerpar|play [ncores]\n");
    return 1;
  }

  char * fname = argv[1];
  char * type = argv[2];

  if (! strcmp(type, "solve"))
    input_number = SOLVE_SIZE;
  else if (! strcmp(type, "calc"))
    input_number = BOARD_SIZE;
  else if (! strcmp(type, "par"))
    input_number = PAR_REPEAT;
  else if (! strcmp(type, "dealerpar"))
    input_number = PAR_REPEAT;
  else if (! strcmp(type, "play"))
    input_number = TRACE_SIZE;

  set_constants();
  main_identify();
#ifdef _WIN32
  QueryPerformanceFrequency(&frequency);
#endif

  boardsPBN bop;
  solvedBoards solvedbdp;
  ddTableDealsPBN dealsp;
  ddTablesRes resp;
  allParResults parp;
  playTracesPBN playsp;
  solvedPlays solvedplp;

  int * dealer_list;
  int * vul_list;
  dealPBN * deal_list;
  futureTricks * fut_list;
  ddTableResults * table_list;
  parResults * par_list;
  parResultsDealer * dealerpar_list;
  playTracePBN * play_list;
  solvedPlay * trace_list;
  int number;

  if (read_file(fname, &number, &dealer_list, &vul_list,
        &deal_list, &fut_list, &table_list, &par_list, &dealerpar_list,
        &play_list, &trace_list) == false)
  {
    printf("read_file failed.\n");
    exit(0);
  }

  if (! strcmp(type, "solve"))
  {
    if (GIBmode)
    {
      printf("GIB file does not work with solve\n");
      exit(0);
    }
    loop_solve(&bop, &solvedbdp, deal_list, fut_list, number);
  }
  else if (! strcmp(type, "calc"))
  {
    loop_calc(&dealsp, &resp, &parp,
              deal_list, table_list, number);
  }
  else if (! strcmp(type, "par"))
  {
    if (GIBmode)
    {
      printf("GIB file does not work with solve\n");
      exit(0);
    }
    loop_par(vul_list, table_list, par_list, number);
  }
  else if (! strcmp(type, "dealerpar"))
  {
    if (GIBmode)
    {
      printf("GIB file does not work with solve\n");
      exit(0);
    }
    loop_dealerpar(dealer_list, vul_list, table_list,
                   dealerpar_list, number);
  }
  else if (! strcmp(type, "play"))
  {
    if (GIBmode)
    {
      printf("GIB file does not work with solve\n");
      exit(0);
    }
    loop_play(&bop, &playsp, &solvedplp,
              deal_list, play_list, trace_list, number);
  }
  else
  {
    printf("Unknown type %s\n", type);
    exit(0);
  }

  print_times(number);
  TestPrintTimer();
  TestPrintTimerList();
  TestPrintCounter();

  free(dealer_list);
  free(vul_list);
  free(deal_list);
  free(fut_list);
  free(table_list);
  free(par_list);
  free(dealerpar_list);
  free(play_list);
  free(trace_list);

  return (0);
}
Example #7
0
int main(int argc, char* argv[]){

	FILE *input = NULL, *output = NULL;
	int out_size;
	double t1, t2, t3;
	char outname[50];
	char line[100];
	
	if(argc != 2 && argc != 3){		//check usage
		printf("Usage:\n%s <input> [output]\n", argv[0]);
		exit(1);
	}
	if(argc == 2){	//if output name not specified, use standard output name
		strcpy(outname, "data.gnumeric");
	}
	else{			//output name specified
		strcpy(outname, argv[2]);
		out_size = strlen(outname);
		//check if it can (and ends) with '.gnumeric'. if not, concatenate it
		if(out_size <= 9 || (out_size > 9 && (strcmp(&outname[out_size - 9], ".gnumeric") != 0)) ){
			strcat(outname, ".gnumeric");
		}
	}

	input = fopen(argv[1], "r");	//open input file
	if(input == NULL){
		printf("cant open file '%s': %s\n", argv[1], strerror(errno));
		exit(2);
	}

	while(fgets(line, 100, input) != NULL){
		if(!strncmp(line, "[term1]    BEGIN DATA", 21)){							//find enclosed data to be filtered
			while(fgets(line, 100, input) != NULL){
				if(!strncmp(line, "[term1]    END DATA", 19)){						//find end of data space and go back
					break;															//to outside loop to check for more data regions
				}
				else if(strncmp(line, "[term1]    *", 12) == 0){					//found implementation name
					line[strlen(line) - 1] = '\0';									//deletes ending '\n'
					add_time(&line[12]);											//a way to avoid first character '*'
				}
				else if(strncmp(line, "[term1]    time", 15) == 0){					//found noc printed time
					sscanf(line, "[term1]    time %lf", &t1);
					now->noc_time = t1/1000000;										//divide it to be read in seconds
				}
				else if(strncmp(line, "[term1]    real", 15) == 0){					//found time printed by linux
					now->linux_time = readLinuxTime(line);							//convert to seconds
				}
				else{
					continue;														//to be disconsidered
				}
			}
		}
	}

//prints the info stored in the lists for debugging
#	ifdef DEBUG
	print_times();
#	endif

	writeTable(outname);
	
	fclose(input);	//close input file
	clear_times();	//free allocated data structure

	return 0;
}
int
main (int argc, char **argv) {
    const int NTMPS = 3;
	VipsImage *in, *out;
    VipsImage *tmps[NTMPS];
    INTMASK *mask;
    int stat;
    const char *ifile, *ofile;
    int extractTop = 100, extractBtm = 200;

    check(argc == 3, "Syntax: %s <input> <output>", argv[0]);
    ifile = argv[1];
    ofile = argv[2];

    timer_start(ifile, "Setup");

    if (im_init_world (argv[0])) error_exit ("unable to start VIPS");

    in = im_open( ifile, "r" );
    if (!in) vips_error_exit( "unable to read %s", ifile );
    check(in->Ysize > 5 && in->Xsize > 5,
          "Input image must be larger than 5 in both dimensions",
          extractBtm);

    stat = im_open_local_array(in, tmps, NTMPS, "tt", "p");
    check(!stat, "Unable to create temps.");

    mask = mk_convmat();

    timer_done();

    /* Reduce the extraction size if it's bigger than the image. */
    if (extractBtm + extractTop >= in->Ysize ||
        extractBtm + extractTop >= in->Xsize) {
        extractTop = 2;
        extractBtm = 2;
    }/* if */

    timer_start(ifile, "im_extract_area");
    check(
        !im_extract_area(in, tmps[0], extractTop, extractTop, in->Xsize - extractBtm,
                         in->Ysize - extractBtm),
        "extract failed.");
    timer_done();

    timer_start(ifile, "im_affine");
    check(
        !im_affine(tmps[0], tmps[1], 0.9, 0, 0, 0.9, 0, 0,
                   0, 0, in->Xsize * 0.9, in->Ysize * 0.9),
        "im_affine failed.");
    timer_done();

    timer_start(ifile, "im_conv");
    check(
        !im_conv (tmps[1], tmps[2], mask),
        "im_conv failed.");
    timer_done();
        
    timer_start(ofile, "writing output");
    out = im_open(ofile, "w");
    check(!!out, "file output failed.");

    im_copy(tmps[2], out);
    timer_done();
    

    timer_start(ofile, "teardown");
    im_close(out);
    im_close(in);
    timer_done();

    print_times();

    return 0;
}/* main */
Example #9
0
int main(int argc, char **argv)
{
    unsigned int p, i, type, size, retry;
    AVProbeData pd = { 0 };
    AVLFG state;
    PutBitContext pb;
    int retry_count= 4097;
    int max_size = 65537;
    int j;

    for (j = i = 1; i<argc; i++) {
        if (!strcmp(argv[i], "-f") && i+1<argc && !single_format) {
            single_format = argv[++i];
        } else if (read_int(argv[i])>0 && j == 1) {
            retry_count = read_int(argv[i]);
            j++;
        } else if (read_int(argv[i])>0 && j == 2) {
            max_size = read_int(argv[i]);
            j++;
        } else {
            fprintf(stderr, "probetest [-f <input format>] [<retry_count> [<max_size>]]\n");
            return 1;
        }
    }

    if (max_size > 1000000000U/8) {
        fprintf(stderr, "max_size out of bounds\n");
        return 1;
    }

    if (retry_count > 1000000000U) {
        fprintf(stderr, "retry_count out of bounds\n");
        return 1;
    }

    av_lfg_init(&state, 0xdeadbeef);

    pd.buf = NULL;
    for (size = 1; size < max_size; size *= 2) {
        pd.buf_size = size;
        pd.buf      = av_realloc(pd.buf, size + AVPROBE_PADDING_SIZE);
        pd.filename = "";

        if (!pd.buf) {
            fprintf(stderr, "out of memory\n");
            return 1;
        }

        memset(pd.buf, 0, size + AVPROBE_PADDING_SIZE);

        fprintf(stderr, "testing size=%d\n", size);

        for (retry = 0; retry < retry_count; retry += FFMAX(size, 32)) {
            for (type = 0; type < 4; type++) {
                for (p = 0; p < 4096; p++) {
                    unsigned hist = 0;
                    init_put_bits(&pb, pd.buf, size);
                    switch (type) {
                    case 0:
                        for (i = 0; i < size * 8; i++)
                            put_bits(&pb, 1, (av_lfg_get(&state) & 0xFFFFFFFF) > p << 20);
                        break;
                    case 1:
                        for (i = 0; i < size * 8; i++) {
                            unsigned int p2 = hist ? p & 0x3F : (p >> 6);
                            unsigned int v  = (av_lfg_get(&state) & 0xFFFFFFFF) > p2 << 26;
                            put_bits(&pb, 1, v);
                            hist = v;
                        }
                        break;
                    case 2:
                        for (i = 0; i < size * 8; i++) {
                            unsigned int p2 = (p >> (hist * 3)) & 7;
                            unsigned int v  = (av_lfg_get(&state) & 0xFFFFFFFF) > p2 << 29;
                            put_bits(&pb, 1, v);
                            hist = (2 * hist + v) & 3;
                        }
                        break;
                    case 3:
                        for (i = 0; i < size; i++) {
                            int c = 0;
                            while (p & 63) {
                                c = (av_lfg_get(&state) & 0xFFFFFFFF) >> 24;
                                if (c >= 'a' && c <= 'z' && (p & 1))
                                    break;
                                else if (c >= 'A' && c <= 'Z' && (p & 2))
                                    break;
                                else if (c >= '0' && c <= '9' && (p & 4))
                                    break;
                                else if (c == ' ' && (p & 8))
                                    break;
                                else if (c == 0 && (p & 16))
                                    break;
                                else if (c == 1 && (p & 32))
                                    break;
                            }
                            pd.buf[i] = c;
                        }
                    }
                    flush_put_bits(&pb);
                    probe(&pd, type, p, size);
                }
            }
        }
    }
    if(AV_READ_TIME())
        print_times();
    return failures;
}
Example #10
0
void print_item(Titem item) {
    print_times(&item);
}
Example #11
0
void
run_timed_test (int argc, char **argv)
{
  int i, n_rounds = atoi (argv[5]);
  if (strstr (dbms, "Virtuoso"))
    {
      new_order_text = new_order_text_kubl;
      payment_text = payment_text_kubl;
      delivery_text = delivery_text_kubl;
      slevel_text = slevel_text_kubl;
      ostat_text = ostat_text_kubl;
    }
  else if (strstr (dbms, "SQL Server"))
    {
      new_order_text = new_order_text_mssql;
      payment_text = payment_text_mssql;
      delivery_text = delivery_text_mssql;
      slevel_text = slevel_text_mssql;
      ostat_text = ostat_text_mssql;
    }
  else if (strstr (dbms, "Oracle"))
    {
      new_order_text = new_order_text_ora;
      payment_text = payment_text_ora;
      delivery_text = delivery_text_ora;
      slevel_text = slevel_text_ora;
      ostat_text = ostat_text_ora;
    }
  else
    {
      printf ("Unknown DBMS %s\n", dbms);
      exit (-1);
    }
  if (argc == 8)
    {
      local_w_id = atoi (argv[6]);
      n_ware = atoi (argv[7]);
    }
  reset_times ();

  for (i = 0; i < n_rounds; i++)
    {
      int n;
      long start, duration;

      start = get_msec_count ();
      for (n = 0; n < 10; n++)
	{
	  transaction_per_period (TEN_PACK_TIME / 23, new_order);
	  transaction_per_period (TEN_PACK_TIME / 23, payment);
	}

      transaction_per_period (TEN_PACK_TIME / 23, delivery);
      transaction_per_period (TEN_PACK_TIME / 23, slevel);
      transaction_per_period (TEN_PACK_TIME / 23, ostat);

      duration = (get_msec_count () - start) / 1000;
      if (TEN_PACK_TIME - duration > 0)
#ifdef WIN32
	Sleep ((TEN_PACK_TIME - duration) * 1000);
#else
	sleep (TEN_PACK_TIME - duration);
#endif
      print_times ();
      if (i && 0 == i % 10)
	{
	  reset_times ();
	}
    }
}
Example #12
0
int
do_run_test (int n_rounds, int _local_w_id, int _n_ware)
{
  int i;
  long start_check_point = get_msec_count (), check_point;
  long start_total = get_msec_count (), total;
  if (strstr (dbms, "Virtuoso"))
    {
      new_order_text = new_order_text_kubl;
      payment_text = payment_text_kubl;
      delivery_text = delivery_text_kubl;
      slevel_text = slevel_text_kubl;
      ostat_text = ostat_text_kubl;
    }
  else if (strstr (dbms, "SQL Server"))
    {
      new_order_text = new_order_text_mssql;
      payment_text = payment_text_mssql;
      delivery_text = delivery_text_mssql;
      slevel_text = slevel_text_mssql;
      ostat_text = ostat_text_mssql;
    }
  else if (strstr (dbms, "Oracle"))
    {
      new_order_text = new_order_text_ora;
      payment_text = payment_text_ora;
      delivery_text = delivery_text_ora;
      slevel_text = slevel_text_ora;
      ostat_text = ostat_text_ora;
    }
  else if (strstr (dbms, "SOAP"))
    {
      new_order_text = new_order_text_SOAP;
      payment_text = payment_text_SOAP;
      delivery_text = delivery_text_SOAP;
      slevel_text = slevel_text_SOAP;
      ostat_text = ostat_text_SOAP;
    }
  else
    {
      return 0;
    }
  if (_local_w_id != -1)
    {
      local_w_id = _local_w_id;
      n_ware = _n_ware;
    }
  reset_times ();

#ifdef GUI
  set_progress_max (n_rounds);
#endif
  ta_init (&total_ta, "TOTAL");
  ta_init (&check_point_ta, "CHECK_POINT");
  ta_enter (&total_ta);
  ta_enter (&check_point_ta);
  for (i = 0; i < n_rounds; i++)
    {
      do_10_pack ();
      if (i && 0 == i % SAMPLE_CHECK)
	{
	  check_point = get_msec_count () - start_check_point;
	  total = get_msec_count () - start_total;
	  printf
	      ("# Transaction No:%d Last cycle:%ld tpmC  From start:%ld tpmC\n", \
	      i, 600000 / (check_point / SAMPLE_CHECK),
	      600000 / (total / i));
	  ta_init (&check_point_ta, "CHECK_POINT");
	  /*Do statistic */
	}
#if 0
      /* not the client's problem during test run */
      if (i && 0 == i % CHECK_POINT_INTERVAL)
	scrap_log ();
#endif
      if (i && 0 == i % 10)
	{
#if !defined(GUI)
	  print_times ();
	  reset_times ();
#endif
	}
#if defined(GUI)
      progress (i);
#endif
    }
#if defined(GUI)
  progress_done ();
#endif
  total = get_msec_count () - start_total;
  printf ("# Total transactions:%d %ld tpmC, %d retries\n", i, 600000 / (total / i), n_deadlocks);

  return 1;
}
Example #13
0
int main(int argc, char **argv) {

    /* parse args */
    int c;
    char *endptr = 0;

    struct vtab *vt = &vtab_ach;

    while( (c = getopt( argc, argv, "f:s:p:r:l:gPhH?Vk")) != -1 ) {
        switch(c) {
        case 'f':
            FREQUENCY = strtod(optarg, &endptr);
            assert(endptr);
            break;
        case 's':
            SECS = strtod(optarg, &endptr);
            assert(endptr);
            break;
        case 'p':
            SEND_RT = (size_t)atoi(optarg);
            assert(SEND_RT);
            break;
        case 'k':
            KERNDEV = 1;
            break;
        case 'r':
            RECV_RT = (size_t)atoi(optarg);
            break;
        case 'l':
            RECV_NRT = (size_t)atoi(optarg);
            break;
        case 'g':
            PASS_NO_RT = 1;
            break;
        case 'P':
            vt = &vtab_pipe;
            break;
        case 'V':   /* version     */
            ach_print_version("achbench");
            exit(EXIT_SUCCESS);
        case 'h':
        case 'H':
        case '?':
        default:
            puts("Usage: achbench [OPTION....]\n"
                 "Benchmark Ach IPC\n"
                 "\n"
                 "Note: Disable CPU power-saving to minimize latency\n"
                 "\n"
                 "Options:\n"
                 "  -f FREQUENCY,       Frequency in Hertz (1000)\n"
                 "  -s SECONDS,         Duration in seconds (1)\n"
                 "  -p COUNT,           Real-Time Publishers (1)\n"
                 "  -r COUNT,           Real-Time Receivers (1)\n"
                 "  -l COUNT,           Non-Real-Time Receivers (0)\n"
                 "  -g,                 Proceed even if real-time setup fails\n"
                 "  -P,                 Benchmark pipes instead of ach\n"
                 "  -k,                 Use kernel channels\n"
                );
            exit(EXIT_SUCCESS);
        }
    }

    fprintf(stderr, "-f %.2f ", FREQUENCY);
    fprintf(stderr, "-s %.2f ", SECS);
    fprintf(stderr, "-r %"PRIuPTR" ", RECV_RT);
    fprintf(stderr, "-l %"PRIuPTR" ", RECV_NRT);
    fprintf(stderr, "-p %"PRIuPTR"\n", SEND_RT);
    size_t i;

    init_time_chan();


    /* setup comms */
    vt->setup();

    /* fork printer */
    pid_t pid_print = fork();
    assert( pid_print >= 0 );
    if(0 == pid_print ) {
        print_times();
        exit(0);
    }

    /* warm up */
    for( i = 0; i < 10; i++) get_ticks();

    /* compute overhead */
    calibrate();
    fprintf(stderr,"overhead 0: %fus\n", overhead*1e6);


    /* fork receivers */
    pid_t pid_recv_rt[RECV_RT+RECV_NRT];
    /* non-realtime receivers */
    for( i = 0; i < RECV_NRT; i ++ ) {
        pid_recv_rt[i] = fork();
        assert( pid_recv_rt[i] >= 0 );
        if(0 == pid_recv_rt[i]) {
            vt->receiver(0);
            exit(0);
        }
    }
    /* realtime receivers */
    for( i = RECV_NRT; i < RECV_NRT + RECV_RT; i ++ ) {
        pid_recv_rt[i] = fork();
        assert( pid_recv_rt[i] >= 0 );
        if(0 == pid_recv_rt[i]) {
            vt->receiver(1);
            exit(0);
        }
    }

    /* fork senders */
    pid_t pid_send_rt[SEND_RT];
    for( i = 0; i < SEND_RT; i ++ ) {
        pid_send_rt[i] = fork();
        assert( pid_send_rt[i] >= 0 );
        if(0 == pid_send_rt[i]) {
            vt->sender();
            exit(0);
        }
    }

    /* Wait for senders */
    for( i = 0; i < SEND_RT; i ++ ) {
        int status;
        waitpid( pid_send_rt[i], &status, 0 );
    }
    /* Wait for printer */
    {
        int status;
        waitpid( pid_print, &status, 0 );
    }
    /* Wait for receivers */
    for( i = 0; i < RECV_RT + RECV_NRT; i ++ ) {
        if( vt == &vtab_pipe ) {
            kill(pid_recv_rt[i],SIGTERM);
        }
        int status;
        waitpid( pid_recv_rt[i], &status, 0 );
    }
    vt->destroy();
    exit(0);
}
Example #14
0
int main(int argc, char *argv[]) {
   double* local_A;
   double* local_x;
   double* local_y;
   int m, local_m, n, local_n;
   int my_rank, comm_sz;
   MPI_Comm comm;
   double* vec = NULL;
   double* v_vec = NULL;
   double* A = NULL;
   int i, j;
   double* x;
   int local_i,  noreal_i;

   MPI_Init(NULL, NULL);
   comm = MPI_COMM_WORLD;
   MPI_Comm_size(comm, &comm_sz);
   MPI_Comm_rank(comm, &my_rank);

   if (my_rank == 0) {
      if (argc<2) {
         printf("the number of parameters is not correct\n");
         exit(-1);
      }
      n= atoi(argv[1]);
      m= n; // for simplicity nxn matrix 
   }

   MPI_Bcast(&m, 1, MPI_INT, 0, comm);
   MPI_Bcast(&n, 1, MPI_INT, 0, comm);
   local_m = m/comm_sz;
   local_n = n/comm_sz;

   // Allocate storage for local parts of A, x, and y
   local_A = malloc(local_m*n*sizeof(double));
   local_x = malloc(local_n*sizeof(double));
   local_y = malloc(local_m*sizeof(double));

   //Read_matrix_vector
   if (my_rank == 0) {
      A = malloc(m*n*sizeof(double));
      v_vec = malloc(n*sizeof(double));
      for (i = 0; i < m; i++)
         for (j = 0; j < n; j++)
              A[i*n+j]=rand(); 
      for (i = 0; i < n; i++)
           v_vec[i]=rand(); 
     }

   //taking time
//   if (my_rank == 0) { gettimeofday(&start_time, NULL); } 

   //Scatter
   MPI_Scatter(A, local_m*n, MPI_DOUBLE, local_A, local_m*n, MPI_DOUBLE, 0, comm);
   MPI_Scatter(v_vec, local_n, MPI_DOUBLE, local_x, local_n, MPI_DOUBLE, 0, comm);

   x = malloc(n*sizeof(double));

   MPI_Allgather(local_x, local_n, MPI_DOUBLE, x, local_n, MPI_DOUBLE, comm);

  // Mat_vect_mult

if (my_rank == 0) { gettimeofday(&start_time, NULL); } 

   for (noreal_i = 0; noreal_i < 100; noreal_i++ ){  // x100 iterations 
     for (local_i = 0; local_i < local_m; local_i++) {
        local_y[local_i] = 0.0;
        for (j = 0; j < n; j++)
           local_y[local_i] += local_A[local_i*n+j]*x[j];
     }
   }

   if (my_rank == 0) { gettimeofday(&end_time, NULL); print_times(); } //taking time
   if (my_rank == 0) { vec = malloc(n*sizeof(double)); }

   //Vector Gather
   MPI_Gather(local_y, local_m, MPI_DOUBLE, vec, local_m, MPI_DOUBLE, 0, comm);

//   if (my_rank == 0) { gettimeofday(&end_time, NULL); print_times(); } //taking time

   if (my_rank == 0) { 
       free(vec);
      free(A);
      free(v_vec);
      }
   free(x);
   free(local_A);
   free(local_x);
   free(local_y);
   MPI_Finalize();
   return 0;
}  /* main */
int main(int argc, char* argv[]) {
  int ierr = 0;
  int p = 1;
  int w = p+7;
  int w_name = 13;

  try {
 
    // Set up command line options
    Teuchos::CommandLineProcessor clp;
    clp.setDocString("This program tests the speed of various forward mode AD implementations for a finite-element-like Jacobian fill");
    int work_count = 200000;
    int num_eqns_begin = 5;
    int num_eqns_end = 65;
    int num_eqns_delta = 10;
    int rt = 0;
    clp.setOption("wc", &work_count, "Work count = num_nodes*num_eqns");
    clp.setOption("p_begin", &num_eqns_begin, "Intitial number of equations");
    clp.setOption("p_end", &num_eqns_end, "Final number of equations");
    clp.setOption("p_delta", &num_eqns_delta, "Step in number of equations");
    clp.setOption("rt", &rt, "Include ADOL-C retaping test");

    // Parse options
    Teuchos::CommandLineProcessor::EParseCommandLineReturn
      parseReturn= clp.parse(argc, argv);
    if(parseReturn != Teuchos::CommandLineProcessor::PARSE_SUCCESSFUL)
      return 1;

    // Print header
    std::cout.setf(std::ios::right);
    std::cout << std::setw(w_name) << "Name" << " ";
    for (int num_eqns = num_eqns_begin; num_eqns <= num_eqns_end; 
	 num_eqns += num_eqns_delta)
      std::cout << std::setw(w) << num_eqns << " ";
    std::cout << std::endl;
    for (int j=0; j<w_name; j++)
      std::cout << '=';
    std::cout << " ";
    for (int num_eqns = num_eqns_begin; num_eqns <= num_eqns_end; 
	 num_eqns += num_eqns_delta) {
      for (int j=0; j<w; j++)
	std::cout << '=';
      std::cout << " ";
    }
    std::cout << std::endl;

    // Analytic
    std::vector<double> times_analytic =
      do_times(work_count, num_eqns_begin, num_eqns_end, num_eqns_delta, 
	       analytic_jac_fill);
    print_times(times_analytic, times_analytic, "Analytic", p, w, w_name);

#ifdef HAVE_ADIC
    // Note there seems to be a bug in ADIC where doing more than one num_eqns
    // value results in incorrect timings after the first.  Doing one value
    // at a time seems to give correct values though.
    std::vector<double> times_adic =
      do_times(work_count, num_eqns_begin, num_eqns_end, num_eqns_delta, 
	       adic_jac_fill);
    print_times(times_adic, times_analytic, "ADIC", p, w, w_name);
#endif

    // Original Fad
    std::vector<double> times_sfad =
      do_times_sfad<Sacado::Fad::SFad>(
	work_count, num_eqns_begin, num_eqns_end, num_eqns_delta);
    print_times(times_sfad, times_analytic, "SFAD", p, w, w_name);

    std::vector<double> times_slfad =
      do_times_sfad<Sacado::Fad::SLFad>(
	work_count, num_eqns_begin, num_eqns_end, num_eqns_delta);
    print_times(times_slfad, times_analytic, "SLFAD", p, w, w_name);

    std::vector<double> times_dfad =
      do_times_fad<Sacado::Fad::DFad>(
	work_count, num_eqns_begin, num_eqns_end, num_eqns_delta);
    print_times(times_dfad, times_analytic, "DFAD", p, w, w_name);
    
    
    // ELR Fad
    std::vector<double> times_elr_sfad =
      do_times_sfad<Sacado::ELRFad::SFad>(
	work_count, num_eqns_begin, num_eqns_end, num_eqns_delta);
    print_times(times_elr_sfad, times_analytic, "ELRSFAD", p, w, w_name);

    std::vector<double> times_elr_slfad =
      do_times_sfad<Sacado::ELRFad::SLFad>(
	work_count, num_eqns_begin, num_eqns_end, num_eqns_delta);
    print_times(times_elr_slfad, times_analytic, "ELRSLFAD", p, w, w_name);

    std::vector<double> times_elr_dfad =
      do_times_fad<Sacado::ELRFad::DFad>(
	work_count, num_eqns_begin, num_eqns_end, num_eqns_delta);
    print_times(times_elr_dfad, times_analytic, "ELRDFAD", p, w, w_name);
   

    // Cache Fad
    std::vector<double> times_cache_sfad =
      do_times_sfad<Sacado::CacheFad::SFad>(
	work_count, num_eqns_begin, num_eqns_end, num_eqns_delta);
    print_times(times_cache_sfad, times_analytic, "CacheSFAD", p, w, w_name);

    std::vector<double> times_cache_slfad =
      do_times_sfad<Sacado::CacheFad::SLFad>(
	work_count, num_eqns_begin, num_eqns_end, num_eqns_delta);
    print_times(times_cache_slfad, times_analytic, "CacheSLFAD", p, w, w_name);

    std::vector<double> times_cache_dfad =
      do_times_fad<Sacado::CacheFad::DFad>(
	work_count, num_eqns_begin, num_eqns_end, num_eqns_delta);
    print_times(times_cache_dfad, times_analytic, "CacheDFAD", p, w, w_name);

    // ELR Cache Fad
    std::vector<double> times_cache_elr_sfad =
      do_times_sfad<Sacado::ELRCacheFad::SFad>(
	work_count, num_eqns_begin, num_eqns_end, num_eqns_delta);
    print_times(times_cache_elr_sfad, times_analytic, "ELRCacheSFAD", p, w, w_name);

    std::vector<double> times_cache_elr_slfad =
      do_times_sfad<Sacado::ELRCacheFad::SLFad>(
	work_count, num_eqns_begin, num_eqns_end, num_eqns_delta);
    print_times(times_cache_elr_slfad, times_analytic, "ELRCacheSLFAD", p, w, w_name);

    std::vector<double> times_cache_elr_dfad =
      do_times_fad<Sacado::ELRCacheFad::DFad>(
	work_count, num_eqns_begin, num_eqns_end, num_eqns_delta);
    print_times(times_cache_elr_dfad, times_analytic, "ELRCacheDFAD", p, w, w_name);
    
  }
  catch (std::exception& e) {
    std::cout << e.what() << std::endl;
    ierr = 1;
  }
  catch (const char *s) {
    std::cout << s << std::endl;
    ierr = 1;
  }
  catch (...) {
    std::cout << "Caught unknown exception!" << std::endl;
    ierr = 1;
  }

  return ierr;
}