11
$\begingroup$

I'm soon going to start a job as a Scientific Computing software developer. My responsibilities as discussed with the manager are as follows:

  • Analyzing/understanding the existing functionalities (numerical algorithms and physical models) in the 2nd version of the code, written in Fortran.
  • Acquiring skills and knowledge regarding the 3rd version of the code, written in C++.
  • Transferring functionalities from 2nd version to 3rd version of the code.
  • Improving and optimizing the transferred functionalities.
  • Enriching the verification base of the code.

I have a fairly solid theoretical background in Computational Science, I'm also quite proficient in programming and related technologies. Although I am not necessarily a software developer. The reason for which I was hired for the job is because they were looking for somebody with a solid understanding of numerical modeling and simulation and not just a plain software developer.

I am going to have an exchange with the current developers and research engineers involved in the development of the code and hopefully, I'll get some training, but since the training part was not really mentioned during the hiring process, here I am asking the members of the community - at least those with solid experience in Scientific Software development.

What are the usual steps in such a situation i.e. upgrading the version with a change in programming language for a Scientific Computing code? Is there any standard practice or protocol to follow?

P.S. The type of modeling done using the part of the code I am going to deal with is thermal hydraulics and fluid dynamics/mechanics.

$\endgroup$
7
  • 4
    $\begingroup$ Does the code have an existing test suite of both unit tests and end to end tests? $\endgroup$
    – Richard
    Oct 16, 2022 at 18:19
  • 1
    $\begingroup$ @Richard, At this point I can't really tell with certainty as I don't have access to the code and its documentation, but given the scale of the code there should be existing unit tests. I will start my job in a week and I didn't really get detailed technical information about the code during the interview (my bad!). $\endgroup$
    – Dude
    Oct 16, 2022 at 18:47
  • 9
    $\begingroup$ Very very few codes have adequate testing. You'll do well coming up with a testing strategy in which you can check the old code for correctness, and then use these tests to also verify the new code's correctness. $\endgroup$ Oct 16, 2022 at 22:29
  • 1
    $\begingroup$ Here's an example: arxiv.org/abs/1508.07231 $\endgroup$ Oct 18, 2022 at 17:04
  • 1
    $\begingroup$ @WolfgangBangerth, Thanks a bunch Wolfgang, available, helpful and resourceful as always. $\endgroup$
    – Dude
    Oct 18, 2022 at 17:39

1 Answer 1

19
$\begingroup$

As I understand it you have:

  1. Code that you believe is error-free, written in Fortran.
  2. A partial rewrite of that code in C++.

And you would like to eventually rewrite all of the code so that it is in C++ instead of Fortran, but you'd like to avoid introducing bugs/regressions in the C++ code.

The strategy I'd suggest is:

  1. Break up the Fortran code so the functions you want in C++ can be called as a library from C++. This allows you to switch to using C++ as your primary interface and gradually reduce the number of Fortran library calls as you port things over.

  2. Use pybind11 to build an interface between Python and your new C++, as well as an interface from Python to C++ to your wrapped Fortran code. This has two advantages:

    1. You can offload a lot of interface/UI/high-level algorithm choices to Python, which will make it much easier to experiment with your code. This is the route taken by PyTorch and TensorFlow as well as Gordon Bell nominees such as PyFR (the Gordon Bell is the "Nobel Prize of Supercomputing") and makes sense in cases where the "glue" holding a series of functions together is much less expensive than the function calls themselves.
    2. It allows you to use Hypothesis, a Python library for "property based testing". Given a function, you can easily tell Hypothesis to run the function hundreds of times on both randomized inputs and common special cases (like 0 or empty strings) and then test the function output to ensure that certain properties hold; in this case, that both your new C++ and your wrapped Fortran produce the same result.
  3. At the same time you're using property testing to compare the C++ and wrapped Fortran, it's a good time to test other properties (eg, that functions are idempotent, that functions always return positive results, monotonicity, &c).

  4. As each C++ function achieves parity with the Fortran, replace the Fortran library calls in your C++ code with calls to the new C++ functions.

$\endgroup$
3
  • 3
    $\begingroup$ Great answer! Make sure that when differences are found that there is a agreed on strategy in place how and when to solve them, defer them or allow them. $\endgroup$ Oct 17, 2022 at 8:32
  • 1
    $\begingroup$ @Richard, Thank you for your nicely structured, clearly presented strategy. Is there any tutorial on such strategy? Or some similar implemented project where I can experiment before getting involved with the real code? $\endgroup$
    – Dude
    Oct 17, 2022 at 18:14
  • $\begingroup$ @Dude: I'm afraid I don't have something off-handedly. Feel free to email me, though. $\endgroup$
    – Richard
    Oct 23, 2022 at 0:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.