Changeset 3839 in Sophya for trunk/SophyaLib/Manual/sophya.tex


Ignore:
Timestamp:
Aug 9, 2010, 7:32:00 PM (15 years ago)
Author:
ansari
Message:

MAJ sophya.tex pour V2.2 en cours, Reza 09/08/2010

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaLib/Manual/sophya.tex

    r3723 r3839  
    4848\vspace{1cm}
    4949\begin{center}
    50 {\bf \Large Sophya Version: 2.2 (V\_Jan2010) }
     50{\bf \Large Sophya Version: 2.2 (V\_Sep2010) }
    5151\end{center}
    5252\titrebp{1}
     
    103103\subsection{Acknowlegments}
    104104Many people have contributed to the development SOPHYA and/or the PI library
    105 and (s)piapp interactive analysis tool.
    106 we are grateful to the following people:
     105and (s)piapp interactive analysis tool, in particular:
    107106
    108107\begin{tabular}{lcl}
     
    159158\item[] {\bf SkyT/}
    160159classes for spectral emission and detector frequency response modelling \\
    161 ({\tt SpectralResponse, RadSpectra, BlackBody} \ldots)
     160({\tt SpectralResponse, RadSpectra, BlackBody} \ldots). This module needs extensive
     161checking and corrections.
    162162\item[] {\bf Samba/} Spherical harmonic analysis, noise generators \ldots
    163163\end{itemize}
     
    234234\item[] {\bf LUC} {\bf L}ittle {\bf U}niverse {\bf C}alculator is a module containing classes to
    235235perform basic computation related to the universe geometry (FRW metric).
    236 \item[] {\bf PMixer/} skymixer and related programs
     236\item[] {\bf PMixer/} skymixer and related programs. This module is {\bf obsolete}.
    237237\end{itemize}
    238238
     
    590590PPF format version (currently V3), the file endiannes {\tt (BIG-ENDIAN , LITTLE-ENDIAN)}
    591591and the file creation date and time. It should be noted that the present SOPHYA version
    592 (V=2.1) does not allow updating an existing PPF file.
     592(V=2.2) does not allow updating an existing PPF file.
    593593\item[\rond] A collection of tagged data items and data structuring tags.
    594594the PPF tags are one byte (8 bits) long and may be followed by a length information
     
    847847\end{itemize}
    848848 
    849  \subsection{Random numbers}
    850  \index{RandomGenerator}
     849 \subsection{Pseudo-random number generators}
     850 \index{Random numbers}
    851851\begin{figure}[hbt]
    852852\dclsbb{ AnyDataObj }{ RandomGeneratorInterface }
     
    855855\dclsbb{ RandomGeneratorInterface }{ FMTRandGen }
    856856\end{figure}
    857 %%   CHECK
    858 {\bf \large SECTION A METTRE A JOUR } \\
    859  The C-functions defined in the file BaseTools/srandgen.h can be used
    860  for generating sequence of random numbers with different PDF (probability
    861  distribution functions : flat, gaussian, poisson \ldots.
    862  However, we advise to use the {\bf RandomGenerator} class which provides
    863 can be used in multi-threaded programs. In this case, a different instance of
    864 the  RandomGenerator class should be created in each thread running in parallel.
    865 In addition, this class has a PPF handler which saves the complete state of the class and
    866 the underlying generatoir to the PPF stream. This can be used to generate very long sequence
    867 of random numbers, distributed over several runs.
    868 \begin{verbatim}
    869 sa_size_t N = 1000;
    870 Vector vf(2*N), vg(2*N);
    871 {
    872 // Instanciate the random generator
    873 RandomGenerator rg;
    874 // Generate some sequence of random numbers
    875 for(sa_size_t i=0; i<N; i++) {
    876   vf(i) = rg.Flat01();
    877   vg(i) = rg.Gaussian();
    878   }
    879 // Save the generator to file rg.ppf
     857The {\bf RandomGeneratorInterface } is a pure virtual class which
     858defines the interface for random number generator classes and implements the
     859generation algorithm for few probability distribution functions:
     860flat, Gaussian, Poisson, Exponential, 2D gaussian \ldots. The pure virtual method
     861{\tt Next() } should be implemented by inheriting  classes.
     862 \index{RandomGeneratorInterface}
     863
     864Several implementations using different pseud-random generators are provided by SOPHYA:
     865\begin{enumerate}
     866\item {\bf DR48RandGen} uses the well known {\tt drand48() }  pseudo-random
     867sequence generator. It implements also the possibility of initializing the generator state, as well saving and
     868restoring the generator state through the SOPHYA PPF mechanism. The  {\tt drand48() }  and thus
     869{\bf DR48RandGen} objects are not NOT thread safe. Different instances of {\bf DR48RandGen}  share
     870the same underlying 48 bit state.
     871\item {\bf ThSDR48RandGen} is a thread safe version of DR48RandGen. Using the constructor flag, in can
     872be instanciated to reproduce the non thread-safe behaviour of DR48RandGen.
     873Several instances of this class can be used in different threads without the risk of
     874corrupting the internal state of the drand48() generator. However, in multi-thread applications,
     875 there is no guarantee to obtain the same sequence of numbers in each thread. 
     876\index{ ThSDR48RandGen}
     877\item {\bf FMTRandGen } ids an implementation of RandomGeneratorInterface using
     878the SIMD-oriented Fast Mersenne Twister (SFMT). It uses the code developed by
     879Mutsuo Saito and Makoto Matsumoto from Hiroshima University. For more information on this
     880method, refer to \\
     881\href{http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html}
     882{ttp://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html} \\
     883The instances of FMTRandGen are thread safe, each instance having its own internal state
     884and produces an independent sequence of random numbers.
     885\index{FMTRandGen }
     886\end{enumerate}
     887
     888A number of c-like functions are defined in the file BaseTools/srandgen.h and can be used
     889to generate random sequences: \\
     890{\tt drand01() , drandpm1() ,  GaussianRand() , PoissonRand \ldots} \\
     891These functions use a global instance  of RandomGeneratorInterface class which can be
     892defined and accessed through the static methods:\\
     893\hspace*{5mm} { \tt RandomGeneratorInterface* RandomGeneratorInterface::GetGlobalRandGenP() } \\
     894\hspace*{5mm} { \tt void SetGlobalRandGenP(RandomGeneratorInterface* rgp) } \\
     895
     896In multi-threaded programs, an instance of ThSDR48RandGen or FMTRandGen
     897should be created in each thread running in parallel and needing to generate random sequences.
     898All the three classes discussed here implement the automatic initialization method defined
     899{\tt (AutoInit() ) } defined in the interface class and implement a number of other initialization
     900methods {\tt (SetSeed() )}.  SOPHYA provides also PPF handlers for these classes
     901which can be used to save the complete  state of the object and the underlying generator to PPF files.
     902The generator object state can be restored subsequently from the PPF file. This feature can be used
     903to generate very long sequence of random numbers, distributed over several runs.
     904The example below illustrates the use of the generator classes and state save/restore
     905through PPF files:
     906\begin{enumerate}
     907\item We create and use a {\bf ThSDR48RandGen} object in a first program. Its sate is saved
     908to the PPF file rg.ppf at some point in the program.
     909\begin{verbatim}
     910// ------ program A
     911// A.1- Create a thread safe generator based on drand48()
     912ThSDR48RandGen rg;
     913// A.2- Auto initilize its state (using the system time)
     914rg.AutoInit();
     915// A.3- compute and print a smal sequence of random numbers
     916int N = 10;
     917for(int i=0; i<N; i++)
     918  cout << " I=" << i << "  rand_flat01= " << rg.Flat01()
     919       << " rand.gaussian= " << rg.Gaussian() << endl;
     920// A.4- Save the generator state for subsequent use
    880921POutPersist po("rg.ppf");
    881 po << rg; 
    882 }
    883 // ....
    884 {
    885 // Create and read the generator from file rg.ppf
    886 RandomGenerator rg;
    887 PInPersist pi("rg.ppf");
    888 pi >> rg; 
    889 // Continue the generation sequence
    890 for(sa_size_t i=N; i<2*N; i++) {
    891   vf(i) = rg.Flat01();
    892   vg(i) = rg.Gaussian();
    893   }
    894 }
    895 \end{verbatim}
     922po << rg;
     923// A.5- compute and print a second sequence of random numbers
     924for(int i=0; i<N; i++)
     925  cout << "++ I=" << i+N << "  rand_flat01= " << rg.Flat01()
     926       << " rand.gaussian= " << rg.Gaussian() << endl;
     927\end{verbatim}
     928
     929\item The pseudo-random generator object state is restored in a second program from the previously created
     930PPF file, before being used :
     931 \begin{verbatim} 
     932// ------ program B
     933// B.1- Create and initialize the generator from the previously saved state
     934ThSDR48RandGen rgr;
     935PInPersist pin("rg.ppf");
     936pin >> rgr;
     937int N = 10;
     938// B.2- Compute and print a sequence of random number,
     939//      should be compared to the sequance A.5
     940for(int i=0; i<N; i++)
     941  cout << "-- I=" << i << "  rand_flat01= " << rgr.Flat01()
     942       << " rand.gaussian= " << rgr.Gaussian() << endl;
     943\end{verbatim}
     944\end{enumerate}
    896945
    897946%%%%%%%%%%%%
     
    11611210\end{verbatim}
    11621211
    1163 \subsection{Input, Output}
     1212
     1213\subsection{Persistence, IO}
    11641214Arrays can easily be saved to, or restored from files in different formats.
    11651215SOPHYA library can handle array I/O to ASCII formatted files, to PPF streams,
     
    13701420\noindent {\bf Shared data access :} It is possible to access a complex array
    13711421elements (real and imaginary parts) through the template functions defined
    1372 in {\tt arrctcast.h} and discussed above. The example below shows how to use
    1373 these functions.
     1422in {\tt arrctcast.h} and discussed above. Four specific template functions are
     1423defined for shared data access to complex arrays:
     1424\begin{itemize}
     1425\item {\bf SDRealPart } return a float/double TArray, when applied to an
     1426array with complex elements, corresponding the the {\bf real} part of the complex values.
     1427\item {\bf SDImagPart } return a float/double TArray, when applied to an
     1428array with complex elements, corresponding the the {\bf imaginary} part of the complex values.
     1429\item {\bf ArrCastC2R } return a float/double TArray, when applied to an
     1430array with complex elements. The data is shared between the two arrays, the real array
     1431containing real and imaginary parts as successive elements.
     1432\item {\bf ArrCastR2C } return a complex valued TArray, when applied to a float/double array.
     1433\end{itemize}
     1434The example below shows how to use these functions:
    13741435
    13751436\begin{verbatim}
     
    14971558\end{verbatim}
    14981559
     1560
     1561\subsection{Special Square Matrices (SSQM) }
     1562SOPHYA V2.2 introduces new classes for handling special square matrices (diagonal, symmetric, triangular \ldots).
     1563The figure below shows the corresponding class hierarchy:
     1564\begin{figure}[hbt]
     1565\dclsccc{AnyDataObj}{\tcls{SpecialSquareMatrix}}{ \tcls{ DiagonalMatrix } }
     1566\dclsc{ \tcls{ LowerTriangularMatrix } }
     1567\dclsc{ \tcls{ SymmetricMatrix } }
     1568\end{figure}
     1569
     1570\index{ \tcls{DiagonalMatrix} }
     1571\index{ \tcls{SymmetricMatrix} }
     1572\index{ \tcls{TriangularMatrix} }
     1573
     1574Theses classes provides methods similar to TArray/TMatrix objects for manipulating these special kind of matrices.
     1575However, no sub-matrix extraction method is provided. The  following features are currently implemented:
     1576\begin{itemize}
     1577\item These classes implements reference sharing and behave in a way similar to TArray objects. The copy
     1578constructor shares the data, while the equal operator (=) performs an element by element copy.
     1579\item The {\bf FIO\_SpecialSquareMatrix$<$T$>$ } manages the persistence (I/O) in PPF format for these classes.
     1580\item Constructor from and conversion to general {\bf TMatrix$<$T$>$ } objects.
     1581 Non relevant elements are ignored when constructing from a general matrix and the special square matrix can be
     1582converted to the general matrix through the {\tt ConvertToStdMatrix () }.
     1583\item Definition of element access operator {\tt mx(r,c) } as well as global assignment operator {\tt mx = a; mxb=mxa; }.
     1584operator {\tt mx[k] } can be used to access the non zero element k.
     1585\item Addition, subtraction of a constant, multiplication or division by a constant, as well as 
     1586\item Element by element addition, subtraction, multiplication and division methods between same type of SSQM
     1587matrices. As in the cases of general matrices, the four binary operators ( + , - , \&\& ,   /) are overloaded to perform
     1588these operations.
     1589\item Matrix multiplication operation between same type SSQM objects or between a general matrix and an SSQM
     1590object is defined through the methods: \\
     1591{\\ Multiply() , MultiplyXG(), MultiplyGX(),  X=D,S,T } \\
     1592The binary multiplication operator ( * ) is then overloaded to perform matrix multiplication.   
     1593\end{itemize}
     1594The sample code below illustrates the use of these special matrices:
     1595\begin{verbatim}
     1596// Create and initialize a diagonal matrix
     1597DiagonalMatrix<double> diag(3);
     1598diag(0,0)=1.;  diag(1,1)=2.;  diag(2,2)=3.;
     1599// use of multiplication by a constant operator
     1600diag *= 10.;
     1601// check the diagonal matrix
     1602cout << diag << diag.ConvertToStdMatrix() << endl;
     1603// define and initialize a general matrix
     1604TMatrix<double> mx(3,3);
     1605mx=RegularSequence();
     1606cout << mx;
     1607// check the result of a matrix mutiplication
     1608cout << mx*diag;
     1609\end{verbatim}
    14991610
    15001611\newpage
     
    24732584transforms on double precision data might be available.
    24742585
     2586\section{Multi-thread and parallel programming with Sophya}
     2587 
    24752588\newpage
    24762589\section{Building and installing Sophya}
    24772590\subsection{Supported platforms}
    2478 Presently, the Sophya library has been tested with the following
    2479 compiler/platform pairs:
     2591Presently, the SOPHYA and PI libraries and tools has been compiled and tested with
     2592the following compiler/platform pairs:
    24802593
    24812594\begin{center}
     
    24842597OS & compiler \\
    24852598\hline
    2486 Linux (32 bits)          &     g++  (3.x \, 4.0)  \\
    2487 Linux  (SCL, 32)          &     icc - Intel compiler (9.0)   \\
    2488 Linux  (SCL, 64)          &     g++  3.3 \, 3.4 \\
    2489 MacOSX/Darwin (PowerPC) 10.3 \, 10.4  &         g++ (3.3  \, 4.0)\\
    2490 MacOSX/Darwin (Intel) 10.4  &         g++ (4.0)\\
    2491 HP/Compaq/DEC Tru64 ( OSF1)  &     cxx  (6.1  6.3) \\
    2492 SGI IRIX64       &     CC   (7.3)   \\
    2493 IBM AIX (5.3)      &     xlC   (8.0)   \\
     2599Linux  (SL5, 64)          &     g++  4.1  \\
     2600Linux  (SL5, 64)          &     icc - Intel compiler (10.1)   \\
     2601Linux Ubuntu             &    g++ 4.4 \\
     2602MacOSX/Darwin 10.3 (PowerPC) \, 10.4  (Intel) &   Apple g++ 3.3  \, 4.0 \\
     2603MacOSX/Darwin 10.5 (Intel)  &  Apple   g++ 4.0 \\
     2604MacOSX/Darwin 10.6 (Intel)   Snow Leopard &  Apple  g++ 4.2 \\
     2605IBM AIX 5.3      &     xlC   8.0   \\
     2606HP/Compaq/DEC Tru64 ( OSF1)  &     cxx  6.1 \, 6.3  \\
    24942607\hline
    24952608\end{tabular}
    24962609\end{center}
     2610
     2611The SOPHYA and PI library and associated tools (spiapp, runcxx \ldots) were ported and tested
     2612on the Silicon Graphics (SGI)  IRIX system and the corresponding native c++ compiler ( IRIX64, CC  7.3 ),
     2613up to SOPHYA V2.1 (V\_Nov2007).
    24972614
    24982615\subsection{Library and makefile structure}
     
    25442661configure [-sbase SOPHYABASE] [-scxx SOPHYACXX] [-incln]
    25452662  [-minc mymake.inc]  [-compopt 'cc/cxxOptions']
    2546   [-arch64] [-sasz64] [-nofpic] [-nothsafe] [-boundcheck] [-sodebug]
     2663  [-arch64] [-arch32] [-sasz64] [-ldble128] [-nofpic] [-nothsafe] [-boundcheck] [-sodebug]
    25472664  [-extp dir1 -extp dir2 ...] [-extip dir1 -extip dir2 ... ] [-extlp dir1 -extlp dir2 ... ]
    25482665  [-noextlib] [-noext fits] [-noext fftw] [-noext lapack] [-noext astro]
     
    25602677\$SOPHYABASE/include/sophyamake.inc. If {\tt -minc} is not specified, one of
    25612678the files in BuildMgr/ directory is selected, based on the system name and the
    2562 compiler {\tt  Linux\_g++\_make.inc , OSF1\_cxx\_make.inc , AIX\_xlC\_make.inc \ldots}
     2679compiler {\tt  Linux\_g++\_make.inc , OSF1\_cxx\_make.inc , AIX\_xlC\_make.inc \ldots}
     2680\item[] -compopt : additional compiler options \\[2mm]
     2681\item[] -arch64 : select/force 64 bits compilation mode. This is the default on 64 bits Linux systems and AIX.
     2682\item[] -arch32  : select/force 32 bits compilation mode. useful on 64 bits Linux systems or AIX
     2683\item[] -sasz64 : select 8 byte (64 bits) size for array indices, useful if you need to allocate an manipulate
     2684large arrays, with more than $2^32$ elements along a single array dimension.
     2685\item[] -ldble128 : set the flags activating {\tt long double} (128 bits) arrays. \\[2mm]
     2686\item[] -nofpic : disable -fPIC (Position Independent Code) generation flag
     2687\item[] -nothsafe : disable thread-safety procedures in SOPHYA : reference sharing \ldots.
     2688 ( activate the conditional compilation flag {\tt SO\_NOTHSAFE } )
     2689\item[] -boundcheck : compile SOPHYA and bound checking activated when accessing array elements
     2690( activate conditional compilation flag {\tt SO\_BOUNDCHECKING } )
     2691\item[] -sodebug : activate conditional compilation flag {\tt SOPHYA\_DEBUG }  \\[2mm]
    25632692\item[] -extp : Adds the specied path to the search path of the external libraries
    25642693include files and archive library.
     
    25692698\item[] -noextlib : Disable compiling of modules referencing external libraries.
    25702699\item[] -noext : Disable compiling of the specified module (with reference to external
    2571 library : {\tt -noext fits , -noext fftw \ldots }
     2700library : {\tt -noext fits , -noext fftw  -noext lapack -noext astro } \\[2mm]
    25722701\item[] -usefftw2: Use FFTW V2 instead of the default FFTW V3 - A preprocessor
    25732702flag will be defined in sspvflags.h
     
    25882717The configure script performs the following actions :
    25892718\begin{enumerate}
    2590 \item Creating directory tree under {\tt \$SOPHYABASE }
    2591 \item Cpoying include files (or creating symbolic) in {\tt \$SOPHYABASE/include/ }
     2719\item Creates directory tree under {\tt \$SOPHYABASE }
     2720\item Copy include files to {\tt \$SOPHYABASE/include/ }  (or creates symbolic link)
    25922721\item Search for external libraries include files and create the necessary links
    25932722in {\tt \$SOPHYABASE/include}
     
    27242853\index{Exception classes} \index{PThrowable} \index{PError} \index{PException}
    27252854SOPHYA library defines a set of exceptions which are used
    2726 for signalling error conditions. The figure below shows a partial
    2727 class diagram for exception classes in SOPHYA.
     2855for signalling error conditions. From version V2.2 , all SOPHYA exceptions inherit from
     2856the standard C++ exception class ( {\bf std::std::exception}). The method {\tt const char* what()} is
     2857thus implemented and returns the corresponding error message.
     2858The figure below shows a partial class diagram for exception classes in SOPHYA.
    27282859\begin{figure}[hbt]
    27292860\dclsbb{PThrowable}{PError}
Note: See TracChangeset for help on using the changeset viewer.