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,n) real x_l1_norm(n) !$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,1:n) ) ! ! Compute sequentially. ! 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 using a loop:' write ( *, * ) ' L1_NORM (first 4 ) = ', x_l1_norm(1:4) write ( *, * ) ' Time = ', wtime ! ! Compute using a loop. ! wtime1 = omp_get_wtime ( ) !$omp parallel shared ( x, x_l1_norm ) private ( i, j ) !$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 !$omp end do !$omp end parallel wtime2 = omp_get_wtime ( ) wtime = wtime2 - wtime1 write ( *, * ) ' ' write ( *, * ) 'Parallel calculation, using a loop:' write ( *, * ) ' L1_NORM (first 4 ) = ', x_l1_norm(1:4) write ( *, * ) ' Time = ', wtime ! ! Compute sequentially using FORTRAN90 vector operations. ! wtime1 = omp_get_wtime ( ) do j = 1, n x_l1_norm(j) = sum ( abs ( x(1:n,j) ) ) end do wtime2 = omp_get_wtime ( ) wtime = wtime2 - wtime1 write ( *, * ) ' ' write ( *, * ) 'Sequential calculation FORTRAN90 vector operations:' write ( *, * ) ' L1_NORM (first 4 ) = ', x_l1_norm(1:4) write ( *, * ) ' Time = ', wtime ! ! Compute using FORTRAN90 vector operations. ! wtime1 = omp_get_wtime ( ) !$omp parallel shared ( x, x_l1_norm ) private ( j ) !$omp do do j = 1, n x_l1_norm(j) = sum ( abs ( x(1:n,j) ) ) end do !$omp end do !$omp end parallel wtime2 = omp_get_wtime ( ) wtime = wtime2 - wtime1 write ( *, * ) ' ' write ( *, * ) 'Parallel calculation using FORTRAN90 vector operations:' write ( *, * ) ' L1_NORM (first 4 ) = ', x_l1_norm(1:4) write ( *, * ) ' Time = ', wtime stop end