2 Appendix: processing of fortran commons and C / C++ global variables
3 ========================================================================
6 This section is the result of studies carried out by Marc Boucker, Alexandre Douce, Céline Béchaud and Marc Tajchman
7 (for further details, see [COMMON]_). We do not aim to present a complete state of possible situations in this description.
8 The fortran 77 codes that are to be controlled from the python interpreter or from Corba / SALOME often define memory zones
9 shared between the different fortran functions, called “common”.
10 For example, functions ``f1`` and ``f2`` use the same memory zone ``a`` in common ``C``.
17 .. include:: ./exemples/exemple11/v1/f1.f
25 .. include:: ./exemples/exemple11/v1/f2.f
28 If the two functions are contained in the same component and common ``C`` is not used by functions of other components, the
29 common is not visible from outside the component and “everything takes place properly” (see
30 figure :ref:`Using a common in a component <figcommon0>`). If the component designer wants to allow common to be read or
31 written from the python and/or CORBA layer, he will easily be able to write access functions (for example ``setCommon`` and
32 ``getCommon`` functions in the following example).
36 .. include:: ./exemples/exemple11/v1/common.f
42 .. image:: images/common0.png
45 .. centered:: Using a common in a component
47 The following is an example encapsulation in C++, then in python (through swig):
52 .. include:: ./exemples/exemple11/v1/f.hxx
58 .. include:: ./exemples/exemple11/v1/modf.i
63 .. include:: ./exemples/exemple11/v1/resultats.txt
66 If common ``C`` is used in several dynamic libraries, management is more difficult. In general, it is impossible
67 to assume that the common used by each library is located at the same memory address. There are two typical
68 situations that can arise:
70 #. The two components are installed locally from the same python interpreter:
75 .. image:: images/common1.png
78 .. centered:: Using a common shared between two libraries – Local version
81 #. The two components are installed in different memory zones (on the same machine or on different machines) through
82 the SALOME mechanism (containers):
87 .. image:: images/common2.png
90 .. centered:: Using a common shared between two libraries – distributed version
92 Synchronization functions are necessary in both cases (for example using functions to read / write commons
93 from the python and/or SALOME command layer). The adaptation to the case of two local components loaded from a
94 python interpreter is written as follows:
96 #. For the first component:
100 .. include:: ./exemples/exemple11/v2/f1.hxx
106 .. include:: ./exemples/exemple11/v2/modf1.i
109 #. For the second component:
113 .. include:: ./exemples/exemple11/v2/f2.hxx
119 .. include:: ./exemples/exemple11/v2/modf2.i
122 #. Read and write functions for the common will be included in each component.
128 .. include:: ./exemples/exemple11/v2/resultats.txt
131 In summary, if an existing code comprising commons has to be broken down into several components, it is possible to either:
133 - modify the code by removing the commons and transferring information through lists of function parameters;
134 - write functions to provide read/write access to the commons and use these read/write functions from layers higher
135 than components, so as to synchronize the internal states of the different components.
137 The first solution requires that in-depth action is taken in the fortran code, while the second requires that the
138 user explicitely synchronises commons in the different components. It is strongly recommended that commons should not be
139 used in new fortran codes.
141 C/C++ global variables
142 ------------------------
143 The situation is similar to the case of commons: each component will have its own set of global variables.
144 A method is necessary to assure that these different sets of variables are consistant.