reduction.f90
program reduction
	implicit none
	real(8), dimension(:), allocatable :: T
	integer :: Nx1 = 4096+4096, i, j, tnot, Total=0
	integer,parameter :: seed = 86456
 
	call srand(seed) ! initialize random number
 
	allocate(T(1:Nx1))
	do i=1,Nx1
		T(i) = rand()
	end do
 
!$OMP PARALLEL SHARED(T,Nx1) PRIVATE(i,j) DEFAULT(SHARED)
!$OMP DO SCHEDULE(RUNTIME) REDUCTION(+:Total)
	do i=1,Nx1
		do j=1,Nx1
			T(i) = T(i) + dsqrt(dabs((dcos(T(i))+dsin(T(j)))))/T(j)
		end do
		Total = Total + T(i)
	end do
!$OMP END DO
 
!$OMP END PARALLEL
 
	deallocate(T)
	print *, "Total=", Total
 
end program reduction
reduction.c
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <omp.h>
 
int main(int argc, char** argv)
{
	double* T;
	int Nx1=4096+4096;
	int seed=86456;
	int Total=0;
	int i, j, tnot;
 
	srand(seed);
 
	T=(double*) malloc(Nx1*sizeof(double));
	for(i=0;i<Nx1;i++){
		T[i]=rand();	
	}
 
#pragma omp parallel for default(shared) private(i,j) schedule(runtime) reduction(+:Total)
	for(i=0;i<Nx1;i++) {
		for(j=0;j<Nx1;j++)
			T[i] = T[i] + sqrt(fabs((cos(T[i])+sin(T[j]))))/T[j];
		Total = Total + T[i];
	}
	free(T);
	printf("total = %d\n", Total);
 
	return 0;
}