Changing all calls to single function

  • Thread starter yairsuari
  • Start date
  • Tags
    Function
In summary, the speaker is running an ecological model in Fortran that calls a single subroutine from 200 different places in a source code divided into 50 text files. After two days of running, they encounter a division by zero error and want to change the subroutine calls to include a different number each time and print where it was called from in the function. They are seeking help with using Perl or sed/awk to make these changes and improve the debugging process. Another suggestion is to modify the subroutine to print a "stack trace" when it crashes, which can be done with a system routine and compiler option. This would provide more information without increasing run time, but editing the calls by hand could introduce more bugs. The speaker thanks the other
  • #1
yairsuari
8
0
Hello

i am runing an ecological model in fortran which calls a single subroutine from about 200 different places in a source code divided to about 50 text files. after ca. 2 days of running i have a devision by zero and the model blows up - this is a tough thing to debug. if i use debug flag on compilation this will take ages.


what i want to do is change every call to this function that currently look like this:
call flux_vector( a,b, c)
to:
call flux_vector( a,b, c,NUMBER)

Where number contains a different number on each call

And then inside the function change the section that stops execution to print where it was called from

write(6,*)NUMBER
stop

i know this can be done using perl or sed/awk but i am not experinced enough to do that, can someone please help?


thank for the time
yair
yairsuari is online now Report Post Edit/Delete Message
 
Technology news on Phys.org
  • #2
A better way would be to modify your subroutine so it prints a "stack trace" when it crashes. There should be a system routine you can call to do this, and a compiler option to include the line numbers and filenames from the source code in the output. Getting that information will not increase the run time, though it will increase the executable program size because of the extra information saying which lines in the source code relates to which parts of the compiled code.

Look in your compiler documentation for how to do that. If you edit hundreds of subroutine calls by hand, even with a script, you could easily add more bugs to your program if you miss a few of the subroutine calls.
 
  • #3
thanks, this solves my problem
 

FAQ: Changing all calls to single function

How does changing all calls to a single function affect my code?

Changing all calls to a single function can streamline your code and make it more efficient. By using a single function, you can avoid repeating the same code multiple times and make it easier to make changes or updates in the future.

Will changing all calls to a single function improve performance?

In most cases, yes. By reducing the number of function calls, your code will run faster and more efficiently. However, it's important to carefully consider the specific context and purpose of your code to determine if this change will have a significant impact on performance.

Are there any potential drawbacks to changing all calls to a single function?

One potential drawback is that it may make your code less readable, especially for other developers who may be unfamiliar with the single function. Additionally, if the single function becomes too long or complex, it may actually decrease performance rather than improve it.

Can I still use multiple functions if I need to perform different actions?

Yes, you can still use multiple functions if needed. You can have a single function that calls different functions based on certain conditions or parameters. This can help maintain code organization and readability while still benefiting from the efficiency of a single function.

Should I change all calls to a single function in my existing code?

It depends on the specific circumstances and goals of your code. If you are experiencing performance issues or want to improve code efficiency, it may be worth considering. However, if your code is already optimized and easy to read, it may not be necessary to make this change.

Similar threads

Replies
8
Views
4K
Replies
6
Views
10K
Replies
4
Views
2K
Replies
12
Views
3K
Replies
6
Views
2K
Replies
2
Views
1K
Replies
22
Views
4K
Back
Top