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,n) real x_l1_norm(n) 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 j = 1, n do i = 1, n x(i,j) = real ( seed ) / real ( 16384 ) seed = mod ( 3125 * seed, 16384 ) end do end do c c Compute norm sequentially. c wtime1 = omp_get_wtime ( ) do j = 1, n x_l1_norm(j) = 0.0 do i = 1, n x_l1_norm(j) = x_l1_norm(j) + abs ( x(i,j) ) end do end do wtime2 = omp_get_wtime ( ) wtime = wtime2 - wtime1 write ( *, * ) ' ' write ( *, * ) 'Sequential calculation:' write ( *, * ) ' L1_NORM (first 4) = ', x_l1_norm(1:4) write ( *, * ) ' Time = ', wtime c c Compute norm using OpenMP loop. c wtime1 = omp_get_wtime ( ) c$ omp parallel shared ( x, x_l1_norm ) private ( i, j ) c$ omp do do j = 1, n x_l1_norm(j) = 0.0 do i = 1, n x_l1_norm(j) = x_l1_norm(j) + abs ( x(i,j) ) end do end do c$ omp end do c$ omp end parallel wtime2 = omp_get_wtime ( ) wtime = wtime2 - wtime1 write ( *, * ) ' ' write ( *, * ) 'Parallel calculation:' write ( *, * ) ' L1_NORM (first 4) = ', x_l1_norm(1:4) write ( *, * ) ' Time = ', wtime stop end