Skip to content

Commit 5f95844

Browse files
authored
Merge pull request #152 from smeskos/new_mini_book--OS-setup-for-Fortran-developement
New mini book: OS setup for Fortran developement
2 parents d6c3e70 + d33b403 commit 5f95844

File tree

7 files changed

+246
-0
lines changed

7 files changed

+246
-0
lines changed

_data/learning.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,17 @@ books:
4141
- link: /learn/building_programs/build_tools
4242
- link: /learn/building_programs/distributing
4343

44+
- title: Setting up your OS
45+
description: How to setup a Fortran developement environment in Windows, Linux and macOS.
46+
category: Getting started
47+
link: /learn/os_setup
48+
pages:
49+
- link: /learn/os_setup/choose_compiler
50+
- link: /learn/os_setup/install_gfortran
51+
- link: /learn/os_setup/text_editors
52+
- link: /learn/os_setup/ides
53+
- link: /learn/os_setup/tips
54+
4455
# Web links listed at the bottom of the 'Learn' landing page
4556
#
4657
reference-links:

learn/os_setup/choose_compiler.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
layout: book
3+
title: Choosing a compiler
4+
permalink: /learn/os_setup/choose_compiler
5+
---
6+
7+
A comprehensive list of available compilers is provided [here]({{site.baseurl}}/compilers). In this guide, we will focus only on those that are free to install and use.
8+
9+
Of those listed at the link above, open source and free are GFortran (with OpenCoarrays), Flang, and LFortran. Finally, NVFortran and IFort* are commercial with free community editions.
10+
11+
_Note_: *IFort (Intel's Fortran Compiler) does not offer a free community edition in general. However, if you are a student, educator, or open-source contributor, you may [qualify for free software](https://software.intel.com/content/www/us/en/develop/articles/qualify-for-free-software.html).
12+
13+
Both NVFortran (NVIDIA) and IFort (Intel) are well documented and readers can find detailed information about installing and using them on their websites respectively. In the next chapter, we use GFortran for the tutorial as it is a mature open source compiler. We encourage users to also try other open source and commercial compilers.

learn/os_setup/ides.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
layout: book
3+
title: IDEs
4+
permalink: /learn/os_setup/ides
5+
---
6+
7+
An IDE (Integrated Development Environment) refers to a complete software development environment, where, all those packages that come as external plug-ins in Text-Editors, are already integrated within the software. An IDE is usually optimized towards a specific set of languages. For example it is very common for IDEs to advertise themselves towards either compiled or interpreted languages, or even towards a single language, or depending on the application developed, like scientific or web development.
8+
IDEs are recommended for beginner programmers, since it is possible to start coding with minimum effort after installation. However, it is quite common, in professional environments, individual developers and teams alike, to choose an IDE for large projects because of some unique features that they may offer over a Text-Editor.
9+
10+
A list of popular IDEs that provide good Fortran support is provided in alphabetical order:
11+
- [AbsoftTools](https://www.absoft.com/technology/absofttools-fortran-ide/): commercial product, cross-platform, comes with Absoft's own Fortran compiler.
12+
- [Code::Blocks](http://www.codeblocks.org/): free product, cross-platform and supports multiple compilers. Plenty of tutorials online on how to install it and add a Fortran Compiler. As well as a recent presentation, [here](https://www.youtube.com/watch?v=M1RwVGGSAgE&ab_channel=FortranCon), of its capabilities and future prospects at the International Fortran Conference 2020 by its main developer.
13+
- [Eclipse-Photran](https://marketplace.eclipse.org/content/photran-fortran-ide-eclipse) *Photran is an IDE and refactoring tool for Fortran based on Eclipse and the C/C++ Development Tools*. A free product, cross-platform and supports multiple compilers.
14+
- [Geany](https://www.geany.org/): a free product, cross platform and supports multiple compilers.
15+
- [NAG Fortran Builder](https://www.nag.com/content/nag-fortran-builder-0) is a commercial product, available in Windows and MacOS and supports NAG's own Fortran Compiler.
16+
- [Plato](https://www.silverfrost.com/16/ftn95/plato.aspx) is a commercial product, cross-platform, comes with Silverfrost's Fortran FTN95 own Fortran compiler.
17+
- [SimplyFortran](https://simplyfortran.com/) is a commercial product, cross-platform with support of the GNU Fortran compiler.
18+
- [Visual Studio](https://visualstudio.microsoft.com/) its *Community Edition 2019* is a free product, available only in Windows and supports only the commercial* Intel's Fortran compiler.
19+
20+
*Intel offers a commercial Fortran compiler. However, if you are a student, an educator, or an open-source contributor, you may [qualify for free software](https://software.intel.com/content/www/us/en/develop/articles/qualify-for-free-software.html).

learn/os_setup/index.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
layout: book
3+
title: Setting up your OS
4+
permalink: /learn/os_setup
5+
---
6+
<br/><br/>
7+
<div style="text-align:center"><span style="font-size:1.5em">A beginner's tutorial on the software that needs to be installed to start with Fortran development</span></div>
8+
<br/><br/>
9+
10+
---
11+
<span style="color:grey; font-size:0.8em">*Authors: Stavros Meskos, Laurence Kedward, Arjen Markus, Ondřej Čertík, Milan Curcic*</span>
12+
13+
<span style="color:grey; font-size:0.8em">*Last update: 19-Oct-2020*</span>
14+
15+
---
16+
17+
In this mini-book we address the very first problem that many new Fortran programmers encounter. Before everything, you will need to choose a compiler and install it. Then you will need a text editor or perhaps an IDE (Integrated Development Environment). There are many options, most of them available in all major OSs (operating systems). However, the process to install and configure them greatly differs between Windows, Linux, and macOS. There are several Fortran compilers. Here, we pick those that meet certain criteria and provide a guide on how to install them in all the aforementioned OSs. A list of popular text editors and IDEs and information on how to choose between them is presented as well.
18+
19+
{% capture redirect_note %}
20+
If you have already set up your environment, you may skip this tutorial and move forward with the [Quickstart Fortran Tutorial]({{site.baseurl}}/learn/quickstart) to start coding your first `Hello World` program or with the [Building programs]({{site.baseurl}}/learn/building_programs) mini-book to understand how a compiler works.
21+
{% endcapture %}
22+
23+
{% include note.html content=redirect_note %}
24+
25+
- - -
26+
27+
*The choice of text editors and IDEs has been controversial among the developers. What you choose is a matter of personal taste. Every solution comes with its own pros and cons. For that reason, in this guide, we will not push the reader towards one or another direction. We will, however, present a list of the most popular tools.*

learn/os_setup/install_gfortran.md

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
---
2+
layout: book
3+
title: Installing GFortran
4+
permalink: /learn/os_setup/install_gfortran
5+
---
6+
7+
GFortran is the name of the [GNU Fortran project](https://gcc.gnu.org/fortran/). The main [wiki](https://gcc.gnu.org/wiki/GFortran) page offers many helpful links about GFortran, as well as Fortran in general. In this guide, the installation process for GFortran on Windows, Linux, and macOS is presented in a beginner-friendly format based on the information from [GFortranBinaries](https://gcc.gnu.org/wiki/GFortranBinaries).
8+
9+
## Windows
10+
11+
12+
Three sources provide quick and easy way to install GFortran compiler on Windows:
13+
1. [http://www.equation.com](http://www.equation.com/servlet/equation.cmd?fa=fortran), provides 32 and 64-bit x86
14+
executables of the latest (10.2) gcc-version.
15+
2. [TDM GCC](https://jmeubank.github.io/tdm-gcc/articles/2020-03/9.2.0-release), provides 32 and 64-bit x86 executables of the 9.2 gcc-version.
16+
3. [MinGW-w64](http://mingw-w64.org/doku.php/download/mingw-builds) provides a 64-bit x86 executable of the 8.1.0 gcc-version.
17+
18+
In all the above choices, the process is straightforward—just download the installer and follow the installation wizard.
19+
20+
### Unix-like development on Windows
21+
For those familiar with a unix-like development environment, several emulation options are available on Windows each of which provide packages for gfortran:
22+
23+
* __Cygwin:__ A runtime environment that provides POSIX compatibility to Windows;
24+
* __MSYS2:__ A collection of Unix-like development tools, based on modern Cygwin and MinGW-w64;
25+
* __Windows Subsystem for Linux (WSL):__ An official compatibility layer for running Linux binary executables on Windows.
26+
27+
All of the above approaches provide access to common shells such as bash and development tools including GNU coreutils, Make, CMake, autotools, git, grep, sed, awk, ssh, etc.
28+
29+
We recommend the WSL environment for those looking for a Unix-like development environment on Windows.
30+
31+
## Linux
32+
33+
34+
### Debian-based (Debian, Ubuntu, Mint, etc...)
35+
Check whether you have gfortran already installed
36+
```bash
37+
which gfortran
38+
```
39+
If nothing is returned then gfortran is not installed.
40+
To install gfortran type:
41+
```bash
42+
sudo apt-get install gfortran
43+
```
44+
to check what version was installed type:
45+
```bash
46+
gfortran --version
47+
```
48+
You can install multiple versions up to version 9 by typing the version number immediately after "gfortran", e.g.:
49+
```bash
50+
sudo apt-get install gfortran-7
51+
```
52+
To install the latest version 10 you need first to add / update the following repository and then install:
53+
```bash
54+
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
55+
sudo apt update
56+
sudo apt install gfortran-10
57+
```
58+
Finally, you can switch between different versions or set the default one with the **update-alternatives** ([see manpage](https://manpages.ubuntu.com/manpages/trusty/man8/update-alternatives.8.html#:~:text=update%2Dalternatives%20creates%2C%20removes%2C,system%20at%20the%20same%20time.)). There are many online tutorials on how to use this feature. A well structured one using as an example C and C++ can be found [here](https://linuxconfig.org/how-to-switch-between-multiple-gcc-and-g-compiler-versions-on-ubuntu-20-04-lts-focal-fossa), you can apply the same logic by replacing either `gcc` or `g++` with `gfortran`.
59+
60+
### RPM-based (Red Hat Linux, CentOS, Fedora, openSuse, Mandrake Linux)
61+
```bash
62+
sudo yum install gcc-gfortran
63+
```
64+
65+
### Arch-based (Arch Linux, Antergos, Manjaro, etc...)
66+
```bash
67+
sudo pacman -S gcc-fortran
68+
```
69+
70+
## macOS
71+
### Xcode
72+
If you have Xcode installed, open a terminal window and type:
73+
```bash
74+
xcode-select --install
75+
```
76+
### Binaries
77+
Go to [fxcoudert/gfortran-for-macOS](https://github.com/fxcoudert/gfortran-for-macOS/releases) to directly install binaries.
78+
### Homebrew
79+
```bash
80+
brew install gcc
81+
```
82+
### Fink
83+
GNU-gcc Package [link](https://pdb.finkproject.org/pdb/browse.php?summary=GNU+Compiler+Collection+Version)
84+
### MacPorts
85+
Search for available gcc versions:
86+
```bash
87+
port search gcc
88+
```
89+
Install a gcc version:
90+
```bash
91+
sudo port install gcc10
92+
```
93+
---
94+
## OpenCoarrays
95+
96+
[OpenCoarrays](http://www.opencoarrays.org/) is an open-source software project that produces an application binary interface (ABI) used by the GNU Compiler Collection (GCC) Fortran front-end to build executable programs that leverage the parallel programming features of Fortran 2018. Since OpenCoarrays is not a separate compiler, we include it here, under gfortran.
97+
98+
While with gfortran you can compile perfectly valid code using coarrays, the generated binaries will only run in a single image (_image_ is a Fortran term for a parallel process), that is, in serial mode. OpenCoarrays allows running code in parallel on shared- and distributed-memory machines, similar to MPI:
99+
```bash
100+
cafrun -n <number_of_images> <executable_name>
101+
```
102+
103+
The process of installation is provided in a clear and comprehensive manner on the official site.
104+
105+
We emphasize that native installation on Windows is not possible. It is only possible through WSL.

learn/os_setup/text_editors.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
---
2+
layout: book
3+
title: Text Editors
4+
permalink: /learn/os_setup/text_editors
5+
---
6+
7+
After you have installed your compiler, you will need a text editor to write your code. Any text editor can serve this purpose, even the built-in Notepad on Windows. However, there are specialized editors for programming languages. These editors come with many useful features like auto-complete, syntax-highlighting, auto-indentation, brace-matching, and many more, with few of them pre-installed and the majority in form of external plug-ins. This means that by default these features are not installed in the editor, but it's up to you to search for them through a package manager and install and configure them manually.
8+
9+
Here's a list of the most popular text editors that support Fortran syntax, in alphabetical order:
10+
- [Atom](https://atom.io/)
11+
- [Emacs](https://www.gnu.org/software/emacs/)
12+
- [NotePad++](https://notepad-plus-plus.org/)
13+
- [SublimeText](https://www.sublimetext.com/)
14+
- [Vim](https://www.vim.org/) and [Neovim](https://neovim.io/)
15+
- [Visual Studio Code](https://code.visualstudio.com/)
16+
17+
A comprehensive list with more choices is provided in [fortranwiki.org](http://fortranwiki.org/fortran/show/Source+code+editors).
18+
19+
Things to consider before choosing a text editor:
20+
- **Ergonomics:** This is purely subjective and concerns how easy, uninterrupted the UI (User Interface) feels to the developer while using the editor.
21+
- **Extensibility:** As mentioned above, text editors come with many features as external packages. The variety, the installation process, the documentation, and user-friendliness of the packages all fall under this category.
22+
- **Speed:** With how powerful modern hardware can be, the speed of editors is becoming of minor importance. However, for the less powerful systems, you may want to consider this as well. Heavyweight editors may impact the writing performance. For example, you can expect Atom and VSCode to run slower than the lightweight editors like Vim or Emacs.
23+
- **Learning curve:** Last but not least, new users should consider how easy it is to get used to a new editor. Vim and Emacs have a steep learning curve and are notoriously difficult for newcomers. They offer a uniquely different experience than any other editor by forcing you to use the keyboard for all editing tasks.
24+
25+
## Configuring VS Code
26+
27+
With the editor opened, at the main UI, at the buttoned-column on the left, there is a *four-square-shaped* icon to open the Marketplace for extensions.
28+
The following extensions are suggested for Fortran developement:
29+
- [Modern Fortran by Miguel Carvajal](https://marketplace.visualstudio.com/items?itemName=krvajalm.linter-gfortran)
30+
- [FORTRAN IntelliSense by Chris Hansen](https://marketplace.visualstudio.com/items?itemName=hansec.fortran-ls)
31+
- Depends on the previous *Modern Fortran* extension, as well as [Python](https://www.python.org/) and [Fortran Language Server](https://github.com/hansec/fortran-language-server), which need to be installed.
32+
- [Fortran Breakpoint Support by ekibun](https://marketplace.visualstudio.com/items?itemName=ekibun.fortranbreaker)
33+
34+
*Note: Both Modern Fortran and Fortran Breakpoint Support require ms-vscode.cpptools, for that you will also need to install the [C/C++ by Microsoft](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools) extension.*
35+
36+
The following are not essential but more advanced users might find useful:
37+
- [Remote - WSL by Microsoft](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-wsl)
38+
- [GitLens — Git supercharged by Eric Amodio](https://marketplace.visualstudio.com/items?itemName=eamodio.gitlens)
39+
- [fprettify by Blamsoft](https://marketplace.visualstudio.com/items?itemName=Blamsoft.fprettify)
40+
- [Even Better TOML by tamasfe](https://marketplace.visualstudio.com/items?itemName=tamasfe.even-better-toml). For Fortran developers that are using the new [fpm](https://github.com/fortran-lang/fpm) *Fortran Package Manager*, a TOML language support might come in handy.
41+
42+
## Configuring SublimeText
43+
44+
A well structured gist that provides instructions on how to set up SublimeText for Fortran developement is given [here](https://gist.github.com/sestelo/6b01e1405c1d0fa7f0ecdc951caaa995).
45+
46+
## Configuring Atom
47+
48+
Atom's configuration process is similar to VSCode one. At the main interface, if the *Welcome Guide* page is already opened for you, just click the **Install a Package** option, otherwise you can find the same option through the navigation bar at the top by clicking *Packages*. In doing so a new page under *Settings* opens where you can just start typing the package you want to install.
49+
50+
One package that includes many Fortran features is [IDE-FORTRAN by hansec](https://atom.io/packages/ide-fortran). It needs the following packages to be installed:
51+
- [atom-ide ui by facebook-atom](https://atom.io/packages/atom-ide-ui)
52+
- [language-fortran by dparkins](https://atom.io/packages/language-fortran)
53+
54+
Additionally just like in VSCode it needs [Python](https://www.python.org/) and [Fortran Language Server](https://github.com/hansec/fortran-language-server) to be installed.
55+
56+
For version control a very popular package is [Git-Plus by akonwi](https://atom.io/packages/git-plus).

learn/os_setup/tips.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
layout: book
3+
title: Smart Tips
4+
permalink: /learn/os_setup/tips
5+
---
6+
7+
To conclude, we give a few tips that may help you to choose a compiler and an editor or an IDE.
8+
9+
- Check [this site](https://www.fortran.uk/fortran-compiler-comparisons/) for a comprehensive comparison of Fortran compilers.
10+
- Since NVFortran version 17.1, the support for compute capability 2.0 (Fermi) and lower has been removed. This is important because, at any time, only the latest compiler version is free to download. Users with older GPUs will not be able to run CUDA Fortran with the current (20.7) or future versions. Read [this wiki](https://www.wikiwand.com/en/CUDA#/GPUs_supported) to find your GPU's compute capability and cross-check with the latest CUDA SDK that supports it.
11+
- There are many online Fortran compilers. These are websites that offer a basic text editor and allow you to compile and run your code on a remote server. They are particularly useful for quick prototyping and testing. Although we promised neutrality, we recommend that you check out the open-source and free [Compiler Explorer](https://godbolt.org/), an amazing tool with unique features.
12+
- Arguably the most popular text editor, according to recent online surveys, is the Visual Studio Code, developed by Microsoft.
13+
- The most popular free IDEs are the Code::Blocks and Geany. Many commercial IDEs give up to 30 days of free trial. Keep in mind that the prices of commercial IDEs may vary, and some may be quite affordable. Finally, if you are a student, an open-source developer, or a …hobbyist *Fortraner* do not hesitate to contact those companies and request a discount. There have been cases, e.g., in r/fortran, where representatives, from at least one company, have offered discount codes to individuals looking for affordable complete solutions (IDE + compiler).
14+
- Finally, please join us on [Fortran Discourse](https://fortran-lang.discourse.group/) and do not hesitate to post your questions and request for further information.

0 commit comments

Comments
 (0)