Fortran and FreeBSD

I have used FreeBSD in a virtual machine for several years (just for testing gtk-fortran building) and I am now thinking about installing it on a true hard drive in dual boot with a Linux on one of my machines, to explore it further (and taste again a Unix system without systemd and snap, etc.).

Does someone here use a BSD system? What is your experience with Fortran and its ecosystem? (compilers, fpm, libraries…) And more generally what is your experience concerning FreeBSD (or other *BSD) as an everyday system?

I recently read that 2018 paper entitled “High-Performance Computing & FreeBSD”:

and of course Fortran was one of the major subjects and the last paragraphs are:

Hopefully, in the long-term, we can improve the Fortran situation and make FreeBSD a truly compelling HPC alternative.
It is also important to realize that improving FreeBSD for HPC will not hurt it, either as a server
or workstation system. On the contrary, it will likely be a boon for these use cases.

2 Likes

The last time I looked into this (at least 8 years ago), if you were going to use FreeBSD on server type hardware, there wasn’t any real problem. If you wanted to run on a laptop, you could run into issues with wireless drivers, hibernate features, and graphics cards.

OTOH, OpenBSD was very good with various types of hardware, as the developers “eat their own dogfood.” A base OpenBSD system was pretty easy to install; the drawback for HPC is the security features that are a crucial part of the monolithic kernel would be a performance hit for the most compute intensive applications. But for “small data” it would work just fine.

NetBSD is known for its wide portability on various types of hardware, but I have not looked into it in detail. It has the smallest BSD userbase IIRC.

1 Like

Thanks for the reply @R_cubed

Concerning this problem, we can hope that 8 years later things have evolved. Installing a Linux in the late 90’s could also be a hell concerning hardware…
But probably bleeding-edge hardware can cause problems… But at home my motherboard is ~10 years old (it does not want to die :laughing: and is sufficient for my desktop needs, and I have become lazy with hacking what is inside my tower :grin:).

1 Like

RE: laptop install – at the time, I got the impression FreeBSD was focused on server side performance, and those who got it running on other types of HW were on their own. I haven’t looked into it in awhile, despite being a big fan of BSD systems.

Void Linux is a distro for BSD fans who want to get work done, and not hack on kernels or desktop environments. You have runit instead of systemd, and can compile with different libc implementations (glib vs musl).

:new: I just found this post on running FreeBSD on a laptop on hacker news:

HN Thread:

1 Like

Well, it may not be ready for laptop.

But I will try on a desktop PC. I have started reading that book:

and hope it will be helpful. The style of the author is very pleasant, technically precise and with some humour.

Maybe I am nostalgic of the original Linux thrill… :slightly_smiling_face: But as I am older, will I put the same energy to succeed?

1 Like

I have been using FreeBSD for more than 15 years now, starting with FreeBSD 6.0. Contrary to popular belief, it’s quite versatile (for example, it is the foundation for the operating systems of the Nintendo Switch and the Sony Playstation; and a German vendor ships its slot machines with FreeBSD). I’m running it on desktops, laptops, servers, and embedded systems without any major issue.

When I made my first steps with Linux, about 25 years ago, I didn’t find it very appealing. If I have to decide between the cathedral and the bazaar, I certainly choose the cathedral. Or, to describe it ex negativo:

  • Wheras FreeBSD is a complete operating system, Linux is just a kernel. You will need a Linux distribution to make any use of it. And that’s where things start to get hairy, with all the subtile differences between them and the dubious decisions of their maintainers (like, systemd).
  • Linux is indifferent towards external packages. There is not separation between the operating system per se and the user land (see /usr/local vs. /usr vs. /opt). Some people may prefer this higgledy-piggledy, but I’d like to keep the OS and all third-party applications apart. Also, it’s trivial to install multiple versions of a package side by side on FreeBSD (like, LLVM, or GCC).
  • I don’t understand the various package management concepts in Linux land. The most natural way to distribute software is by source (called Ports in FreeBSD). And if you maintain more than one machine, FreeBSD makes it quite easy to set-up your own package build infrastructure (called Poudriere), to distribute software with the build options you have chosen.
  • I’ve found the documentation on FreeBSD to be of much higher quality than on Linux (especially, man pages). Maybe, because you find more grown-up people there who care to write documentation in the first place.
  • Virtualisation on Linux is just weird for anyone who has ever seen FreeBSD Jails or Solaris Zones.
  • Linux will never have proper ZFS support.
  • GNUisms are the worst (they should be punishable).

At the end, it comes down to ideological questions. If you can’t give any reason to abandon Linux, you probably shouldn’t. But if you want to experience the true Unix feeling, you should give FreeBSD a try!

5 Likes

Thanks @interkosmos for your precise answer.
I won’t say I want abandon Linux, but I am not happy with some Ubuntu evolutions, especially snaps packages (I need to clean old versions to keep space, my browser starts slower than before, and shows regularly pop-up windows about new snap versions…)

But sure, I feel attracted by a purer experience, the true Unix feeling as you say. Yes, I will try FreeBSD as soon as I have some time for installation, and report it. And I will see later if I want to go further…

So you are programming in Fortran (or other languages) in BSD? No specific problems?

Well, the variety in Fortran compilers is obviously more limited (no Intel oneAPI, but it may work through the Linux abstraction layer, haven’t tried). Overall, the development experience is better in my opinion, simply, because you build from source anyway, so, most dev tools are present by default; FreeBSD packages ship with headers (no silly -dev packages like on Linux); and you can install multiple versions of a compiler on the same machine without any issues.

Beside Fortran, I also code in C/C++, Lua, Tcl, and Python on FreeBSD. I did some experiments with assembler (MOS 6510), Forth, Inform, BASIC, COBOL, REXX, and many more, all work flawlessly.

1 Like

By this, are you referring to GNU extensions of the C language? The other interpretation I found are incompatibilities (additional options) in what are supposed to be POSIX tools.

Yes. And there are plenty, either in the kernel or in GNU ports of various Unix tools, such as sed, make, awk¹.


¹ To be honest, GNU awk is much better than the AT&T UNIX version.

FreeBSD also has a binary packages manager. If there are a lot of tools to install (especially if you want a desktop with LibreOffice) compiling from source could take a very long time.

@interkosmos Since you have lots of experience with FreeBSD, could you describe how you selected the hardware you would use? I wanted an OS that worked on something I could pick up at a “big box” electronics store in the U.S. and could not be as selective in my hardware choices as serious BSD users are. I concluded that if one is willing to put in the time up front and make careful hardware selections, FreeBSD could be a great choice for a developer’s system. If I needed to do HPC, FreeBSD would be worth serious consideration.

1 Like

You definitely have to do your research upfront and check the compatibility (by web search, FreeBSD wiki look-up, or live system from USB memstick). Your choices regarding GPUs are limited: either Intel, for which free drivers exist, or Nvidia (official BLOB driver). Also, the newest wifi chipsets may not be supported. On desktop, I went fine with Intel CPU, Intel mainboard, and Nvidia GPU. For mobile computing, > 2 years old ThinkPad generations are mostly fine.

True. That’s why I build the packages on an octa-core Xeon with 128 GiB memory. LibreOffice is still in the mid-range, LLVM and Rust are much worse.

1 Like

Well, in my virtual machine I used the binary packages manager (pkg install) to install what I need (GFortran, GTK, XFCE, Firefox…).
And I think I will do the same if I try FreeBSD on my 10 years old secondary machine at home with a Pentium G3220 (a low cost 2 cores) and 8 GB… Although it’s old, I don’t want to kill it too soon :fire: :laughing:

So you create a disk partition for /usr ? And does it really mean you can reinstall the system without reinstalling the external packages?

You don’t have to put /usr in its on partition. It’s just about the separation between OS (/usr) and packages/ports (/usr/local). Usually, there is no need to reinstall FreeBSD, I’ve done it rarely in the past. Moreover, “installation” on FreeBSD just means unpacking a .txz archive, even if this step is hidden by shell scripts like bsdinstall(8). In theory, the base installation shouldn’t interfere with any third-party applications.

1 Like

First of all, using GNU/Linux doesn’t mean you have to tolerate systemd or snap. I use GNU/Linux since… forever, and I never used a distribution with such bloatware - and never will. There are several systemd-free choices, but I would also consider distributions free of other crapware (at least for me, that’s exactly what it is) - such as elogind, and pulseaudio.

Now, about FreeBSD. I use it for a few years now (real installation to disk, both 32- and 64-bit versions). Fortran-wise, there are no issues to speak of (at least for gfortran.) In fact, while developing my libraries, all I have to do to make it work on FreeBSD is to untar and rebuild, with zero changes in the code, makefiles, FORD documentation, valgrind checking, etc.

Admittedly, I had to modify my makefiles so that they install stuff at the right place (for example, shared libraries go to /usr/local/lib instead of /usr/lib or usr/lib64.) But it’s not hard to make a generic makefile that will detect the operating system running, and pick the right place for libraries, *.mod files, etc. Those are trivial changes you do once and then forget about it. In fact, pretty much all my projects were developed half-GNU/Linux, half-FreeBSD, depending on the machine I was working at the moment. It’s not uncommon for me to have a part of the code written in FreeBSD, then switch to GNU/Linux the next day, add some code, then back to FreeBSD. With very little effort done years ago, the transition is literally seamless since then. I even forget what operating system I am using while programming.

If you want the latest gfortran always installed, you will have to do tweaks, because FreeBSD is a bit conservative on updating packages (comes with gfortran 12.2 by default right now.) But that’s nothing new, many GNU/Linux distributions do the same - except the “bleeding-edge” distributions, which I wouldn’t recommend anyway. Other Fortran compilers may not work.

Some pros worth mentioning:

  • Excellent package manager. Easily the best one I’ve ever used. Debian’s “apt” is not bad at all, but FreeBSD’s “pkg” is better.
  • The “native” file system, ZFS, is excellent (but you can use others too.)
  • Great documentation out-of-the-box, and the forums are full of people willing to help (as long you follow the rules, which are more strict that the norm.)
  • Dual booting is done the easiest and most lightweight way ever. You can easily forget about bloatware such as GRUB, if you want to.
  • Can run on ancient hardware. I have a 15+ years old netbook, which was nothing to write home about even when it was new, and it runs the latest stable FreeBSD release (I use it for programming when I’m not at home and have limited space for a proper laptop.) The same machine can’t run most GNU/Linux distributions, and soon won’t be able to run any. That’s because glibc breaks compatibility with some old hardware (since glibc 2.36.) It is very unlikely something similar will ever happen in FreeBSD.
  • Forget about systemd and elogind once and forall (sic - or should I say “concurrent” to be more up-to-date?) There ain’t such a thing in FreeBSD. Pulseaudio is installed only if you want to.
  • Most software you would expect is there, one doas pkg install away. It is a myth FreeBSD lacks important software. It doesn’t.
  • “Linuxisms” are frowned upon and, I dare say, for good reason.

Not everything is la vie en rose though:

  • Lack of drivers… if you have the latest, expensive GPU, you 'll probably have issues. And if you have a laptop, make sure your WiFi chipset is supported (this is the most common problem,) or get ready for a WiFi dongle.
  • Bluetooth is… problematic, to say the least.
  • BSD in general is treated as a second-class citizen. Several developers don’t even bother to mention it (but like I said that’s not true for “important” software.) That’s not a problem for me, but might be for others.

To sum up, I will completely migrate to FreeBSD (together with OpenBSD, which I also like) at some point. It’s that good. However I keep using some GNU/Linux distributions (together with BSDs) because… good luck convincing people to do the same.
I’d say, if you have a spare machine, or an external SSD, or even a decent USB, give it a try with a real installation. I have seen issues caused by virtual machines, which you won’t have in real installations.
The least issue you will have is Fortran programming.

2 Likes

Thanks a lot, all that is encouraging!

Maybe it will be more encouraging if I describe the one and only change I had to make (and like I said you do that once, then forget it.) I have a generic Makefile like this:

TEST_STRING = $(shell echo "test")
ifeq ($(TEST_STRING),test)
	TARGET_OS = Unix
	ifeq ($(shell uname), Linux)             # GNU/Linux settings:
		MAKE = make -j
		USR_DIR = /usr
		ifeq ($(shell getconf LONG_BIT), 64)
			SYSTEM_LIB_DIR=$(USR_DIR)/lib64
		else
			SYSTEM_LIB_DIR=$(USR_DIR)/lib
		endif
	else ifeq ($(shell uname), FreeBSD)      # FreeBSD settings:
		MAKE = gmake -j
		USR_DIR = /usr/local
		SYSTEM_LIB_DIR=$(USR_DIR)/lib
	endif
	SYSTEM_INC_DIR = $(USR_DIR)/include
else ifeq ($(TEST_STRING), "test")
	# Stuff for... that other "operating system" goes here, if you need it.
endif

include Makefile.$(TARGET_OS)

This defines the system’s include and lib directories. For GNU/Linux it’s basically the FHS (Filesystem Hierarchy Standard) - except the system’s lib directory may differ in 64-bit. As you can see, settings for FreeBSD are even easier.

This generic Makefile loads Makefile.Unix in the end, which is the normal Makefile you would use on GNU/Linux, except include and lib directories are predefined in the generic Makefile above as $SYSTEM_INC_DIR and $SYSTEM_LIB_DIR, respectively.
The actual Makefile that does the building job is named “Makefile.Unix” because it is exactly the same for GNU/Linux and FreeBSD.

In this example, I use gmake for the actual building in FreeBSD, which is basically GNU Make. The makefiles would be slightly different if you use BSD’s make, but if you switch from one operating to another often (as I do) using gmake is more practical.

And… that’s pretty much it. Everything in your code should be exactly the same. In other words: use a generic makefile like the one above to set directories, and that’s it. The rest is the same for both GNU/Linux and FreeBSD.

I’m sure there are other ways to do the same thing, but the one I tried to describe here just works. Every time. This is why I said with very little effort done once, transition to FreeBSD programming is seamless.

1 Like

I have installed FreeBSD 13.2 ten days ago on an old 120 GB Sata3 hard drive on my “old” PC. Before installation, I removed all the other drives by security. Now with UEFI, if I want to go in FreeBSD, I just have to press F8 at boot to see the UEFI boot menu. So I have not yet tried to configure GRUB2.

The installation was easy using the “memstick” image. The steps are detailed in:

It was also easy to install Xorg and XFCE for the desktop. I just had to install also the driver of my video card to improve the fluidity. And XFCE depending on GTK, that library was already installed. And yes, the development files are included in each library package. Video, sound and networking are working. I have not yet tried to install my printer.

Development tools were easy to install:

# pkg install gcc13 git cmake pkgconf vim

GFortran is included in the gcc13 package and is named gfortran13. To install fpm, I had to create two symbolic links in /usr/local/bin for gcc and gfortran.

I have also noticed that there is a LFortran 0.19 package available:

$ pkg search fortran
cfortran-4.3                   Easy-to-use powerful bridge between C and FORTRAN
fortran-utils-1.1              Tools for use with Fortran code, from 4.4BSD
lfortran-0.19.0_2              Modern interactive Fortran compiler built on top of LLVM
linux-c7-libgfortran-4.8.5_6   Runtime libraries for gfortran (Linux Centos 7.9.2009)
netcdf-fortran-4.6.0           Fortran library for machine-independent, array-oriented data access

Well, so far FreeBSD is very pleasant. It sticks to the configuration text files philosophy. And it looks like a very well ordered system (I discovered the page man hier). And the official documentation is really excellent!

I am continuing to read the book Absolute FreeBSD (also excellent) and learn a lot of things (and some concerning also Linux).

1 Like

Searching in the packages comments:

$ pkg search -c fortran
f77flow-0.12_1                 Analyze the structure of a fortran77 program
py39-scikit-build-0.16.7_1     Build system generator for Python C/C++/Fortran/Cython extensions
pgplot-5.2.2_30                C/FORTRAN library for drawing graphs on a variety of display devices
math77-6.0_10                  CalTech mathematical subprogram libraries for Fortran 77
cfortran-4.3                   Easy-to-use powerful bridge between C and FORTRAN
ftnchek-3.3.1                  Fortran 77 semantic checking utility
fox-xml-4.1.2.91_5             Fortran XML library
shroud-wrapper-generator-0.12.2.20220929 Fortran and Python wrapper generator for C and C++ libraries
qrupdate-1.1.2_12              Fortran library for fast updates of QR and Cholesky decomposition
netcdf-fortran-4.6.0           Fortran library for machine-independent, array-oriented data access
fpp-1.1_1                      Fortran preprocessor for FORTRAN 77 and Fortran 90 programs
SLICOT-5.8_2                   Fortran subroutines library for systems and control
f2c-20200916                   Fortran-to-C converter and its run-time libraries
p5-ExtUtils-F77-1.26_2         Helps link C programs with Fortran subroutines
R-cran-inline-0.3.19_1         Inline C, C++, Fortran function calls from R
lapack95-1.0_20                LAPACK95, Fortran90/95 wrapper for LAPACK
cgribex-1.9.4_3                Lightweight GRIBEX in C with portable Fortran interface
mpifx-1.3.1_1                  Modern Fortran wrappers around MPI routines
scalapackfx-1.1_1              Modern Fortran wrappers around ScaLAPACK routines
lfortran-0.19.0_2              Modern interactive Fortran compiler built on top of LLVM
py39-pynleq2-0.0.2_8           Python binding for NLEQ2 algorithm s fortran implementation
ratfor-1985.06_15              Rational FORTRAN compiler
cblas-3.11.0_1                 Reference implementation of the C interface to the legacy Fortran BLAS
linux-c7-libgfortran-4.8.5_6   Runtime libraries for gfortran (Linux Centos 7.9.2009)
xmlf90-1.5.5_1                 Suite of light-weight libraries to work with XML in Fortran
toml-f-0.3.1_1                 TOML parser for data serialization and deserialization in Fortran
fortran-utils-1.1              Tools for use with Fortran code, from 4.4BSD
opencoarrays-2.10.1            Transport layer for coarray Fortran compilers