INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

modifying the order of the loops

modifying the order of the loops

(OP)
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

RE: modifying the order of the loops

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.

RE: modifying the order of the loops

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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close