[793] | 1 | \documentclass[twoside,12pt]{article}
|
---|
| 2 | % Package standard : Utilisation de caracteres accentues, mode francais et graphique
|
---|
| 3 | \usepackage[latin1]{inputenc}
|
---|
| 4 | \usepackage[T1]{fontenc}
|
---|
| 5 | \usepackage{babel}
|
---|
| 6 | \usepackage{graphicx}
|
---|
| 7 |
|
---|
| 8 | % Extension de symboles mathematiques
|
---|
| 9 | \usepackage{amssymb}
|
---|
| 10 |
|
---|
| 11 | % Definition de taille de page
|
---|
| 12 | \setlength{\textwidth}{16cm}
|
---|
| 13 | \setlength{\textheight}{21.5cm}
|
---|
| 14 | \setlength{\topmargin}{0.5cm}
|
---|
| 15 | \setlength{\oddsidemargin}{0.cm}
|
---|
| 16 | \setlength{\evensidemargin}{0.cm}
|
---|
| 17 | \setlength{\unitlength}{1mm}
|
---|
| 18 |
|
---|
| 19 | \newcommand{\bul}{$\bullet \ $}
|
---|
| 20 |
|
---|
| 21 | \begin{document}
|
---|
| 22 |
|
---|
| 23 | \begin{titlepage}
|
---|
| 24 | \vspace{1cm}
|
---|
| 25 | \rule{110 mm}{0.5 mm}\makebox[50 mm]{\bf Planck HFI L2}
|
---|
| 26 | \vspace{2cm}
|
---|
| 27 | \begin{center}
|
---|
| 28 | \par \renewcommand{\baselinestretch}{2.0} \small
|
---|
| 29 | {\LARGE \bf
|
---|
| 30 | Planck HFI L2 \\
|
---|
| 31 | Software Development Guidelines
|
---|
| 32 | }
|
---|
| 33 | \par \renewcommand{\baselinestretch}{1.0} \normalsize
|
---|
| 34 | \vspace{5 cm}
|
---|
| 35 | \begin{tabular}{ll}
|
---|
| 36 | {R. Ansari} & {\tt ansari@lal.in2p3.fr} \\
|
---|
| 37 | {É. Aubourg} & {\tt aubourg@hep.saclay.cea.fr} \\
|
---|
| 38 | % {É. Lesquoy} & {\tt lesquoy@hep.saclay.cea.fr} \\
|
---|
| 39 | % {C. Magneville} & {\tt cmv@hep.saclay.cea.fr} \\
|
---|
| 40 | \end{tabular}
|
---|
| 41 |
|
---|
| 42 | \end{center}
|
---|
| 43 | \vfill
|
---|
| 44 | \hfill
|
---|
| 45 | % \includegraphics[width=4cm]{Fig/hfi_icon_vsmall.eps}
|
---|
| 46 | \framebox[\textwidth]{\hspace{0.5cm} \bf Planck HFI Level 2
|
---|
| 47 | \hspace{1cm} \today }
|
---|
| 48 | \end{titlepage}
|
---|
| 49 |
|
---|
| 50 | \tableofcontents
|
---|
| 51 |
|
---|
| 52 | \newpage
|
---|
| 53 | % \tableofcontents
|
---|
| 54 |
|
---|
| 55 | \section{Introduction}
|
---|
| 56 | We intend to gather gradually in this document the guidelines
|
---|
| 57 | for the development of Planck HFI Level 2 data processing softwares.
|
---|
| 58 | We assume throughout this document that C++ is the baseline option
|
---|
| 59 | as the programming language for the development of Planck HFI
|
---|
| 60 | Level 2 processing software.
|
---|
| 61 |
|
---|
| 62 | \section{Integration of software modules in different languages}
|
---|
| 63 | We review here some of the problems which may arise when integrating software
|
---|
| 64 | modules written in other languages into C++ programs.
|
---|
| 65 |
|
---|
| 66 | \subsection{C and C++}
|
---|
| 67 | C++ extends the possibilities offered by the C language.
|
---|
| 68 | All of the C language data types and function call syntax are thus
|
---|
| 69 | supported by C++. Among other features, C++ offers the function
|
---|
| 70 | overloading possibility. This means that functions with different
|
---|
| 71 | argument list can have the same name.
|
---|
| 72 | \begin{verbatim}
|
---|
| 73 | int fo(int a);
|
---|
| 74 | int fo(int a, int b);
|
---|
| 75 | int fo(double a, double b);
|
---|
| 76 | \end{verbatim}
|
---|
| 77 | Using {\bf C}, one would have written:
|
---|
| 78 | \begin{verbatim}
|
---|
| 79 | int foi(int a);
|
---|
| 80 | int foii(int a, int b);
|
---|
| 81 | int fodd(double a, double b);
|
---|
| 82 | \end{verbatim}
|
---|
| 83 | C++ compilers use internally a name containing the encoding of the
|
---|
| 84 | argument list. In order to instruct the compiler to use simple
|
---|
| 85 | names, {\bf C} functions should be declared as \\
|
---|
| 86 | {\tt extern "C" }. This is usually included in the header
|
---|
| 87 | file (.h). In the example above, the header file (.h) file
|
---|
| 88 | would be in the form:
|
---|
| 89 | \begin{verbatim}
|
---|
| 90 | #ifdef __cplusplus
|
---|
| 91 | extern "C" {
|
---|
| 92 | #endif
|
---|
| 93 | int foi(int a);
|
---|
| 94 | int foii(int a, int b);
|
---|
| 95 | int fodd(double a, double b);
|
---|
| 96 | #ifdef __cplusplus
|
---|
| 97 | }
|
---|
| 98 | #endif
|
---|
| 99 | \end{verbatim}
|
---|
| 100 |
|
---|
| 101 | \subsection{Fortran and C++}
|
---|
| 102 | Fortran is a simple language and uses only basic data types.
|
---|
| 103 | Although the exact mapping between Fortran and C/C++ basic data types
|
---|
| 104 | may vary depending on the OS and hardware architecture, it is close
|
---|
| 105 | to the one shown in the table below:
|
---|
| 106 | \begin{center}
|
---|
| 107 | \begin{tabular}{lll}
|
---|
| 108 | INTEGER & int & usually 4 bytes \\
|
---|
| 109 | REAL*4 & float & usually 4 bytes \\
|
---|
| 110 | REAL*8 & double & usually 8 bytes \\
|
---|
| 111 | COMPLEX & complex<float> & \\
|
---|
| 112 | COMPLEX*16 & complex<double> & \\
|
---|
| 113 | \end{tabular}
|
---|
| 114 | \end{center}
|
---|
| 115 | In fortran, all arguments are passed by address and
|
---|
| 116 | fortran compilers (on Unix systems) add an underscore "\_"
|
---|
| 117 | to all symbol names. It is thus rather easy to call
|
---|
| 118 | Fortran subroutines or functions from C or C++.
|
---|
| 119 | This is illustrated in the following example:
|
---|
| 120 | \begin{verbatim}
|
---|
| 121 | C Fortran-Code
|
---|
| 122 | SUBROUTINE FSUB(A,N,B,M)
|
---|
| 123 | REAL A(*),B(*)
|
---|
| 124 | INTEGER N,M
|
---|
| 125 | RETURN
|
---|
| 126 | END
|
---|
| 127 | \end{verbatim}
|
---|
| 128 | The corresponding C (or C++) declaration is: \\[3mm]
|
---|
| 129 | {\tt void fsub\_(float *a, int *n, float *b, int *m); } \\[3mm]
|
---|
| 130 | {\tt FSUB} can be called from C code, as is shown below :
|
---|
| 131 | \begin{verbatim}
|
---|
| 132 | float aa[10];
|
---|
| 133 | int na=10;
|
---|
| 134 | float bb[10];
|
---|
| 135 | int mb=10;
|
---|
| 136 | fsub_(aa, &na, bb, &mb);
|
---|
| 137 | \end{verbatim}
|
---|
| 138 |
|
---|
| 139 | The case of character string arguments in fortran subroutines
|
---|
| 140 | needs a bit more attention, and the string length needs to be passed
|
---|
| 141 | as an additional integer type argument.
|
---|
| 142 | As with {\bf C} functions, fortran functions or subroutines
|
---|
| 143 | have to be delared {\tt extern "C"} to be used within {\bf C++}
|
---|
| 144 | programs. {\bf C/C++} driver routines can easily be written for
|
---|
| 145 | extensively used fortran modules, simplifying calling sequences.
|
---|
| 146 |
|
---|
| 147 | It should also be noted that the fortran support libraries have to be
|
---|
| 148 | included for the link with the C++ driver.
|
---|
| 149 | It is also possible to translate the whole fortran source code
|
---|
| 150 | into {\bf C} code using {\bf f2c} program. The call syntax
|
---|
| 151 | will be exactly the same as with a Fortran compiler, and
|
---|
| 152 | {\tt libf2c.a} should be used when linking the program.
|
---|
| 153 |
|
---|
| 154 | It is very difficult to use C++ classes directly from fortran.
|
---|
| 155 | However, high level functionalities based on a C++ libray can
|
---|
| 156 | be wrapped in a fortran style function which can be
|
---|
| 157 | called from fortran. One looses of course many of the
|
---|
| 158 | possibilities offered by underlying C++ library.
|
---|
| 159 |
|
---|
| 160 | We illustrate below the wrapping of a simple C++ class:
|
---|
| 161 | \begin{verbatim}
|
---|
| 162 | // An example class performing some computation
|
---|
| 163 | class Example {
|
---|
| 164 | Example();
|
---|
| 165 | ~Example();
|
---|
| 166 | void compute(int sz, float *x);
|
---|
| 167 | int getSize();
|
---|
| 168 | float getResult(int k);
|
---|
| 169 | };
|
---|
| 170 | \end{verbatim}
|
---|
| 171 |
|
---|
| 172 | The wrapper would then look like:
|
---|
| 173 | \begin{verbatim}
|
---|
| 174 | extern "C" {
|
---|
| 175 | void foradapt_(float *a, int *n, float *b, int *m);
|
---|
| 176 | }
|
---|
| 177 |
|
---|
| 178 | foradapt_(float *a, int *m, float *b, int *n)
|
---|
| 179 | {
|
---|
| 180 | // a is the input array, m it's size
|
---|
| 181 | // b is the output array, n the returned size
|
---|
| 182 | // b has to dimensioned big enough in the calling program
|
---|
| 183 |
|
---|
| 184 | Example ex;
|
---|
| 185 | ex.compute(*n, a);
|
---|
| 186 | *m = ex.getSize();
|
---|
| 187 | for(int i=0; i<ex.getSize(); i++)
|
---|
| 188 | b[i] = ex.getResult(i);
|
---|
| 189 | }
|
---|
| 190 | \end{verbatim}
|
---|
| 191 |
|
---|
| 192 | One can then call {\tt FORADPAT} from fortran :
|
---|
| 193 | \begin{verbatim}
|
---|
| 194 | REAL A(1000)
|
---|
| 195 | REAL B(1000)
|
---|
| 196 | INTEGER N,M
|
---|
| 197 | M = 1000
|
---|
| 198 | N = 1000
|
---|
| 199 | CALL FORADPAT(A, M, B, N)
|
---|
| 200 | \end{verbatim}
|
---|
| 201 |
|
---|
| 202 |
|
---|
| 203 | \subsection{Fortran-90 and C++}
|
---|
| 204 | Fortran-90 (F90) is a much more complex language than Fortran 77
|
---|
| 205 | (F77). Compared to F77, it introduces many new constructions, including:
|
---|
| 206 | \begin{itemize}
|
---|
| 207 | \item[-] pointers
|
---|
| 208 | \item[-] local and global variables
|
---|
| 209 | \item[-] in, out, in-out argument type for function and subroutines
|
---|
| 210 | \item[-] compound data types, similar to structures in C
|
---|
| 211 | \item[-] multidimensional arrays
|
---|
| 212 | \item[-] function and operator overloading.
|
---|
| 213 | \end{itemize}
|
---|
| 214 | It is thus more difficult to use full featured F90 modules from
|
---|
| 215 | {\bf C} or {\bf C++}. One would have to map all these different
|
---|
| 216 | data structures with their attributes between the two languages,
|
---|
| 217 | in a OS/compiler independent way.
|
---|
| 218 | It should however be possible to encapsulate F90 modules into simple F77
|
---|
| 219 | like subroutines that could be called from C/C++.
|
---|
| 220 |
|
---|
| 221 |
|
---|
| 222 | \newpage
|
---|
| 223 | \appendix
|
---|
| 224 |
|
---|
| 225 | \section{The C++ language}
|
---|
| 226 | \vspace{5 mm}
|
---|
| 227 | {\bf C++} is a very powerful Object Oriented language.
|
---|
| 228 | It has been developped by extending the {\bf C} language,
|
---|
| 229 | keeping in mind the efficiency and performance,
|
---|
| 230 | as well as easy integration with existing softwares.
|
---|
| 231 | It incorporates new possibilities such as:
|
---|
| 232 |
|
---|
| 233 | \begin{itemize}
|
---|
| 234 | \item Introduction of object and classes
|
---|
| 235 | \item function overloading
|
---|
| 236 | \item Operator overloading
|
---|
| 237 | \item function and operator inlining (optimisation)
|
---|
| 238 | \item virtual functions (polymorphism)
|
---|
| 239 | \item public, protected and private members
|
---|
| 240 | \item dynamic memory management operators
|
---|
| 241 | \item Exception handling
|
---|
| 242 | \item generic (template) function and classes
|
---|
| 243 | \end{itemize}
|
---|
| 244 |
|
---|
| 245 | {\bf C++} can be considered now as a mature language.
|
---|
| 246 | C++ class library covering various areas, including
|
---|
| 247 | numerical data processing are available as freeware
|
---|
| 248 | or commercial products. Many software tools feature
|
---|
| 249 | a standard C++ API.
|
---|
| 250 | \par \vspace{3mm}
|
---|
| 251 | The current standard for C++ and C are defined by
|
---|
| 252 | \footnote{Available from {\bf http://www.ansi.org/ } }:
|
---|
| 253 | \begin{itemize}
|
---|
| 254 | \item[] {\bf ISO/IEC 14882-1998(E)} Programming languages -- C++
|
---|
| 255 | \item[] {\bf ANSI/ISO 9899-1990} for Programming Languages C
|
---|
| 256 | \end{itemize}
|
---|
| 257 |
|
---|
| 258 |
|
---|
| 259 | \newpage
|
---|
| 260 | \section{C++ compilers}
|
---|
| 261 |
|
---|
| 262 |
|
---|
| 263 | Powerful compilers are available on most platforms,
|
---|
| 264 | including:
|
---|
| 265 |
|
---|
| 266 | \begin{itemize}
|
---|
| 267 | \item[-] the GNU multiplatform g++ \footnote{http://gcc.gnu.org/},
|
---|
| 268 | \item[-] KAI KCC \footnote{http://www.kai.com/C\_plus\_plus/} which is a
|
---|
| 269 | nice multiplatform optimising C++ compiler.
|
---|
| 270 | \item[-] Digital (Compaq) cxx \footnote{http://www.unix.digital.com/cplus/}
|
---|
| 271 | \item[-] IBM VisualAge C++ \footnote{http://www-4.ibm.com/software/ad/vacpp/}
|
---|
| 272 | \item[-] HP aCC \footnote{http://www.hp.com/esy/lang/cpp/}
|
---|
| 273 | \item[-] Silicon Graphics SGI-CC on IRIX \footnote{http://www.sgi.com/developers/devtools/languages/c++.html}
|
---|
| 274 | \item[-] Cray C++ compiler on Unicos \footnote{http://www.sgi.com/software/unicos/cplusoverview.html}
|
---|
| 275 | \end{itemize}
|
---|
| 276 |
|
---|
| 277 |
|
---|
| 278 | \end{document}
|
---|