int main( int argc, char** argv ) { /* loop variables */ int x,y; /* Create matrixes */ unsigned int * input_array; unsigned int * serial_array; unsigned int * output_array; unsigned int * filter_list; /* Initialize the data. Values don't matter much. */ posix_memalign ( (void**)&input_array, 4096, DATA_LEN * sizeof(unsigned int)); // input_array = (unsigned int*) posix_memalign ( DATA_LEN * sizeof(unsigned int), 4096); for (x=0; x<DATA_LEN; x++) { input_array[x] = x % 2048; } /* start with an empty *all zeros* output array */ posix_memalign ( (void**)&output_array, 4096, DATA_LEN * sizeof(unsigned int)); memset ( output_array, 0, DATA_LEN ); posix_memalign ( (void**)&serial_array, 4096, DATA_LEN * sizeof(unsigned int)); memset ( serial_array, 0, DATA_LEN ); /* Initialize the filter. Values don't matter much. */ filter_list = (unsigned int*) malloc ( FILTER_LEN * sizeof(unsigned int)); for (y=0; y<FILTER_LEN; y++) { filter_list[y] = y; } /* Execute at a variety of filter lengths */ for ( int filter_len =16; filter_len<=FILTER_LEN; filter_len*=2) { serialDataFirst ( DATA_LEN, input_array, serial_array, filter_len, filter_list ); memset ( output_array, 0, DATA_LEN ); serialFilterFirst ( DATA_LEN, input_array, output_array, filter_len, filter_list ); checkData ( serial_array, output_array ); memset ( output_array, 0, DATA_LEN ); //omp_set_num_threads(16); parallelFilterFirst ( DATA_LEN, input_array, output_array, filter_len, filter_list ); checkData ( serial_array, output_array ); memset ( output_array, 0, DATA_LEN ); parallelDataFirst ( DATA_LEN, input_array, output_array, filter_len, filter_list ); checkData ( serial_array, output_array ); memset ( output_array, 0, DATA_LEN ); } }
int main( int argc, char** argv ) { /* loop variables */ int x,y; /* Create matrixes */ unsigned int * input_array; unsigned int * serial_array; unsigned int * output_array; unsigned int * filter_list; /* Initialize the data. Values don't matter much. */ posix_memalign ( (void**)&input_array, 4096, DATA_LEN * sizeof(unsigned int)); // input_array = (unsigned int*) posix_memalign ( DATA_LEN * sizeof(unsigned int), 4096); for (x=0; x<DATA_LEN; x++) { input_array[x] = x % 2048; } /* start with an empty *all zeros* output array */ posix_memalign ( (void**)&output_array, 4096, DATA_LEN * sizeof(unsigned int)); memset ( output_array, 0, DATA_LEN ); posix_memalign ( (void**)&serial_array, 4096, DATA_LEN * sizeof(unsigned int)); memset ( serial_array, 0, DATA_LEN ); /* Initialize the filter. Values don't matter much. */ filter_list = (unsigned int*) malloc ( FILTER_LEN * sizeof(unsigned int)); for (y=0; y<FILTER_LEN; y++) { filter_list[y] = y; } int n; printf("Please input a DIGIT(1: Loop efficiency; 2: Parallel speedup; 3: Parallel scaleup; 4: Optimized verion speedup; 5: Optimized version scaleup): \n"); scanf("%d", &n); // serialDataFirst ( DATA_LEN, input_array, serial_array, 512, filter_list ); // memset ( output_array, 0, DATA_LEN ); if (n == 4) { printf("Optimized verion speedup:\n"); serialDataFirst ( DATA_LEN, input_array, serial_array, 512, filter_list ); memset ( output_array, 0, DATA_LEN ); /*************************** optimized speedup ***************************/ for ( int i = 1; i <= 20; i++) { for (int j = 1; j <= 16; j = j * 2) { omp_set_num_threads(j); optimizedParallelDataFirst ( DATA_LEN, input_array, output_array, 512, filter_list ); checkData ( serial_array, output_array ); memset ( output_array, 0, DATA_LEN ); omp_set_num_threads(j); optimizedParallelFilterFirst ( DATA_LEN, input_array, output_array, 512, filter_list ); checkData ( serial_array, output_array ); memset ( output_array, 0, DATA_LEN ); } printf("\n"); } } if (n == 5) { printf("Optimized verion scaleup:\n"); serialDataFirst ( DATA_LEN, input_array, serial_array, 512, filter_list ); memset ( output_array, 0, DATA_LEN ); /*************************** optimized scaleup (need to alter DATA_LEN as well) ***************************/ for ( int i = 1; i <= 20; i++) { omp_set_num_threads(4); optimizedParallelDataFirst ( DATA_LEN, input_array, output_array, 512, filter_list ); checkData ( serial_array, output_array ); memset ( output_array, 0, DATA_LEN ); omp_set_num_threads(4); optimizedParallelFilterFirst ( DATA_LEN, input_array, output_array, 512, filter_list ); checkData ( serial_array, output_array ); memset ( output_array, 0, DATA_LEN ); } printf("\n"); } if (n == 1) { printf("Loop efficiency:\n"); /*************************** loop efficiency part ***************************/ for ( int i = 1; i <= 20; i++) { /* Execute at a variety of filter lengths */ for ( int filter_len =1; filter_len<=FILTER_LEN; filter_len*=2) //filter_len =16 { serialDataFirst ( DATA_LEN, input_array, serial_array, filter_len, filter_list ); memset ( output_array, 0, DATA_LEN ); serialFilterFirst ( DATA_LEN, input_array, output_array, filter_len, filter_list ); checkData ( serial_array, output_array ); memset ( output_array, 0, DATA_LEN ); } } } if (n == 2) { printf("Parallel speedup:\n"); serialDataFirst ( DATA_LEN, input_array, serial_array, 512, filter_list ); memset ( output_array, 0, DATA_LEN ); /*************************** speedup ***************************/ for ( int i = 1; i <= 20; i++) { for (int i = 1; i <= 16; i = i * 2) { omp_set_num_threads(i); parallelFilterFirst ( DATA_LEN, input_array, output_array, 512, filter_list ); checkData ( serial_array, output_array ); memset ( output_array, 0, DATA_LEN ); omp_set_num_threads(i); parallelDataFirst ( DATA_LEN, input_array, output_array, 512, filter_list ); checkData ( serial_array, output_array ); memset ( output_array, 0, DATA_LEN ); } } } if (n == 3) { printf("Parallel scaleup:\n"); serialDataFirst ( DATA_LEN, input_array, serial_array, 512, filter_list ); memset ( output_array, 0, DATA_LEN ); /*************************** scaleup (need to alter DATA_LEN as well)***************************/ for (int i = 1; i <= 20; i++) { omp_set_num_threads(4); parallelFilterFirst ( DATA_LEN, input_array, output_array, 512, filter_list ); checkData ( serial_array, output_array ); memset ( output_array, 0, DATA_LEN ); omp_set_num_threads(4); parallelDataFirst ( DATA_LEN, input_array, output_array, 512, filter_list ); checkData ( serial_array, output_array ); memset ( output_array, 0, DATA_LEN ); } } }