Technical data
this code reasoned that because J is different in each iteration, J/10 will also
be different. Unfortunately, because J/10 uses integer division, it often gives
the same results for different values of J.
Although this is a fairly simple error, it is not easy to see. When run on a
single processor, the program always gets the right answer. Some of the time
it gets the right answer when multiprocessing. The error occurs only when
different processes attempt to load from and/or store into the same location
in the AGGREGATE array at exactly the same time.
After reviewing the debugging hints from the previous section, try reversing
the order of the iterations. Replace
DO J = 2, M–1
with
DO J = M–1, 2, –1
This still gives the right answer when running with one process and the
wrong answer when running with multiple processes. The LOCAL
variables look right, there are no EQUIVALENCE statements, and INEW
uses only very simple indexing. The likely item to check is AGGREGATE.
The next step is to use the debugger.
First compile the program with the –g –mp_keep options.
% f77 –g –mp –mp_keep driver.f total.f –o total.ex
driver.f:
total.f:
This debug session is being run on a single-processor machine, which forces
the creation of multiple threads.
% setenv MP_SET_NUMTHREADS 2
Start the debugger.
% dbx total.ex










