program main !*****************************************************************************80 ! !! MAIN is the main program for L1_NORM. ! use omp_lib integer n parameter ( n = 1000 ) integer i integer num_threads double precision wtime double precision wtime1 double precision wtime2 real x(n) real x_l1_norm !$omp parallel num_threads = omp_get_num_threads ( ) !$omp end parallel write ( *, * ) ' ' write ( *, * ) 'L1_NORM' write ( *, * ) ' FORTRAN90 version' write ( *, * ) ' Number of threads available is ', num_threads ! ! Set X to random values. ! call random_number ( harvest = x(1:n) ) ! ! Compute sequentially. ! 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 ! ! Compute using a loop. ! wtime1 = omp_get_wtime ( ) x_l1_norm = 0.0 !$omp parallel shared ( x ) private ( i ) reduction ( + : x_l1_norm ) !$omp do do i = 1, n x_l1_norm = x_l1_norm + abs ( x(i) ) end do !$omp end do !$omp end parallel wtime2 = omp_get_wtime ( ) wtime = wtime2 - wtime1 write ( *, * ) ' ' write ( *, * ) 'Parallel calculation #1:' write ( *, * ) ' L1_NORM = ', x_l1_norm write ( *, * ) ' Time = ', wtime ! ! Compute with F90 array operations. ! wtime1 = omp_get_wtime ( ) !$omp parallel private ( i ) shared ( x, x_l1_norm ) !$omp workshare x_l1_norm = sum ( abs ( x(1:n) ) ) !$omp end workshare !$omp end parallel wtime2 = omp_get_wtime ( ) wtime = wtime2 - wtime1 write ( *, * ) ' ' write ( *, * ) 'Parallel calculation #2:' write ( *, * ) ' L1_NORM = ', x_l1_norm write ( *, * ) ' Time = ', wtime stop end