0

I got 2 programs that give me EXACTLY the same results for the input that I give them. They are actually the EXACT same programs, except for this one line 'integer dim' in the second program (line 103). This is not there in the first program (should be line 141 if it was there).

http://pastebin.com/wh7NUt3Z & http://pastebin.com/S1hAB6TW

Now, the problem is that this declaration of the integer dim gives me a slower time in the second program than in the first program (found by this timer). I declared the integer again in the first program and I found that it gave me the same time as the second program, so I know that this is the reason why the second program is slower.

Now I want to know WHY I have to declare this integer again in the second program, but not in the first one... And if possible, I want to remove this (because it will reduce the time calculating).

Anyone that can help?

  • Is this running on a 8088? How long does it really take to declare a single variable? – Scott Solmer Feb 28 '14 at 18:54
  • i3 CPU M370 @ 2.40GHz Yes, I know it's not an optimal processor to do calculations :). Anyway, this is the result now and I want it fixed, or at least understand why it was possible in the first program, but not in the second one. It's also not declaring 1 variable, but declaring n x n x n variables (but I know that shouldn't be a problem for fast CPU's) – user3365108 Feb 28 '14 at 18:56
  • My advice: In this era, use Fortran 95. The free-form source form is easier. More importantly, placing your procedures (subroutines and functions) into modules and using those modules from the main program (or any procedure) will cause the compiler to check the actual and dummy arguments for consistency. Rather than us debating whether some variable is a real or integer, have the compiler check. I don't want to bother comparing your calls with the actual procedures. Also, while developing your program, use the warning options of your compiler. It will save time in the end. – M. S. B. Feb 28 '14 at 19:47
  • example of module usage: http://stackoverflow.com/questions/6511711/computing-the-cross-product-of-two-vectors-in-fortran-90 – M. S. B. Feb 28 '14 at 19:58

1 Answers1

2

These programs are not at all the same! I think your first link is wrong.

But anyway, the reason you need the INTEGER DIM in the second program is that without it, it's implicitly REAL. Since you're passing an integer, if you don't declare DIM to be integer the bits will get misinterpreted as a real and bad things will result, and any timings will be irrelevant. Most likely the integer bits will be interpreted as a denormalized real value making the upper bound of the loop zero.

I'll also comment that without the integer declaration, this program is not standard Fortran 2003 because of the non-integer DO loop control variable - this is a mis-feature that was deleted from the language.

Steve Lionel
  • 6,972
  • 18
  • 31
  • The programs are actually the same ;). They just have different names and blabla. But they do exactly the same (I just imporved the first program to the second one) But I declare the dim variable in the program as an integer in the 3rd line and later, it's still an integer. So why would it suddenly become a real value then? (I just started programming, so forgive me my stupid questions) – user3365108 Feb 28 '14 at 18:50
  • I see - you changed all the variable names and restructured the code. In the second program, the declaration of dim as integer in line 3 doesn't carry into function DistM which is an "external procedure" that shares no declarations with the main program. – Steve Lionel Mar 07 '14 at 21:26