/* Write to an array in parallel. */ #include #include #include #include int main(int argc, char** argv) { int num_threads; //nb threads requested by user long n; //size of array int block; double t1, t2; //read args from user if (argc != 4) { printf("usage: %s [n] [nthreads] [k]\n", argv[0]); exit(1); } n = atol(argv[1]); num_threads = atoi(argv[2]); block = atoi(argv[3]); printf("using n=%ld, numthreads=%d block ==%d\n", n, num_threads, block); //allocate visibility array int* vis = (int*) malloc(n * sizeof(int)); assert(vis); t1 = omp_get_wtime(); long i; double sum = 0; omp_set_num_threads(num_threads); #pragma omp parallel { //private variables to each thread double localsum = 0; int thread_id = omp_get_thread_num(); if (thread_id == 0) { printf("[master] nb. threads is %d\n", omp_get_num_threads()); } //printf("Start(%d)\n", thread_id); #pragma omp for schedule(static, block) for (i=0; i