program workshare !$ use OMP_LIB implicit none real(8), dimension(:), allocatable :: T integer :: Nx1 = 4096+4096, i, j, tnot 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) tnot = OMP_GET_NUM_THREADS() ! get the total number of threads currently running this PR !$OMP DO SCHEDULE(STATIC,Nx1/tnot) do i=1,Nx1 do j=1,Nx1 T(i) = T(i) + dsqrt(dabs((dcos(T(i))+dsin(T(j)))))/T(j) end do end do !$OMP END DO !$OMP END PARALLEL deallocate(T) end program workshare #include #include #include #include #include int main(int argc, char** argv) { int Nx1 = 4096+4096; int i; int j; int tnot; int seed = 86456; double * T = malloc(Nx1 * sizeof(double)); srand(time(NULL)); for ( i = 0; i < Nx1; i++ ) T[i] = rand(); #pragma omp parallel shared(T,Nx1) private(i,j) default(shared) { tnot = omp_get_num_threads(); // get the total number of threads currently running this PR # pragma omp for schedule(static,Nx1/tnot) for ( i = 0; i < Nx1; i++ ) for ( j = 0; j < Nx1; j++ ) T[i] = T[i] + sqrt(abs((cos(T[i]+sin(T[j])))))/T[j]; } free(T); return 0; }