Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
#include <stdlib.h>
#include <stdio.h>
#include <omp.h>
int main (int argc, char *argv[])
{
int t ;
t = omp_get_thread_num() ;
int x ;
x = omp_get_thread_num() ;
t += x ;
printf( "%d\n", t ) ;
return 0;
}
#include <stdlib.h>
#include <stdio.h>
#include <omp.h>
int main ()
{
int t ;
t = omp_get_num_threads() ;
#pragma omp parallel
int x,y ;
x = omp_get_num_threads() ;
y = omp_get_thread_num() ;
t += x ;
printf( "%d\n", t ) ;
return 0;
}
Which of the following codes will always produce the output s=2 when run
with OMP_NUM_THREADS=2.
#include <stdlib.h>
#include <stdio.h>
#include <omp.h>
int main ()
{
int s = 0 ;
#pragma omp parallel shared( s )
{
int tid=omp_get_thread_num();
#pragma omp single
s++ ;
#pragma omp master
s++ ;
#pragma omp barrier
printf( "s=%d by thread %d\n", s,tid ) ;
}
return 0;
}
#include <stdlib.h>
#include <stdio.h>
#include <omp.h>
int main ()
{
int s = 0 ;
#pragma omp parallel shared( s )
{
int tid=omp_get_thread_num();
#pragma omp master
s++ ;
#pragma omp single
s++ ;
#pragma omp barrier
printf( "s=%d by thread %d\n", s,tid ) ;
}
return 0;
}
#include <stdlib.h>
#include <stdio.h>
#include <omp.h>
int main ()
{
int t ;
t = omp_get_num_threads() ;
{
int x,y ;
int tid=omp_get_thread_num();
x = omp_get_num_threads() ;
y = omp_get_thread_num() ;
return 0;
}
Nowait:
OpenMP provides a clause – nowait, which can be used with a for directive
to indicate that the threads can proceed to the next statement without
waiting for all other threads to complete the for loop execution.
Sections:
The lastprivate clause, in this case, specifies that the last section
(lexically) of the sections directive updates the value of the variable.
The clauses that can be used in this context are: private, firstprivate,
lastprivate, reduction, schedule, nowait and ordered.
setenv OMP_NUM_THREADS 8
setenv OMP_SCHEDULE "static,4"
setenv OMP_SCHEDULE "dynamic"
setenv OMP_SCHEDULE "guided"