C primes1.fcm: Simple Program modified from CMF Programming Guide, Ch. 11 C PARALLEL VERSION: Compile using CM Fortran version 0.7 or later C This first version is a straightforward translation of the serial C version. Though it is much faster than the serial version, it is C not the fastest implementation. PROGRAM findPrimes IMPLICIT NONE INTEGER i, n, nextPrime PARAMETER (n = 999) LOGICAL PRIMES(n), CANDID(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 PRIMES = .FALSE. CANDID = .TRUE. CANDID(1) = .FALSE. C C Loop: Find next valid candidate, mark it as prime, C invalidate all multiples as candidates, repeat. C nextPrime = 2 DO WHILE (nextPrime .LE. SQRT(REAL(n))) PRIMES(nextPrime) = .TRUE. CANDID(nextPrime:n:nextPrime) = .FALSE. nextPrime = MINVAL([1:n], dim=1, mask=CANDID) END DO C C At this point, all valid candidates are prime C PRIMES(nextPrime:n) = CANDID(nextPrime:n) 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) DO i=1, n IF (PRIMES(i)) PRINT *, i ENDDO STOP END