Questions tagged [fortran-common-block]

A common block is a structure in Fortran that contains variables that are global to the program. Questions should be about their use in Fortran, porting common blocks to other programming languages, or interoperability with other languages.

A common block is a structure in Fortran that contains variables that are global to the program. Questions should be about their use in Fortran, porting common blocks to other programming languages, or interoperability with other languages.

61 questions
6
votes
2 answers

"Saving" a common block

I'm dealing with some legacy code that uses COMMON blocks extensively and sometimes uses the SAVE statement. After consulting the Fortran standard, it says: The appearance of a common block name preceded and followed by a slash in a SAVE statement…
mgilson
  • 300,191
  • 65
  • 633
  • 696
5
votes
1 answer

Do COMMON blocks in Fortran have to be declared threadprivate in every subroutine for OpenMP?

I am modifying some old, old Fortran code to run with OpenMP directives, and it makes heavy use of COMMON block. I have found multiple sources that say that using OMP directives to declare COMMON blocks as THREADPRIVATE solves the issue of COMMON…
Frank
  • 544
  • 2
  • 14
4
votes
0 answers

Named common block in a shared library

I am encountering a problem when I include a Fortran subroutine in a shared library. This subroutine has a named common block. I have a Fortran main program that uses this common block and links with the shared library. The behavior is that…
4
votes
0 answers

Loading two instances of a shared library without RTLD_PRIVATE or multiple copies

In C++ I need to run multiple instances of legacy FORTRAN libraries (over which I have no control) which use COMMON BLOCK variables. I can successfully do this following the prescription of Question 3433522, where I create 2 physical copies of the…
4
votes
2 answers

Is there a difference memory-wise between using Common Blocks and Modules in Fortran 90

I am recently learning Fortran without any guidance, and experimenting with different versions. I have found from this site: Is a MODULE better than a COMMON block? Almost always yes. The only reasons to use COMMON blocks are if you expect to use…
osolmaz
  • 1,873
  • 2
  • 24
  • 41
4
votes
2 answers

Why would common block variables not preserve their values?

First, I know that using common blocks is a bad idea in fortran (and programming in general). However, I'm updating someone else's code and I don't want to mess up things that are known to work. Second, I know I should post something more specific…
Yotam
  • 10,295
  • 30
  • 88
  • 128
4
votes
3 answers

Making multiple modules from multiple common blocks fortran 77

Currently in my program I have several common blocks spread across several subprograms and functions. I sometimes forget to change all instances of a common block as I add variables to it. I want to make these common blocks into modules so I can add…
kxk7607
  • 207
  • 1
  • 4
  • 10
3
votes
3 answers

Allocatable arrays performance

There is an mpi-version of a program which uses COMMON blocks to store arrays that are used everywhere through the code. Unfortunately, there is no way to declare arrays in COMMON block size of which would be known only run-time. So, as a workaround…
TruLa
  • 1,031
  • 11
  • 21
3
votes
1 answer

Can I add a watch to a COMMON block?

I have a very large, very old, very byzantine, very undocumented set of Fortran code that I am trying to troubleshoot. It is giving me divide-by-zero problems at run time due to a section that's roughly like this: subroutine badsub(ainput) …
Frank
  • 544
  • 2
  • 14
3
votes
1 answer

How do I compile this legacy FORTRAN 77 code with *.h files?

I have a collection of .F and .H files that makeup a FORTRAN code. I'm running into trouble tyring to compile the .H files. The .H files contain a bunch of common blocks. An example of one of the .H files is: *AC HEAD c …
Bob
  • 263
  • 1
  • 3
  • 6
3
votes
2 answers

Visibility, Fortran common variables, runtime loading of shared libraries

Environment: Intel Linux, Red Hat 5. Compiler: gcc 3.4.6 (old stuff, legacy environment with serious infrastructure, sorry) I have multiple versions of a particular shared library (call it something like "shared_lib.so") derived from Fortran which…
3
votes
3 answers

Common block equivalent in C++

I am trying to convert an old Fortran 77 code to C++ and most of the variables are declared in Common blocks such as: COMMON/BLK1/Gw(200),Eta(4096),t(4096),Phi(200),w(200) COMMON/BLK2/g,dw,Vel,M,dt,N,Ioutp1,Ioutp2 COMMON/BLK3/Hs,Std,E,Hs1,Tdt As I…
user3460758
  • 957
  • 7
  • 15
  • 25
3
votes
1 answer

How does Fortran 77 allocate common-block variables?

I am developing a library in C that should work with C, C++, or Fortran code. One mechanism it uses is to trap writes to pages in the stack, heap, or data/bss segments. The "heap" in this case is a special heap that the library creates out of a…
Amittai Aviram
  • 2,270
  • 3
  • 25
  • 32
2
votes
1 answer

C-Fortran Mixed Programming

I am working on a project where I have to use a Fortran library in C. In the Fortran library there is a common block containing a complex*16, 4x4 array. Now in C, a complex variable is simply a struct containing two elements and since it is…
Shaz
  • 273
  • 2
  • 6
  • 12
2
votes
0 answers

Custom type with pointer in COMMON block not being passed properly

(Edited 2021-09-06 13:30 CEST after I found out that the problem is caused at a different place of my code already) I am working on some code (not my own) where they use a custom type for dynamic integer arrays. One instance of this type is passed…
1
2 3 4 5