I have the following code:
PROGRAM PEU72
USE PRIMES
IMPLICIT NONE
INTEGER, PARAMETER :: MYKIND = SELECTED_INT_KIND(16)
INTEGER (KIND=MYKIND) :: SOFAR
INTEGER :: NRP, M
SOFAR = 0_MYKIND
CALL GEN(ALLNUMS,ALLPRIMES) ! This is a call to a module that creates a list of primes. It works fine.
DO M = 2,8 ! When I try to compile in G95, this loop doesn't increment. M = 2 for each cycle.
SOFAR = SOFAR + NRP(M)
END DO
PRINT *,'ANS: ',SOFAR
READ *,SOFAR
END PROGRAM PEU72
FUNCTION NRP(NUM) RESULT(PHI)
USE PRIMES
IMPLICIT NONE
INTEGER :: NUM, PHI, I!, DIF
INTEGER :: VAR
I = 1
PHI = NUM-1
VAR = NUM
DO
IF (MOD(NUM,ALLPRIMES(I))==0) THEN
PHI = PHI-((NUM-1)/ALLPRIMES(I))
NUM = NUM/ALLPRIMES(I) ! This is the line that silverfrost doesn't like. The code works absolutely fine without it, it just takes too long.
END IF
I = I + 1
VAR = NUM-ALLPRIMES(I)
IF (VAR<0) THEN
EXIT
END IF
END DO
RETURN
END FUNCTION
For optimisation purposes, I want to divide num, a criteria for the while loop, every iteration. My (silverfrost) compiler throws an error (Active DO loop altered) when I do this, and the G95 compiler breaks completely, not iterating the first loop at all. I've tried using DO - IF - EXIT terminology, none of it works. How can I achieve a situation where Num is divided every time, and Allprimes(i) is incremented?
NUM = NUM/ALLPRIMES(I)there is an attempt to modify the loop variablem(as the actual argument associated withnum) inside the loop. This is not allowed.