SC16 Preview: Modernizing, Modularizing Fortran Codes

By Mark Potts

November 9, 2016

The programming language Fortran has been in existence since 1957, and a large percentage of software that runs on HPC systems worldwide is written, at least in part, in Fortran. Since it has been in existence for so long, and so many scientists and engineers learned it early in their careers and have utilized it extensively, much of this code is not up to modern standards of software development.

Although there is no doubt that most of that code works well and runs fast, as codes have grown more complex and involve more developers, errors can easily be introduced. As I’ll discuss in greater detail next week at SC16, these types of errors can be greatly reduced with a more disciplined approach to software development.

Fortunately, the Fortran language has continued to evolve and has incorporated many of the most successful paradigms of more modern languages such as C++ and Java, while still retaining its overall speed and general simplicity. For example, the 2003 standard, which greatly enhanced Fortran 95, introduced pointers to procedures, object-oriented programming, and better interoperability with C among other things.

The new object-oriented paradigm is particularly useful when refactoring existing Fortran code to make it more modular and robust. It is also fairly straight-forward to implement!

It is fair to ask, “Why change something that’s not broken?” In some cases, it may not make any sense to refactor legacy code, but if the code is still being developed actively, and there are multiple contributors to the code base, refactoring with OOP standards makes a lot of sense. Perhaps the most important reason to refactor is to reduce code duplication. There is a tendency among many programmers to simply copy a subroutine or function that does 90% of what is needed and then modify the new routine to fit the rest. This can lead to lots of headaches if something in the original routine needs to be changed or added, and often leads to discrepancies that are hard to trace. Fortunately, using the classes, inheritance, and polymorphism now available in Fortran 2003, this dilemma can be almost completely avoided.

When two or more files contain very similar routines, it is usually possible to combine the shared functionality in a base class and then add derived classes that “finish off” the calculation in their own unique manner. By eliminating the copied code, the new classes will now make use of the same core computation, which can be easily modified for all classes at once and also lends itself very well to the addition of unit testing—a big component to any modern software design. The figures below show a very simple example of this sort of combination using an abstract base class along with two derived classes.

hpcwire-fortran-fig1
Figure 1: This is a simple abstract base class with a procedure (process_most_data) defined to handle the common core of computation.

 

hpcwire-fortran-fig2a
.
hpcwire-fortran-fig2b
Figure 2: Sample derived classes (sample_one_class and sample_two_class)

Both derived classes inherit the process_most_data procedure from the abstract base class, and both use that function directly in their own version of process_data. The “=>” seen under the extends command refers to the fact that the process_data procedure required in the base class has been implemented locally and renamed within the specific derived class. Figure 3 below shows a sample driver routine that allocates both classes, sets the initial data value for each and then has each instance process the data according to its version of the procedure.

hpcwire-fortran-fig3
Figure 3: Sample driver program that calls two derived classes and processes sample data.

When compiled and run, the output looks as follows:

first data is now    33.000000000000000
second data is now    22.000000000000000

Both derived classes (first and second) start with data equal to 10.0 when each is called to run the process_data routine. Each then runs through the common core functionality provided by the abstract base class and then performs its own individual calculation. In the case of first, that is multiply by 3.0; for second, it is multiply by 2.0.

While this is clearly a trivial example of combining common calculations into a single procedure, it provides a template for doing so in an object-oriented manner using Fortran. Because abstract classes cannot be instantiated, the use of an abstract base class in this instance also ensures that no future developer will accidentally try to use it rather than a fully defined derived class.

Extending this idea even further, unit tests can now be added to these new classes. Using pFUnit, which is an open source unit-testing framework for Fortran, a unit test for sample_one_class would look something like Figure 4.

hpcwire-fortran-fig4
Figure 4

In the sample unit test shown in Figure 4, most of the text is boilerplate, with only the highlighted red text indicating the tailoring for the sample class. The class is included at the top of the file, it is defined under @TestCase, allocated in setup, and deallocated in tearDown—all with very simple additions to the boilerplate. The actual test takes place in testSampleOne where the process_data procedure is called after starting with an initial data value of 10.0. The AssertEqual command checks that the value of data matches 33.0, as it should after the process_data procedure is complete. This sort of test will run extremely quickly and will provide an early warning sign if the base class is changed without making sure that all derived classes are updated appropriately.

I’ll be presenting on this topic at SC16 on Wednesday, Nov. 16 at 4 p.m., and would be happy to answer your questions. Please stop by!

About the Author:

Mark Potts, Ph.D., is a Senior Computational Scientist at RedLine Performance Solutions, LLC. Dr. Potts has over 20 years of software development experience, including more than 15 years of work in research and application development using HPC systems. He joined Redline Performance Solutions in 2015 and has since been working with NOAA to accelerate and modernize their Gridpoint Statistical Interpolation (GSI) analysis code used to assimilate data into operational weather models.

Subscribe to HPCwire's Weekly Update!

Be the most informed person in the room! Stay ahead of the tech trends with industy updates delivered to you every week!

Pfizer HPC Engineer Aims to Automate Software Stack Testing

January 17, 2019

Seeking to reign in the tediousness of manual software testing, Pfizer HPC Engineer Shahzeb Siddiqui is developing an open source software tool called buildtest, aimed at automating software stack testing by providing the community with a central repository of tests for common HPC apps and the ability to automate execution of testing. Read more…

By Tiffany Trader

Senegal Prepares to Take Delivery of Atos Supercomputer

January 16, 2019

In just a few months time, Senegal will be operating the second largest HPC system in sub-Saharan Africa. The Minister of Higher Education, Research and Innovation Mary Teuw Niane made the announcement... Read more…

By Tiffany Trader

Google Cloud Platform Extends GPU Instance Options

January 16, 2019

If it's Nvidia GPUs you're after to power your AI/HPC/visualization workload, Google Cloud has them, now claiming "broadest GPU availability." Each of the three big public cloud vendors has by turn touted the latest and Read more…

By Tiffany Trader

HPE Extreme Performance Solutions

HPE Systems With Intel Omni-Path: Architected for Value and Accessible High-Performance Computing

Today’s high-performance computing (HPC) and artificial intelligence (AI) users value high performing clusters. And the higher the performance that their system can deliver, the better. Read more…

IBM Accelerated Insights

Resource Management in the Age of Artificial Intelligence

New challenges demand fresh approaches

Fueled by GPUs, big data, and rapid advances in software, the AI revolution is upon us. Read more…

STAC Floats ML Benchmark for Financial Services Workloads

January 16, 2019

STAC (Securities Technology Analysis Center) recently released an ‘exploratory’ benchmark for machine learning which it hopes will evolve into a firm benchmark or suite of benchmarking tools to compare the performanc Read more…

By John Russell

Google Cloud Platform Extends GPU Instance Options

January 16, 2019

If it's Nvidia GPUs you're after to power your AI/HPC/visualization workload, Google Cloud has them, now claiming "broadest GPU availability." Each of the three Read more…

By Tiffany Trader

STAC Floats ML Benchmark for Financial Services Workloads

January 16, 2019

STAC (Securities Technology Analysis Center) recently released an ‘exploratory’ benchmark for machine learning which it hopes will evolve into a firm benchm Read more…

By John Russell

A Big Data Journey While Seeking to Catalog our Universe

January 16, 2019

It turns out, astronomers have lots of photos of the sky but seek knowledge about what the photos mean. Sound familiar? Big data problems are often characterize Read more…

By James Reinders

Intel Bets Big on 2-Track Quantum Strategy

January 15, 2019

Quantum computing has lived so long in the future it’s taken on a futuristic life of its own, with a Gartner-style hype cycle that includes triggers of innovation, inflated expectations and – though a useful quantum system is still years away – anticipatory troughs of disillusionment. Read more…

By Doug Black

IBM Quantum Update: Q System One Launch, New Collaborators, and QC Center Plans

January 10, 2019

IBM made three significant quantum computing announcements at CES this week. One was introduction of IBM Q System One; it’s really the integration of IBM’s Read more…

By John Russell

IBM’s New Global Weather Forecasting System Runs on GPUs

January 9, 2019

Anyone who has checked a forecast to decide whether or not to pack an umbrella knows that weather prediction can be a mercurial endeavor. It is a Herculean task: the constant modeling of incredibly complex systems to a high degree of accuracy at a local level within very short spans of time. Read more…

By Oliver Peckham

The Case Against ‘The Case Against Quantum Computing’

January 9, 2019

It’s not easy to be a physicist. Richard Feynman (basically the Jimi Hendrix of physicists) once said: “The first principle is that you must not fool yourse Read more…

By Ben Criger

The Deep500 – Researchers Tackle an HPC Benchmark for Deep Learning

January 7, 2019

How do you know if an HPC system, particularly a larger-scale system, is well-suited for deep learning workloads? Today, that’s not an easy question to answer Read more…

By John Russell

Quantum Computing Will Never Work

November 27, 2018

Amid the gush of money and enthusiastic predictions being thrown at quantum computing comes a proposed cold shower in the form of an essay by physicist Mikhail Read more…

By John Russell

Cray Unveils Shasta, Lands NERSC-9 Contract

October 30, 2018

Cray revealed today the details of its next-gen supercomputing architecture, Shasta, selected to be the next flagship system at NERSC. We've known of the code-name "Shasta" since the Argonne slice of the CORAL project was announced in 2015 and although the details of that plan have changed considerably, Cray didn't slow down its timeline for Shasta. Read more…

By Tiffany Trader

AMD Sets Up for Epyc Epoch

November 16, 2018

It’s been a good two weeks, AMD’s Gary Silcott and Andy Parma told me on the last day of SC18 in Dallas at the restaurant where we met to discuss their show news and recent successes. Heck, it’s been a good year. Read more…

By Tiffany Trader

The Case Against ‘The Case Against Quantum Computing’

January 9, 2019

It’s not easy to be a physicist. Richard Feynman (basically the Jimi Hendrix of physicists) once said: “The first principle is that you must not fool yourse Read more…

By Ben Criger

US Leads Supercomputing with #1, #2 Systems & Petascale Arm

November 12, 2018

The 31st Supercomputing Conference (SC) - commemorating 30 years since the first Supercomputing in 1988 - kicked off in Dallas yesterday, taking over the Kay Ba Read more…

By Tiffany Trader

Contract Signed for New Finnish Supercomputer

December 13, 2018

After the official contract signing yesterday, configuration details were made public for the new BullSequana system that the Finnish IT Center for Science (CSC Read more…

By Tiffany Trader

Nvidia’s Jensen Huang Delivers Vision for the New HPC

November 14, 2018

For nearly two hours on Monday at SC18, Jensen Huang, CEO of Nvidia, presented his expansive view of the future of HPC (and computing in general) as only he can do. Animated. Backstopped by a stream of data charts, product photos, and even a beautiful image of supernovae... Read more…

By John Russell

HPE No. 1, IBM Surges, in ‘Bucking Bronco’ High Performance Server Market

September 27, 2018

Riding healthy U.S. and global economies, strong demand for AI-capable hardware and other tailwind trends, the high performance computing server market jumped 28 percent in the second quarter 2018 to $3.7 billion, up from $2.9 billion for the same period last year, according to industry analyst firm Hyperion Research. Read more…

By Doug Black

Leading Solution Providers

SC 18 Virtual Booth Video Tour

Advania @ SC18 AMD @ SC18
ASRock Rack @ SC18
DDN Storage @ SC18
HPE @ SC18
IBM @ SC18
Lenovo @ SC18 Mellanox Technologies @ SC18
NVIDIA @ SC18
One Stop Systems @ SC18
Oracle @ SC18 Panasas @ SC18
Supermicro @ SC18 SUSE @ SC18 TYAN @ SC18
Verne Global @ SC18

HPC Reflections and (Mostly Hopeful) Predictions

December 19, 2018

So much ‘spaghetti’ gets tossed on walls by the technology community (vendors and researchers) to see what sticks that it is often difficult to peer through Read more…

By John Russell

Intel Confirms 48-Core Cascade Lake-AP for 2019

November 4, 2018

As part of the run-up to SC18, taking place in Dallas next week (Nov. 11-16), Intel is doling out info on its next-gen Cascade Lake family of Xeon processors, specifically the “Advanced Processor” version (Cascade Lake-AP), architected for high-performance computing, artificial intelligence and infrastructure-as-a-service workloads. Read more…

By Tiffany Trader

Germany Celebrates Launch of Two Fastest Supercomputers

September 26, 2018

The new high-performance computer SuperMUC-NG at the Leibniz Supercomputing Center (LRZ) in Garching is the fastest computer in Germany and one of the fastest i Read more…

By Tiffany Trader

Microsoft to Buy Mellanox?

December 20, 2018

Networking equipment powerhouse Mellanox could be an acquisition target by Microsoft, according to a published report in an Israeli financial publication. Microsoft has reportedly gone so far as to engage Goldman Sachs to handle negotiations with Mellanox. Read more…

By Doug Black

Houston to Field Massive, ‘Geophysically Configured’ Cloud Supercomputer

October 11, 2018

Based on some news stories out today, one might get the impression that the next system to crack number one on the Top500 would be an industrial oil and gas mon Read more…

By Tiffany Trader

The Deep500 – Researchers Tackle an HPC Benchmark for Deep Learning

January 7, 2019

How do you know if an HPC system, particularly a larger-scale system, is well-suited for deep learning workloads? Today, that’s not an easy question to answer Read more…

By John Russell

Summit Supercomputer is Already Making its Mark on Science

September 20, 2018

Summit, now the fastest supercomputer in the world, is quickly making its mark in science – five of the six finalists just announced for the prestigious 2018 Read more…

By John Russell

IBM Quantum Update: Q System One Launch, New Collaborators, and QC Center Plans

January 10, 2019

IBM made three significant quantum computing announcements at CES this week. One was introduction of IBM Q System One; it’s really the integration of IBM’s Read more…

By John Russell

  • arrow
  • Click Here for More Headlines
  • arrow
Do NOT follow this link or you will be banned from the site!
Share This