User Tools

Site Tools


Site Tools

atom.f90
program atom
!$ use OMP_LIB
	implicit none
	integer :: rank, tnot
	real(8) :: val
 
	val = 10.0d0
	!$OMP PARALLEL SHARED(val) PRIVATE(rank) DEFAULT(SHARED)
	rank = OMP_GET_THREAD_NUM (); tnot =  OMP_GET_NUM_THREADS()
 
	!$OMP ATOMIC
 	val = val - 1
 
	! !$OMP BARRIER
 
	!$OMP CRITICAL(CRI0)
 	val = val**2
 	val = sqrt(val)
	!$OMP END CRITICAL(CRI0)
 
	print *,rank,val
	!$OMP END PARALLEL
	print *,val
 
end program atom
atom.c
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <omp.h>
 
int main(int argc, char** argv)
{
	int rank, tnot;
	double val;
	val = 10.0;
 
#pragma omp parallel shared(val) private(rank) default(shared)
{
	rank = omp_get_thread_num(); 
	tnot = omp_get_num_threads();
 
#pragma omp atomic
	val-=1;
 
#pragma omp critical(cri0)
{
	val = val*val;
	val = sqrt(val);
}
 
	printf("Rank=%d Val=%lf\n",rank,val);
 
}
 
	printf("Val=%lf\n",val);
 
	return 0;
}