Example #1
0
void timing_basic_alltoall_nelements( int DIM1, int procs, int loop, char* testname, MPI_Comm local_communicator) {
      
  float* send_array;
  float* recv_array;
  
  int myrank;
  int base, typesize, bytes, i;
  char method[50];

  send_array = malloc( DIM1 * procs * sizeof(float));
  recv_array = malloc( DIM1 * procs * sizeof(float));

  MPI_Comm_rank( local_communicator, &myrank );

  base = myrank * DIM1 + 1;
  utilities_fill_unique_array_1D_float( &send_array[0], DIM1, base );

  if ( myrank == 0 ) {
    snprintf(method, 50, "reference");
        
    MPI_Type_size( MPI_FLOAT, &typesize );
    bytes = typesize * DIM1 * procs;

    timing_init( testname, &method[0], bytes );
  }

  for( i=0 ; i<loop ; i++ ) {
    MPI_Alltoall(&send_array[0], DIM1, MPI_FLOAT, &recv_array[0], DIM1, MPI_FLOAT, local_communicator );
    MPI_Alltoall(&recv_array[0], DIM1, MPI_FLOAT, &send_array[0], DIM1, MPI_FLOAT, local_communicator );
    if ( myrank == 0 ) {
      timing_record(3);
    }
  }

  if ( myrank == 0 ) {
    timing_print( 1 );
  }

  free(send_array);
  free(recv_array);
}     
Example #2
0
void timing_basic_ping_pong_nelements( int DIM1, int loop, char* testname, MPI_Comm local_communicator) {

  float* array;
  int myrank;
  int base, typesize, bytes, i;
  char method[50];

  array = malloc( DIM1 * sizeof(float));

  MPI_Comm_rank( local_communicator, &myrank );

  base = myrank * DIM1 + 1;
  utilities_fill_unique_array_1D_float( &array[0], DIM1, base );

  if ( myrank == 0 ) {
    snprintf(&method[0], 50, "reference");

    MPI_Type_size( MPI_FLOAT, &typesize );
    bytes = typesize * DIM1;

    timing_init( testname, &method[0], bytes );
  }

  for( i=0 ; i<loop ; i++ ){
    if ( myrank == 0 ) {
      MPI_Send( &array[0], DIM1, MPI_FLOAT, 1, itag, local_communicator );
      MPI_Recv( &array[0], DIM1, MPI_FLOAT, 1, itag, local_communicator, MPI_STATUS_IGNORE );
      timing_record(3);
    } else {
      MPI_Recv( &array[0], DIM1, MPI_FLOAT, 0, itag, local_communicator, MPI_STATUS_IGNORE );
      MPI_Send( &array[0], DIM1, MPI_FLOAT, 0, itag, local_communicator );
    }
  }

  if ( myrank == 0 ) {
    timing_print( 1 );
  }

  free(array);
}
Example #3
0
int
main (int argc, char **argv)
{
  char *ch;

  if (argc != 2) {
    fputs("Invalid number of arguments\n", stderr);
    fputs("usage: hspwrap EXEFILE\n", stderr);
    exit(EXIT_FAILURE);
  }

  ch = getenv("HSP_BCAST_CHUNK_SIZE");
  if (ch) {
    sscanf(ch, "%zu", &bcast_chunk_size);
  } else {
    bcast_chunk_size = 4L << 20;
  }

  ch = getenv("HSP_INPUT_FORMAT");
  if (!ch || ch[0] == '\0' || ch[0] == 'l') {
    info("Input format: Lines\n");
    input_fmt = 'l';
  } else if (ch[0] == 'f') {
    info("Input format: FASTA\n");
    input_fmt = 'f';
  } else {
    fputs("Invalid input format specified\n", stderr);
    exit(EXIT_FAILURE);
  }

  // Pre-fork process pool (even on master)
#ifndef TIMING_MODE
  sleep(1);
  pool_ctl = process_pool_fork();
  trace("Process pool created.\n");
  sleep(1);
#endif

  // Initialize MPI
  int rank, ranks;
  if (MPI_Init(NULL, NULL) != MPI_SUCCESS) {
    fprintf(stderr, "Error initialize MPI.\n");
    return EXIT_FAILURE;
  }

  MPI_Comm_rank(MPI_COMM_WORLD, &rank);
  MPI_Comm_size(MPI_COMM_WORLD, &ranks);
  trace("MPI Initialized.\n");

  // Initialize our state
  timing_init(&timing);
  if (rank) {
    slave_init(rank, ranks-1, NUM_PROCS);
  } else {
    print_banner_slant(stderr);
    master_init();
  }

  // Broadcast binary files first
  if (rank) {
    slave_broadcast_work_file("exefile");
  } else {
    master_broadcast_file(getenv("HSP_EXEFILE"));
  }

  // Distribute DB files
  MPI_Barrier(MPI_COMM_WORLD);
  timing_record(&timing.db_start);

  char *dbdir   = getenv("HSP_DBDIR");
  char *dbfiles = strdup(getenv("HSP_DBFILES"));
  char *fn, path[PATH_MAX];

  for (fn = strtok(dbfiles, ":"); fn; fn = strtok(NULL, ":")) {
    snprintf(path, sizeof(path), "%s/%s", dbdir, fn);    

    if (rank) {
      timing.db_kbytes += slave_broadcast_shared_file(path)/1024;
    } else {
      timing.db_kbytes += master_broadcast_file(path)/1024;
    }
  }
  free(dbfiles);

  MPI_Barrier(MPI_COMM_WORLD);
  timing_record(&timing.db_end);

#ifdef TIMING_MODE
  if (!rank) {
    timing_print(&timing);
  }
  MPI_Finalize();
  return 0;
#endif

  // FIXME: The order of things is generally wrong. Should be:
  // Fork Forker, MPI_Init, PS Ctl, EXE/DB distro, forking, main loop

#if 0
  // Now print some stats
  if (rank) {
    MPI_Barrier(MPI_COMM_WORLD);
    printf("Rank %d Processes: %d", rank, ps_ctl->nprocesses);
    printf("  Process ID: %d", getpid());
    printf("  Files: %d (", ps_ctl->ft.nfiles);
    for (i=0; i<ps_ctl->ft.nfiles; ++i) {
      printf("%s, ", ps_ctl->ft.file[i].name);
    }
    puts(")");
  } else {
    printf("Ranks: %d\n\n", ranks);
    MPI_Barrier(MPI_COMM_WORLD);
  }
#endif

  if (rank) {
    slave_main(argv[1]);
  } else {
    master_main(ranks-1);
    timing_print(&timing);
  }

  return 0;
}
Example #4
0
/* Main program. */
int main(void)
{
    int i, j, n_samples, max_n, step_n;
    int array_size;
    int radix;
    test_item_t a[N_ITEMS], test_array[N_ITEMS];
    test_item_t *timing_array, *copy_array;
    timing_t *t;
    
    /* Assign random values to the key of each array element. */
    rand_array(a, N_ITEMS, 100);

    /* Now test quicksort(). */
    memcpy(test_array, a, sizeof(test_array));
    printf("array before quicksort\n = ");
    print_array(test_array, N_ITEMS);
    printf("\n\n");
    quicksort(test_array, N_ITEMS, sizeof(test_item_t), item_cmp);
    printf("array after quicksort\n = ");
    print_array(test_array, N_ITEMS);
    printf("\n\n");

    /* Now test mergesort0(). */
    memcpy(test_array, a, sizeof(test_array));
    printf("array before mergesort0\n = ");
    print_array(test_array, N_ITEMS);
    printf("\n\n");
    mergesort0(test_array, N_ITEMS, sizeof(test_item_t), item_cmp);
    printf("array after mergesort0\n = ");
    print_array(test_array, N_ITEMS);
    printf("\n\n");

    /* Now test mergesort(). */
    memcpy(test_array, a, sizeof(test_array));
    printf("array before mergesort\n = ");
    print_array(test_array, N_ITEMS);
    printf("\n\n");
    mergesort(test_array, N_ITEMS, sizeof(test_item_t), item_cmp);
    printf("array after mergesort\n = ");
    print_array(test_array, N_ITEMS);
    printf("\n\n");
    
    /* Now test radix sort. */
    memcpy(test_array, a, sizeof(test_array));
    printf("array before radixsort\n = ");
    print_array(test_array, N_ITEMS);
    printf("\n\n");
    radixsort(test_array, N_ITEMS, sizeof(test_item_t), get_value, 10);
    printf("array after radixsort\n = ");
    print_array(test_array, N_ITEMS);
    printf("\n\n");

    /* Now test heapsort. */
    memcpy(test_array, a, sizeof(test_array));
    printf("array before heapsort\n = ");
    print_array(test_array, N_ITEMS);
    printf("\n\n");
    heapsort(test_array, N_ITEMS, sizeof(test_item_t), item_cmp);
    printf("array after heapsort\n = ");
    print_array(test_array, N_ITEMS);
    printf("\n\n");
    
    /* Time the quicksort and mergesort sorting functions. */

    printf("Enter the number of samples to use: ");
    scanf("%d", &n_samples);
    printf("Enter the maximum array length to sort: ");
    scanf("%d", &max_n);
    printf("Enter the step size for array lengths: ");
    scanf("%d", &step_n);

    t = timing_alloc(5);  /* Five different sorting algorithms. */
    
    printf("\nResults (n, qsort, quicksort, mergesort, mergesort0, heapsort) (msec)\n"
	  );
    for(i = step_n; i <= max_n; i += step_n) {
	array_size = i * sizeof(test_item_t);
        timing_array = malloc(array_size);
	copy_array = malloc(array_size);
	rand_array(copy_array, i, MAX_VALUE);

        timing_reset(t);
	
	for(j = 0; j < n_samples; j++) {
	    memcpy(timing_array, copy_array, array_size);
            timing_start();
	    qsort(timing_array, i, sizeof(test_item_t), item_cmp);
            timing_stop(t,0);

	    memcpy(timing_array, copy_array, array_size);
            timing_start();
	    quicksort(timing_array, i, sizeof(test_item_t), item_cmp);
            timing_stop(t,1);

	    memcpy(timing_array, copy_array, array_size);
            timing_start();
	    mergesort(timing_array, i, sizeof(test_item_t), item_cmp);
            timing_stop(t,2);

	    memcpy(timing_array, copy_array, array_size);
            timing_start();
	    mergesort0(timing_array, i, sizeof(test_item_t), item_cmp);
            timing_stop(t,3);

	    memcpy(timing_array, copy_array, array_size);
            timing_start();
	    heapsort(timing_array, i, sizeof(test_item_t), item_cmp);
            timing_stop(t,4);
	}
	printf("%d", i);
	timing_print(t,"\t%.2f",n_samples);
	putchar('\n');

	free(timing_array);
	free(copy_array);
    }
    timing_free(t);

    /* Time radix sort on the largest array, using different radix sizes. */
    printf("\nRadix Sort Results.  Using n = %d\n", max_n);
    printf("(radix, time)\n");
    array_size = max_n * sizeof(test_item_t);
    timing_array = malloc(array_size);
    copy_array = malloc(array_size);
    rand_array(copy_array, max_n, MAX_VALUE);
    for(radix = 2; radix <= max_n; radix <<= 1) {

        timer_reset();
	
	for(j = 0; j < n_samples; j++) {
	    memcpy(timing_array, copy_array, array_size);
            timer_start();
	    radixsort(timing_array, max_n, sizeof(test_item_t), get_value,
		      radix);
            timer_stop();
	}
	
	printf("%d", radix);
	timer_print("\t%.2f", n_samples);
	putchar('\n');
    }
    free(timing_array);
    free(copy_array);
	
    return 0;
}