int main(int argc, char **argv) { int i, n=200, chunk, a[n], suma=0; omp_sched_t schedule_type; int chunk_value; if(argc < 3) { fprintf(stderr,"\nFalta iteraciones o chunk \n"); exit(-1); } n = atoi(argv[1]); if (n>200) n=200; chunk = atoi(argv[2]); for (i=0; i<n; i++) a[i] = i; #pragma omp parallel for firstprivate(suma) lastprivate(suma) \ schedule(dynamic,chunk) for (i=0; i<n; i++) { suma = suma + a[i]; printf(" thread %d suma a[%d]=%d suma=%d \n", omp_get_thread_num(),i,a[i],suma); if(omp_get_thread_num() == 0) { printf(" Dentro de 'parallel for':\n"); printf(" static = 1, dynamic = 2, guided = 3, auto = 4\n"); omp_get_schedule(&schedule_type, &chunk_value); printf(" dyn-var: %d, nthreads-var:%d, thread-limit-var:%d,run-sched-var: %d, chunk: %d\n", \ omp_get_dynamic(), \ omp_get_max_threads(), omp_get_thread_limit(), \ schedule_type, chunk_value); printf(" get_num_threads: %d,get_num_procs: %d,in_parallel():%d \n", \ omp_get_num_threads(),omp_get_num_procs(),omp_in_parallel()); } } printf("Fuera de 'parallel for' suma=%d\n",suma); printf(" static = 1, dynamic = 2, guided = 3, auto = 4\n"); omp_get_schedule(&schedule_type, &chunk_value); printf(" dyn-var: %d, nthreads-var:%d, thread-limit-var:%d,run-sched-var: %d, chunk: %d\n" \ , omp_get_dynamic(), \ omp_get_max_threads(), omp_get_thread_limit(), \ schedule_type, chunk_value); printf(" get_num_threads: %d,get_num_procs: %d,in_parallel():%d \n", \ omp_get_num_threads(),omp_get_num_procs(),omp_in_parallel()); }
int main () { #pragma omp target if (0) #pragma omp teams thread_limit (1) if (omp_get_thread_limit () != 1) abort (); return 0; }
SEXP getDTthreads_R(SEXP verbose) { // verbose checked at R level if (!isLogical(verbose) || LENGTH(verbose)!=1 || INTEGER(verbose)[0]==NA_LOGICAL) error("'verbose' must be TRUE or FALSE"); if (LOGICAL(verbose)[0]) { Rprintf("omp_get_max_threads() = %d\n", omp_get_max_threads()); Rprintf("omp_get_thread_limit() = %d\n", omp_get_thread_limit()); // can be INT_MAX meaning unlimited Rprintf("DTthreads = %d\n", DTthreads); #ifndef _OPENMP Rprintf("This installation of data.table has not been compiled with OpenMP support.\n"); // the omp_ functions used above are defined in myomp.h to be 1 in this case #endif } return ScalarInteger(getDTthreads()); }
int32_t omp_get_thread_limit_ (void) { return omp_get_thread_limit (); }
main(int argc, char **argv) { int i, n=200,chunk,a[n],suma=0; if(argc < 3) { fprintf(stderr,"\nFalta iteraciones o chunk \n"); exit(-1); } n = atoi(argv[1]); if (n>200) n=200; chunk = atoi(argv[2]); for (i=0; i<n; i++) a[i] = i; #pragma omp parallel for firstprivate(suma) lastprivate(suma) schedule(dynamic,chunk) num_threads(4) for (i=0; i<n; i++) { if( i == 0) printf("Dentro del parallel; dyn-var = %d, nthreads-var = %d, thread-limit-var = %d\n",omp_get_dynamic(), omp_get_max_threads(),omp_get_thread_limit() ); suma = suma + a[i]; printf(" thread %d suma a[%d]=%d suma=%d \n",omp_get_thread_num(),i,a[i],suma); } printf("Fuera de 'parallel for' suma=%d\n",suma); printf("Fuera del parallel; dyn-var = %d, nthreads-var = %d, thread-limit-var = %d\n",omp_get_dynamic(), omp_get_max_threads(),omp_get_thread_limit() ); }