User Tools

Site Tools


Site Tools

variables.f90
program variables
!$ use OMP_LIB
	implicit none
	integer :: a=22,b=67,c=53,d=12,rank,tnot
 
!$OMP PARALLEL SHARED(a) FIRSTPRIVATE(b) PRIVATE(d)  DEFAULT(SHARED)
	print *, " My values are ", a,b,c,d
	rank = OMP_GET_THREAD_NUM ()  ! get the rank of current thread
	tnot   = OMP_GET_NUM_THREADS()  ! get the total number of threads currently running this PR
	b=tnot
        d=rank
        print *, " My values are now ", a,b,c,d
!$OMP END PARALLEL
	print *, "After parallel region, my values are (look at difference with private and shared) :",a,b,c,d
 
end program variables
variables.c
#include<stdio.h>
#include<omp.h>
 
int main(int argc, char** argv)
{
	int a = 22;
	int b = 67;
	int c = 53;
	int d = 12;
	int rank;
	int tnot;
 
#pragma omp parallel shared(a) firstprivate(b) private(d) default(shared)
{
	printf(" My values are %d %d %d %d\n",a,b,c,d);
	rank   = omp_get_thread_num();
	tnot   = omp_get_num_threads();
	b = tnot;
        d = rank;
        printf(" My values are now %d %d %d %d\n",a,b,c,d);
}
 
	printf("After parallel region, my values are (look at difference with private and shared) : %d %d %d %d\n",a,b,c,d);
 
	return 0;
}