BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News Fortran on Cloudflare Workers Leveraging WebAssembly

Fortran on Cloudflare Workers Leveraging WebAssembly

Cloudflare has recently showcased how to run Fortran on Cloudflare Workers by compiling to WebAssembly. The project leveraged recent advancements in LLVM Flang, enabling Fortran to compile to Wasm.

As Cloudflare Workers uses the V8 engine and natively supports Wasm, the platform supports any language that compiles to Wasm. John Graham-Cumming, CTO at Cloudflare, and Sven Sauleau, software engineer at Cloudflare, explain why Fortran remains relevant for numerical programming or teams handling scientific data:

If you look at the ranking of the fastest supercomputers in the world you will discover that the measurement of "fast" is based on these supercomputers running a piece of software called LINPACK that was originally written in Fortran.

Earlier this year, George Stagg, lead developer of the webR project at Posit PBC, detailed the process of patching LLVM Flang to generate WebAssembly objects. Designed as a replacement for Classic Flang, the open-sourced version of pgfortran, LLVM Flang is a reimplementation of a Fortran frontend for LLVM. Stagg explains:

Flang is not yet considered to be ready for production use, but its development is extremely active right now and pre-production versions of the flang-new compiler have been made available by the team. In recent years, the compiler has become very usable for compiling real-world Fortran code.

Taking advantage of LLVM’s modular design, it is possible to integrate the Flang frontend with LLVM's WebAssembly backend. Stagg further notes:

Currently, LLVM Flang cannot generate WebAssembly output out of the box. Despite this (...) due to the impressive development efforts in the flang-new frontend, creating a Fortran to WebAssembly compiler is possible with just a few small changes to LLVM’s source code.

Stagg’s article sparked a debate on Hacker News, with various users hoping Flang would integrate these changes and offer a WebAssembly compiler as a standard feature. Winston Chang comments:

That would be a win-win -- these patches wouldn't need to be maintained separately, and since unmodified Flang would be able to compile to Wasm, it would benefit other projects out there that use Fortran.

To simplify the execution of Fortran code on Cloudflare Workers, the Cloudflare team released Fortiche, a Fortran compiler for Cloudflare Workers utilizing Flang and the Emscripten compiler toolchain. Additionally, Graham-Cumming and Sauleau introduced a demo project for number recognition in Fortran: users draw a number in the browser, and Fortran code operating on Cloudflare's network deciphers the value.

This isn't Cloudflare's first demonstration of Cloudflare Workers' ability to support older languages. Previously, Graham-Cumming showed how Cloudflare Workers supports COBOL explaining:

GnuCOBOL can compile COBOL to C and Emscripten compiles C/C++ to WebAssembly. However, we need to make sure that our WebAssembly binary is as small and fast as possible to maximize the time for user-code to run instead of COBOL's runtime.

In addition to any language targeting WebAssembly, the Workers platform currently natively supports JavaScript, TypeScript, Python, and Rust.

 

About the Author

Rate this Article

Adoption
Style

BT