program main c*********************************************************************72 c cc MAIN is the main program for L1_NORM. c include 'omp_lib.h' integer n parameter ( n = 1000 ) integer i integer num_threads integer seed double precision wtime double precision wtime1 double precision wtime2 real x(n) real x_l1_norm c$omp parallel num_threads = omp_get_num_threads ( ) c$omp end parallel write ( *, * ) ' ' write ( *, * ) 'L1_NORM' write ( *, * ) ' FORTRAN77 version' write ( *, * ) ' Number of threads is ', num_threads c c Set X to random values. c seed = 11857 do i = 1, n x(i) = real ( seed ) / real ( 16384 ) seed = mod ( 3125 * seed, 16384 ) end do c c Compute norm sequentially. c wtime1 = omp_get_wtime ( ) x_l1_norm = 0.0 do i = 1, n x_l1_norm = x_l1_norm + abs ( x(i) ) end do wtime2 = omp_get_wtime ( ) wtime = wtime2 - wtime1 write ( *, * ) ' ' write ( *, * ) 'Sequential calculation:' write ( *, * ) ' L1_NORM = ', x_l1_norm write ( *, * ) ' Time = ', wtime c c Compute norm using OpenMP loop. c wtime1 = omp_get_wtime ( ) x_l1_norm = 0.0 c$ omp parallel shared ( x ) private ( i ) reduction ( + : x_l1_norm ) c$ omp do do i = 1, n x_l1_norm = x_l1_norm + abs ( x(i) ) end do c$ omp end do c$ omp end parallel wtime2 = omp_get_wtime ( ) wtime = wtime2 - wtime1 write ( *, * ) ' ' write ( *, * ) 'Parallel calculation:' write ( *, * ) ' L1_NORM = ', x_l1_norm write ( *, * ) ' Time = ', wtime stop end