User Tools

Site Tools


Site Tools

exclu.f90
program exclu
!$ use OMP_LIB
	implicit none
	integer :: rank, val, ori
 
!$OMP PARALLEL DEFAULT(SHARED) PRIVATE(val,rank) SHARED(ori)
	rank = OMP_GET_THREAD_NUM () ! get the rank of current thread
 
!$OMP SINGLE
	val = 10
!$OMP END SINGLE
!$OMP MASTER
	ori = 7777
	val = val + 5
!$OMP END MASTER
 
	print *,"I am rank",rank,"and my values are",val,ori
 
!$OMP END PARALLEL
 
end program exclu
exclu.c
#include <stdlib.h>
#include <stdio.h>
#include <omp.h>
 
int main(int argc, char** argv)
{
	int rank, val, ori;
 
#pragma omp parallel default(shared) private(val,rank) shared(ori)
{
	rank = omp_get_thread_num(); // get the rank of current thread
#pragma omp single
{
	val = 10;
}
#pragma omp master
{
	ori = 7777;
	val = val + 5;
}
	printf("I am rank %d and my values are %d, %d\n", rank, val, ori);
}
	return 0;
}