void iiFree() { if (fileList) { g_slist_foreach(fileList, (GFunc) g_free, NULL); //1 g_slist_free(fileList); } if (dirList) { g_slist_foreach(dirList, (GFunc) g_free, NULL); //1 g_slist_free(dirList); } if (paramList) { g_slist_foreach(paramList, (GFunc) g_free, NULL); g_slist_free(paramList); } timing_free(); ast_free(); var_free(); //groups_free(); }
int main (int argc, char ** argv ) { int i; MPI_Init (&argc, &argv); MPI_Comm_dup (MPI_COMM_WORLD, &comm); MPI_Comm_rank (comm, &rank); MPI_Comm_size (comm, &nproc); comp_comm_init(comm); if (processArgs(argc, argv)) { return 1; } if (!rank) { printf ("Setup parameters:\n"); printf (" # of steps (outputs): %d\n", nsteps); printf (" # of iterations per step: %d\n", niterations); printf (" # of computation units in each iteration: %d\n", ncomp); printf (" # of communication units in each iteration: %d\n", ncomm); printf (" output size per process: %d x %d doubles = %lld bytes\n", nx, ny, sizeof(double) * nx * (uint64_t) ny); printf (" output size per step: %lld bytes\n", nproc * sizeof(double) * nx * (uint64_t) ny); } //2D array with 1D decomposition offs_x = rank * nx; offs_y = 0; gnx = nproc * nx; gny = ny; data = (double*) malloc (sizeof(double) * nx * (size_t) ny); timing_alloc(nsteps); int bufsizeMB = nx*ny*sizeof(double)/1048576 + 1; output_init(comm, bufsizeMB); output_define(nx, ny, gnx, gny, offs_x, offs_y); int it, step, icomp, icomm; /* Warm up a bit */ if (!rank) printf ("Warm up for 1 steps, %d iterations per step...\n", niterations); for (step=0; step < 1; step++) { for (it=0; it < niterations; it++) { for (icomp=0; icomp < ncomp; icomp++) { do_calc_unit (data, nx, ny); } for (icomm=0; icomm < ncomm; icomm++) { do_comm_unit (comm); } } } /* Do the steps with output now */ data_init(); if (!rank) printf ("Start running with I/O and measurements...\n"); double Tcalc_it, Tcomm_it; double Truntime; //to print total time for the loop below (for overhead calculation) char filename[256]; MPI_Barrier (comm); Truntime = MPI_Wtime(); for (step=0; step < nsteps; step++) { if (!rank) printf ("Start step %d\n", step); Tcalc[step] = 0; Tcomm[step] = 0; for (it=0; it < niterations; it++) { // spend some time with computation Tcalc_it = MPI_Wtime(); for (icomp=0; icomp < ncomp; icomp++) { do_calc_unit (data, nx, ny); } Tcalc_it = MPI_Wtime() - Tcalc_it; Tcalc[step] += Tcalc_it; // spend some time with communication Tcomm_it = MPI_Wtime(); for (icomm=0; icomm < ncomm; icomm++) { do_comm_unit (comm); } Tcomm_it = MPI_Wtime() - Tcomm_it; Tcomm[step] += Tcomm_it; } // output per step snprintf (filename, sizeof(filename), "data%6.6d", step); if (!rank) printf ("Output to %s\n", filename); MPI_Barrier (comm); output_dump(filename, step, data); } MPI_Barrier (comm); Truntime = MPI_Wtime() - Truntime; if (!rank) printf ("Finalize...\n"); MPI_Barrier (comm); output_finalize (rank); timing_report(nsteps, comm); double Truntime_max; MPI_Reduce (&Truntime, &Truntime_max, 1, MPI_DOUBLE, MPI_MAX, 0, comm); if (!rank) printf ("Total runtime of main loop: %9.3f\n", Truntime); free (data); timing_free(); MPI_Barrier (comm); MPI_Finalize (); return 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; }