Changeset 3839 in Sophya for trunk/SophyaLib/Manual/sophya.tex
- Timestamp:
- Aug 9, 2010, 7:32:00 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaLib/Manual/sophya.tex
r3723 r3839 48 48 \vspace{1cm} 49 49 \begin{center} 50 {\bf \Large Sophya Version: 2.2 (V\_ Jan2010) }50 {\bf \Large Sophya Version: 2.2 (V\_Sep2010) } 51 51 \end{center} 52 52 \titrebp{1} … … 103 103 \subsection{Acknowlegments} 104 104 Many 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: 105 and (s)piapp interactive analysis tool, in particular: 107 106 108 107 \begin{tabular}{lcl} … … 159 158 \item[] {\bf SkyT/} 160 159 classes for spectral emission and detector frequency response modelling \\ 161 ({\tt SpectralResponse, RadSpectra, BlackBody} \ldots) 160 ({\tt SpectralResponse, RadSpectra, BlackBody} \ldots). This module needs extensive 161 checking and corrections. 162 162 \item[] {\bf Samba/} Spherical harmonic analysis, noise generators \ldots 163 163 \end{itemize} … … 234 234 \item[] {\bf LUC} {\bf L}ittle {\bf U}niverse {\bf C}alculator is a module containing classes to 235 235 perform 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}. 237 237 \end{itemize} 238 238 … … 590 590 PPF format version (currently V3), the file endiannes {\tt (BIG-ENDIAN , LITTLE-ENDIAN)} 591 591 and 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. 593 593 \item[\rond] A collection of tagged data items and data structuring tags. 594 594 the PPF tags are one byte (8 bits) long and may be followed by a length information … … 847 847 \end{itemize} 848 848 849 \subsection{ Random numbers}850 \index{Random Generator}849 \subsection{Pseudo-random number generators} 850 \index{Random numbers} 851 851 \begin{figure}[hbt] 852 852 \dclsbb{ AnyDataObj }{ RandomGeneratorInterface } … … 855 855 \dclsbb{ RandomGeneratorInterface }{ FMTRandGen } 856 856 \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 857 The {\bf RandomGeneratorInterface } is a pure virtual class which 858 defines the interface for random number generator classes and implements the 859 generation algorithm for few probability distribution functions: 860 flat, Gaussian, Poisson, Exponential, 2D gaussian \ldots. The pure virtual method 861 {\tt Next() } should be implemented by inheriting classes. 862 \index{RandomGeneratorInterface} 863 864 Several 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 867 sequence generator. It implements also the possibility of initializing the generator state, as well saving and 868 restoring 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 870 the same underlying 48 bit state. 871 \item {\bf ThSDR48RandGen} is a thread safe version of DR48RandGen. Using the constructor flag, in can 872 be instanciated to reproduce the non thread-safe behaviour of DR48RandGen. 873 Several instances of this class can be used in different threads without the risk of 874 corrupting 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 878 the SIMD-oriented Fast Mersenne Twister (SFMT). It uses the code developed by 879 Mutsuo Saito and Makoto Matsumoto from Hiroshima University. For more information on this 880 method, 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} \\ 883 The instances of FMTRandGen are thread safe, each instance having its own internal state 884 and produces an independent sequence of random numbers. 885 \index{FMTRandGen } 886 \end{enumerate} 887 888 A number of c-like functions are defined in the file BaseTools/srandgen.h and can be used 889 to generate random sequences: \\ 890 {\tt drand01() , drandpm1() , GaussianRand() , PoissonRand \ldots} \\ 891 These functions use a global instance of RandomGeneratorInterface class which can be 892 defined and accessed through the static methods:\\ 893 \hspace*{5mm} { \tt RandomGeneratorInterface* RandomGeneratorInterface::GetGlobalRandGenP() } \\ 894 \hspace*{5mm} { \tt void SetGlobalRandGenP(RandomGeneratorInterface* rgp) } \\ 895 896 In multi-threaded programs, an instance of ThSDR48RandGen or FMTRandGen 897 should be created in each thread running in parallel and needing to generate random sequences. 898 All 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 900 methods {\tt (SetSeed() )}. SOPHYA provides also PPF handlers for these classes 901 which can be used to save the complete state of the object and the underlying generator to PPF files. 902 The generator object state can be restored subsequently from the PPF file. This feature can be used 903 to generate very long sequence of random numbers, distributed over several runs. 904 The example below illustrates the use of the generator classes and state save/restore 905 through PPF files: 906 \begin{enumerate} 907 \item We create and use a {\bf ThSDR48RandGen} object in a first program. Its sate is saved 908 to 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() 912 ThSDR48RandGen rg; 913 // A.2- Auto initilize its state (using the system time) 914 rg.AutoInit(); 915 // A.3- compute and print a smal sequence of random numbers 916 int N = 10; 917 for(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 880 921 POutPersist 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} 922 po << rg; 923 // A.5- compute and print a second sequence of random numbers 924 for(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 930 PPF file, before being used : 931 \begin{verbatim} 932 // ------ program B 933 // B.1- Create and initialize the generator from the previously saved state 934 ThSDR48RandGen rgr; 935 PInPersist pin("rg.ppf"); 936 pin >> rgr; 937 int N = 10; 938 // B.2- Compute and print a sequence of random number, 939 // should be compared to the sequance A.5 940 for(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} 896 945 897 946 %%%%%%%%%%%% … … 1161 1210 \end{verbatim} 1162 1211 1163 \subsection{Input, Output} 1212 1213 \subsection{Persistence, IO} 1164 1214 Arrays can easily be saved to, or restored from files in different formats. 1165 1215 SOPHYA library can handle array I/O to ASCII formatted files, to PPF streams, … … 1370 1420 \noindent {\bf Shared data access :} It is possible to access a complex array 1371 1421 elements (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. 1422 in {\tt arrctcast.h} and discussed above. Four specific template functions are 1423 defined for shared data access to complex arrays: 1424 \begin{itemize} 1425 \item {\bf SDRealPart } return a float/double TArray, when applied to an 1426 array 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 1428 array 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 1430 array with complex elements. The data is shared between the two arrays, the real array 1431 containing 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} 1434 The example below shows how to use these functions: 1374 1435 1375 1436 \begin{verbatim} … … 1497 1558 \end{verbatim} 1498 1559 1560 1561 \subsection{Special Square Matrices (SSQM) } 1562 SOPHYA V2.2 introduces new classes for handling special square matrices (diagonal, symmetric, triangular \ldots). 1563 The 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 1574 Theses classes provides methods similar to TArray/TMatrix objects for manipulating these special kind of matrices. 1575 However, 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 1578 constructor 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 1582 converted 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; }. 1584 operator {\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 1587 matrices. As in the cases of general matrices, the four binary operators ( + , - , \&\& , /) are overloaded to perform 1588 these operations. 1589 \item Matrix multiplication operation between same type SSQM objects or between a general matrix and an SSQM 1590 object is defined through the methods: \\ 1591 {\\ Multiply() , MultiplyXG(), MultiplyGX(), X=D,S,T } \\ 1592 The binary multiplication operator ( * ) is then overloaded to perform matrix multiplication. 1593 \end{itemize} 1594 The sample code below illustrates the use of these special matrices: 1595 \begin{verbatim} 1596 // Create and initialize a diagonal matrix 1597 DiagonalMatrix<double> diag(3); 1598 diag(0,0)=1.; diag(1,1)=2.; diag(2,2)=3.; 1599 // use of multiplication by a constant operator 1600 diag *= 10.; 1601 // check the diagonal matrix 1602 cout << diag << diag.ConvertToStdMatrix() << endl; 1603 // define and initialize a general matrix 1604 TMatrix<double> mx(3,3); 1605 mx=RegularSequence(); 1606 cout << mx; 1607 // check the result of a matrix mutiplication 1608 cout << mx*diag; 1609 \end{verbatim} 1499 1610 1500 1611 \newpage … … 2473 2584 transforms on double precision data might be available. 2474 2585 2586 \section{Multi-thread and parallel programming with Sophya} 2587 2475 2588 \newpage 2476 2589 \section{Building and installing Sophya} 2477 2590 \subsection{Supported platforms} 2478 Presently, the S ophya library has been tested with the following2479 compiler/platform pairs:2591 Presently, the SOPHYA and PI libraries and tools has been compiled and tested with 2592 the following compiler/platform pairs: 2480 2593 2481 2594 \begin{center} … … 2484 2597 OS & compiler \\ 2485 2598 \hline 2486 Linux (32 bits) & g++ (3.x \, 4.0)\\2487 Linux (S CL, 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)\\2599 Linux (SL5, 64) & g++ 4.1 \\ 2600 Linux (SL5, 64) & icc - Intel compiler (10.1) \\ 2601 Linux Ubuntu & g++ 4.4 \\ 2602 MacOSX/Darwin 10.3 (PowerPC) \, 10.4 (Intel) & Apple g++ 3.3 \, 4.0 \\ 2603 MacOSX/Darwin 10.5 (Intel) & Apple g++ 4.0 \\ 2604 MacOSX/Darwin 10.6 (Intel) Snow Leopard & Apple g++ 4.2 \\ 2605 IBM AIX 5.3 & xlC 8.0 \\ 2606 HP/Compaq/DEC Tru64 ( OSF1) & cxx 6.1 \, 6.3 \\ 2494 2607 \hline 2495 2608 \end{tabular} 2496 2609 \end{center} 2610 2611 The SOPHYA and PI library and associated tools (spiapp, runcxx \ldots) were ported and tested 2612 on the Silicon Graphics (SGI) IRIX system and the corresponding native c++ compiler ( IRIX64, CC 7.3 ), 2613 up to SOPHYA V2.1 (V\_Nov2007). 2497 2614 2498 2615 \subsection{Library and makefile structure} … … 2544 2661 configure [-sbase SOPHYABASE] [-scxx SOPHYACXX] [-incln] 2545 2662 [-minc mymake.inc] [-compopt 'cc/cxxOptions'] 2546 [-arch64] [- sasz64] [-nofpic] [-nothsafe] [-boundcheck] [-sodebug]2663 [-arch64] [-arch32] [-sasz64] [-ldble128] [-nofpic] [-nothsafe] [-boundcheck] [-sodebug] 2547 2664 [-extp dir1 -extp dir2 ...] [-extip dir1 -extip dir2 ... ] [-extlp dir1 -extlp dir2 ... ] 2548 2665 [-noextlib] [-noext fits] [-noext fftw] [-noext lapack] [-noext astro] … … 2560 2677 \$SOPHYABASE/include/sophyamake.inc. If {\tt -minc} is not specified, one of 2561 2678 the 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} 2679 compiler {\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 2684 large 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] 2563 2692 \item[] -extp : Adds the specied path to the search path of the external libraries 2564 2693 include files and archive library. … … 2569 2698 \item[] -noextlib : Disable compiling of modules referencing external libraries. 2570 2699 \item[] -noext : Disable compiling of the specified module (with reference to external 2571 library : {\tt -noext fits , -noext fftw \ldots }2700 library : {\tt -noext fits , -noext fftw -noext lapack -noext astro } \\[2mm] 2572 2701 \item[] -usefftw2: Use FFTW V2 instead of the default FFTW V3 - A preprocessor 2573 2702 flag will be defined in sspvflags.h … … 2588 2717 The configure script performs the following actions : 2589 2718 \begin{enumerate} 2590 \item Creat ingdirectory tree under {\tt \$SOPHYABASE }2591 \item C poying 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) 2592 2721 \item Search for external libraries include files and create the necessary links 2593 2722 in {\tt \$SOPHYABASE/include} … … 2724 2853 \index{Exception classes} \index{PThrowable} \index{PError} \index{PException} 2725 2854 SOPHYA 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. 2855 for signalling error conditions. From version V2.2 , all SOPHYA exceptions inherit from 2856 the standard C++ exception class ( {\bf std::std::exception}). The method {\tt const char* what()} is 2857 thus implemented and returns the corresponding error message. 2858 The figure below shows a partial class diagram for exception classes in SOPHYA. 2728 2859 \begin{figure}[hbt] 2729 2860 \dclsbb{PThrowable}{PError}
Note:
See TracChangeset
for help on using the changeset viewer.