int main(int argc, char *argv[]) { unsigned int dim_x = 80, dim_y = 40, time_steps = 80, num_threads = 3; if (argc > 1) time_steps = strtoul(argv[1], NULL, 0); if (argc > 2) dim_x = strtoul(argv[2], NULL, 0); if (argc > 3) dim_y = strtoul(argv[3], NULL, 0); if (argc > 4) num_threads = strtoul(argv[4], NULL, 0); if(dim_x < 9 || dim_y < 9) { printf("Invalid dim_x / dim_y!\n"); exit(EXIT_FAILURE); } size_t size = sizeof(unsigned char) * dim_x * dim_y; unsigned char *grid = malloc(size); if(grid == NULL) exit(EXIT_FAILURE); memset(grid, 0, size); r_pentomino(grid, dim_x, dim_y, dim_x/2, dim_y/2); printf("\nGame of Life: time_steps = %u; dim_x = %u; dim_y = %u; threads = %u \n\n", time_steps, dim_x, dim_y, num_threads); print_gol(grid, dim_x, dim_y); printf("\n\n"); struct timespec begin, end; clock_gettime(CLOCK_REALTIME, &begin); unsigned int living_cells = gol(grid, dim_x, dim_y, time_steps, num_threads); clock_gettime(CLOCK_REALTIME, &end); print_gol(grid, dim_x, dim_y); printf("Living Cells after %u time steps: %u\n", time_steps, living_cells); printf("\nProcessing Time: %.3lf seconds\n", ts_to_double(ts_diff(begin, end))); free(grid); return 0; }
int main(int argc, char** argv) { int N = 100; int num_threads = 4; int input; while ((input = getopt(argc, argv, "t:n:")) != -1) { switch (input) { case 't': if (sscanf(optarg, "%d", &num_threads) != 1) goto error; break; case 'n': if (sscanf(optarg, "%d", &N) != 1) goto error; break; case '?': error: printf( "Usage:\n" "-t \t number of threads used in computation\n" "-n \t number of iterations\n" "\n" "Example:\n" "%s -t 4 -n 2500\n", argv[0]); exit(EXIT_FAILURE); break; } } unsigned long **a = get_int64_twodim_array(N + 1); unsigned long **b = get_int64_twodim_array(N + 1); unsigned long **c = get_int64_twodim_array(N + 1); unsigned long **d = get_int64_twodim_array(N + 1); struct timespec begin, end; clock_gettime(CLOCK_REALTIME, &begin); compute(a, b, c, d, N, num_threads); clock_gettime(CLOCK_REALTIME, &end); printf("\nTime: %.3lf seconds\n", ts_to_double(ts_diff(begin, end))); free(a); free(b); free(c); free(d); return 0; }