Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

modifying the order of the loops

Status
Not open for further replies.

NTC0394

Programmer
Jun 19, 2013
21
0
0
Hi guys! I am trying to modify my code but it do not works.
I am trying to put "DO j= 1, 1000" first that "DO i= 1, 20". How to do and keep the same results?

DO i = 1, 20
m = 0
m_2 = 0
p = 10*i

DO j = 1, 1000
d = 0
c = 0

DO
IF (harvest .lt. 0.5) THEN
d = d + 1
ELSE
d = d - 1
END IF
c = c + 1
IF (c .eq. p) exit
END IF
END DO

m = m + d/real(1000)
m_2 = m_2 + (d**2)/real(1000)
END DO
WRITE(1, *) p, m
dp = sqrt(m_2 - m**2)
WRITE(2, *) p, dp
WRITE(3, *) sqrt(REAL(p)), log(dp)
END DO
 
I don't think you can, to be sure, you shouldn't do that, anyway. As c is to vary more rapidly than p, and c varies 1 at a time and p, 10 at a time...it just does not make sense to have the p-varying loop in the inside...many of those iterations would be futile as there is no way p=10*i would be able to match a c that is not multiple of ten; on the flip side, as c = c + 1 is bound to match any p at some point. Not to mention that the p-loop performs a multiplication and, presently, it is carried out 20 times only...if you put this loops inside the 1000 iteration loops, that multiplication will need to be done 20,000 times...why would you want to do that?

Now, given that p has a maximum of 10*20 = 200, there is no need for the inner loop to be larger than 200.
 
I want to become this code a little bit fast. Actually, in the final code, each loop will be 10000 times larger than this one.
now I have : "1000*(10 + 200)*20/2" and I want: "1000*20*10" which looks lik possible.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top