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!

At GTC: Nvidia Expands Scope of Its AI and Datacenter Ecosystem

March 19, 2019

In the high-stakes race to provide the AI life-cycle solution of choice, three of the biggest horses in the field are IBM, Intel and Nvidia. While the latter is only a fraction of the size of its two bigger rivals, and h Read more…

By Doug Black

AWS to Offer Nvidia’s T4 GPUs for AI Inferencing

March 19, 2019

The AI inference market is booming, prompting well-known hyperscaler and Nvidia partner Amazon Web Services to offer a new cloud instance that addresses the growing cost of scaling inference. The new “G4” instances... Read more…

By George Leopold

Nvidia Debuts Clara AI Toolkit with Pre-Trained Models for Radiology Use

March 19, 2019

AI’s push into healthcare got a boost yesterday with Nvidia’s release of the Clara Deploy AI toolkit which includes 13 pre-trained models for use in radiology. Clara, you may recall, is Nvidia’s biomedical platform Read more…

By John Russell

HPE Extreme Performance Solutions

HPE and Intel® Omni-Path Architecture: How to Power a Cloud

Learn how HPE and Intel® Omni-Path Architecture provide critical infrastructure for leading Nordic HPC provider’s HPCFLOW cloud service.

powercloud_blog.jpgFor decades, HPE has been at the forefront of high-performance computing, and we’ve powered some of the fastest and most robust supercomputers in the world. Read more…

IBM Accelerated Insights

The Spark That Ignited A New World of Real-Time Analytics

High Performance Computing has always been about Big Data. It’s not uncommon for research datasets to contain millions of files and many terabytes, even petabytes of data, or more. Read more…

DARPA, NSF Seek Real-Time ML Processor

March 18, 2019

A new U.S. research initiative seeks to develop a processor capable of real-time learning while operating with the “efficiency of the human brain.” The National Science Foundation (NSF) and the Defense Advanced Research Projects Agency jointly announced a “Real Time Machine Learning” project on March 15 soliciting industry proposals for “foundational breakthroughs” in hardware required to “build systems that respond and adapt in real time.” Read more…

By George Leopold

At GTC: Nvidia Expands Scope of Its AI and Datacenter Ecosystem

March 19, 2019

In the high-stakes race to provide the AI life-cycle solution of choice, three of the biggest horses in the field are IBM, Intel and Nvidia. While the latter is Read more…

By Doug Black

Nvidia Debuts Clara AI Toolkit with Pre-Trained Models for Radiology Use

March 19, 2019

AI’s push into healthcare got a boost yesterday with Nvidia’s release of the Clara Deploy AI toolkit which includes 13 pre-trained models for use in radiolo Read more…

By John Russell

It’s Official: Aurora on Track to Be First U.S. Exascale Computer in 2021

March 18, 2019

The U.S. Department of Energy along with Intel and Cray confirmed today that an Intel/Cray supercomputer, "Aurora," capable of sustained performance of one exaf Read more…

By Tiffany Trader

Why Nvidia Bought Mellanox: ‘Future Datacenters Will Be…Like High Performance Computers’

March 14, 2019

“Future datacenters of all kinds will be built like high performance computers,” said Nvidia CEO Jensen Huang during a phone briefing on Monday after Nvidia revealed scooping up the high performance networking company Mellanox for $6.9 billion. Read more…

By Tiffany Trader

Oil and Gas Supercloud Clears Out Remaining Knights Landing Inventory: All 38,000 Wafers

March 13, 2019

The McCloud HPC service being built by Australia’s DownUnder GeoSolutions (DUG) outside Houston is set to become the largest oil and gas cloud in the world th Read more…

By Tiffany Trader

Quick Take: Trump’s 2020 Budget Spares DoE-funded HPC but Slams NSF and NIH

March 12, 2019

U.S. President Donald Trump’s 2020 budget request, released yesterday, proposes deep cuts in many science programs but seems to spare HPC funding by the Depar Read more…

By John Russell

Nvidia Wins Mellanox Stakes for $6.9 Billion

March 11, 2019

The long-rumored acquisition of Mellanox came to fruition this morning with GPU chipmaker Nvidia’s announcement that it has purchased the high-performance net Read more…

By Doug Black

Optalysys Rolls Commercial Optical Processor

March 7, 2019

Optalysys, Ltd., a U.K. company seeking to advance it optical co-processor technology, moved a step closer this week with the unveiling of what it claims is th Read more…

By George Leopold

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

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

ClusterVision in Bankruptcy, Fate Uncertain

February 13, 2019

ClusterVision, European HPC specialists that have built and installed over 20 Top500-ranked systems in their nearly 17-year history, appear to be in the midst o Read more…

By Tiffany Trader

Intel Reportedly in $6B Bid for Mellanox

January 30, 2019

The latest rumors and reports around an acquisition of Mellanox focus on Intel, which has reportedly offered a $6 billion bid for the high performance interconn Read more…

By Doug Black

Looking for Light Reading? NSF-backed ‘Comic Books’ Tackle Quantum Computing

January 28, 2019

Still baffled by quantum computing? How about turning to comic books (graphic novels for the well-read among you) for some clarity and a little humor on QC. The Read more…

By John Russell

Why Nvidia Bought Mellanox: ‘Future Datacenters Will Be…Like High Performance Computers’

March 14, 2019

“Future datacenters of all kinds will be built like high performance computers,” said Nvidia CEO Jensen Huang during a phone briefing on Monday after Nvidia revealed scooping up the high performance networking company Mellanox for $6.9 billion. 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

Deep500: ETH Researchers Introduce New Deep Learning Benchmark for HPC

February 5, 2019

ETH researchers have developed a new deep learning benchmarking environment – Deep500 – they say is “the first distributed and reproducible benchmarking s Read more…

By John Russell

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

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 Bets $2B Seeking 1000X AI Hardware Performance Boost

February 7, 2019

For now, AI systems are mostly machine learning-based and “narrow” – powerful as they are by today's standards, they're limited to performing a few, narro Read more…

By Doug Black

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

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

Arm Unveils Neoverse N1 Platform with up to 128-Cores

February 20, 2019

Following on its Neoverse roadmap announcement last October, Arm today revealed its next-gen Neoverse microarchitecture with compute and throughput-optimized si Read more…

By Tiffany Trader

Move Over Lustre & Spectrum Scale – Here Comes BeeGFS?

November 26, 2018

Is BeeGFS – the parallel file system with European roots – on a path to compete with Lustre and Spectrum Scale worldwide in HPC environments? Frank Herold Read more…

By John Russell

France to Deploy AI-Focused Supercomputer: Jean Zay

January 22, 2019

HPE announced today that it won the contract to build a supercomputer that will drive France’s AI and HPC efforts. The computer will be part of GENCI, the Fre 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

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