C primes2.fcm: Simple Program modified from CMF Programming Guide, Ch. 11 C Fast (?) PARALLEL VERSION: Compile using CM Fortran version 0.7 or later C This version is very fast because it uses more processors. C (And will lose its speed advantage as VP ratio goes up.) Comment: However, runs much slower than primes1.fcm??? PROGRAM findPrimes2 IMPLICIT NONE INTEGER i, n, nn PARAMETER (n = 500) INTEGER TEMP1(n,n), TEMP2(n,n) LOGICAL CANDID(n,n), PRIMES(n) comment: Need to include CMF timer utilities: include'/usr/include/cm/timer-fort.h' comment: Clear and start timer 0. call cm_timer_clear(0) call cm_timer_start(0) C C Initialization C CANDID = .FALSE. FORALL(i=1:n) TEMP1(i,:) = 2*i+1 FORALL(i=1:n) TEMP2(:,i) = 2*i+1 C C At this point, the temporary two dimensional arrays are modulated C element by element. If an element in TEMP1 is not a multiple of C the corresponding element of TEMP2, or (for the sake of an easily C generated argument to the upcoming ALL instrinsic) the element in C TEMP1 is greater than or equal to the corresponding element in C TEMP2, then the corresponding element in the CANDID array is set. C WHERE (((MOD(TEMP1,TEMP2) .NE. 0) .AND. (TEMP1 .GT. TEMP2)) .OR. $ (TEMP1 .LE. TEMP2)) CANDID = .TRUE. END WHERE C C The following statement performs an AND across the second C dimension of CANDID and stores the results in PRIMES. C PRIMES = ALL(CANDID, dim=2) comment: Stop and Print timer call cm_timer_stop(0) print*,'total CM5 time' call cm_timer_print(0) C C Print results C PRINT *, "Number of primes:", COUNT(PRIMES)+1 PRINT *, 2 DO i=1,n IF (PRIMES(i)) PRINT *, 2*i+1 ENDDO STOP END