スレッド並列プログラム

      Program test
      Use omp_lib
      Integer :: ti, tn, nb, st, ed
      Integer, Parameter :: n = 2048
      Real(kind=8) :: y(n), x(n)
      Real(kind=8) :: t0, t1
      Character :: c      

      do i=1,n
         x(i) = 1.0
      end do

!$omp parallel default(none) private(ti,tn,nb,st,ed,y,x,t0,t1)
      ti = omp_get_thread_num()
      tn = omp_get_num_threads()
      nb = n / tn
      st = nb *  ti + 1
      ed = nb * (ti + 1)

      call getttime(t0)
      do i=st,ed
         y(i) = x(i)
      end do
      call gettime(t1)

      write (*,*) t1 - t0
!$omp end parallel

      write(*,*) y

      read(*,*) c

      End Program
#include <sys/time.h>
void gettime_(double * ret)
{
   struct timeval tv;
   gettimeofday(&tv, NULL);
   *ret = tv.tv_sec * 1000000 + tv.tv_usec;

   return;
}
FC=gfortran
CC=gcc

hoge.exe:
	$(CC) -c gettime.c
	$(FC) -c hoge.f
	$(FC) -fopenmp gettime.o hoge.o -o hoge.exe