#include #include #include #include #include "utils.h" #define DFT_WORKERS 1UL #define DFT_N 10UL #define DFT_THREADS 1UL #define BASE 10 //#define VERBOSE uint64_t workers = DFT_WORKERS; uint64_t size = DFT_N; uint64_t nthreads = DFT_THREADS; static const struct option lopts[] = { {"workers", 0, NULL, 'w'}, {"size", 0, NULL, 's'}, {"threads", 0, NULL, 'n'}, {"help", 0, NULL, 'h'}, {NULL, 0, NULL, 0} }; void print_help(char* prog) { printf("Usage: %s \n", prog); printf("\t -w, --workers Number of workers (default = %lu)\n", DFT_WORKERS); printf("\t -s, --size Size of array (default = %lu)\n", DFT_N); printf("\t -n, --threads Number of OpemMP threads (default = %lu)\n", DFT_THREADS); printf("\t -h, --help Show help\n"); exit(EXIT_FAILURE); } void parse_opts(int argc, char** argv) { int opt; char* end; do{ opt = getopt_long(argc, argv, "w:s:n:h", lopts, NULL); switch(opt){ case 'h': print_help(argv[0]); exit(EXIT_FAILURE); case 'w': workers = strtol(optarg, &end, 10); if(*end){ printf("Error converting %s as workers.\n",optarg); exit(EXIT_FAILURE); } break; case 's': size = strtol(optarg, &end, 10); if(*end){ printf("Error converting %s as size.\n",optarg); exit(EXIT_FAILURE); } break; case 'n': nthreads = strtol(optarg, &end, 10); if(*end){ printf("Error converting %s as OpenMP threads.\n",optarg); exit(EXIT_FAILURE); } break; case -1: break; default: printf("Option %c not regognized!. Aborting.\n",opt); print_help(argv[0]); exit(EXIT_FAILURE); } }while(opt != -1); printf("Parsed options: \n"); printf("\t Number of workers = %" PRIu64 "\n",workers); printf("\t Array size = %" PRIu64 "\n",size); printf("\t OpenMP threads = %" PRIu64 "\n",nthreads); } int array_add(void* in, size_t ilen, void** out, size_t* olen) { uint64_t i; uint64_t* lin; double* lout; uint64_t n = ilen / sizeof(uint64_t); lout = malloc(ilen * sizeof(uint64_t)); if(lout == NULL) goto err; lin = (uint64_t*) in; #pragma omp parallel for num_threads(nthreads) for(i=0; i