Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 154 lines (110 sloc) 6.555 kB
c6eedb9 @bjpop Updated to hakyll 3 and added notes and notes about sprng
authored
1 ---
2 title: Building the SPRNG library
3 ---
4
5 ## Background
6
7 [SPRNG (Scalable Parallel Pseudo Random Number Generators Library)](http://sprng.cs.fsu.edu/) is
8 a library of pseudo random number generators, provided by the Department of Computer Science and the School of Computational Science at Florida State University.
9
10 At the time of writing this document (March 2011), the latest version of SPRNG is 4, which was released in
11 July 2007. The source is a mixture of C++ and Fortran, and can be compiled with or without MPI.
12 The SPRNG website suggests that you can build the code like so:
13
14 tar xvf sprng4.tar
15 ./configure
16 make
17
18 but this did not work for me on OS X Snow Leopard (10.6.7) using recent versions of GCC (>= 4.3).
19
20 In this note below I describe the steps I took to build the (non-MPI) version of the code on my mac. I expect
21 similar steps will apply to other unix environments such as Linux.
22
23 ## Instructions
24
e5b3ab8 @bjpop Added more detail to sprng note. Fixed up the patch file.
authored
25 1. Install gcc 4.4. This will provide C (gcc), C++ (g++) and Fortran (gfortran) compilers.
26 Xcode does not ship with Fortran.On OS X you can install it from macports like so:
c6eedb9 @bjpop Updated to hakyll 3 and added notes and notes about sprng
authored
27
e5b3ab8 @bjpop Added more detail to sprng note. Fixed up the patch file.
authored
28 sudo port install gcc44
c6eedb9 @bjpop Updated to hakyll 3 and added notes and notes about sprng
authored
29
e5b3ab8 @bjpop Added more detail to sprng note. Fixed up the patch file.
authored
30 Normally this will put the compilers in:
c6eedb9 @bjpop Updated to hakyll 3 and added notes and notes about sprng
authored
31
e5b3ab8 @bjpop Added more detail to sprng note. Fixed up the patch file.
authored
32 /opt/local/bin/gcc-mp-4.4
33 /opt/local/bin/g++-mp-4.4
34 /opt/local/bin/gfortran-mp-4.4
c6eedb9 @bjpop Updated to hakyll 3 and added notes and notes about sprng
authored
35
36 2. Untar the SPRNG source, and move to the top-level of the untarred directory:
37
38 tar xvf sprng4.tar
39 cd sprng4
40
41 3. Apply [this patch file](/files/sprng.patch.txt) to the source code:
42
43 patch -p1 < sprng.patch.txt
44
e5b3ab8 @bjpop Added more detail to sprng note. Fixed up the patch file.
authored
45 The patch fixes the following problems:
46
47 - deprecated header includes of `<iostream.h>` and `<iomanip.h>`, which should
48 be `<iostream>` and `<iomanip>`.
49 - addition of `using namespace std;` where needed.
50 - inclusion of `<cstdlib>` and `<cstring>` where needed.
51 - fix of `#ifdef SYNC ... #elsif !SYNC` which causes trouble for gcc >= 4.4.
c6eedb9 @bjpop Updated to hakyll 3 and added notes and notes about sprng
authored
52
53 If the patch works correctly you should see this output after running the above command:
54
55 patching file SRC/bignum.cpp
56 patching file SRC/bignum.h
57 patching file SRC/cmrg/cmrg.cpp
58 patching file SRC/fwrap.cpp
59 patching file SRC/fwrap.cpp~
60 patching file SRC/lcg/lcg.cpp
61 patching file SRC/lcg64/lcg64.cpp
62 patching file SRC/lfg/lfg.cpp
63 patching file SRC/mlfg/mlfg.cpp
64 patching file SRC/pmlcg/bignum.h
65 patching file SRC/pmlcg/pmlcg.cpp
66 patching file SRC/pmlcg/pmlcg.cpp~
67 patching file SRC/sprng_cpp.cpp
e5b3ab8 @bjpop Added more detail to sprng note. Fixed up the patch file.
authored
68 patching file TESTS/chisquare.cpp
69 patching file TESTS/coupon.cpp
70 patching file TESTS/metropolis.cpp
71 patching file TESTS/mpitests/coupon.cpp
72 patching file EXAMPLES/mpisprng/message_mpi.cpp
73 patching file EXAMPLES/mpisprng/seed_mpi.cpp
74 patching file EXAMPLES/mpisprng/sprng_mpi.cpp
75 patching file EXAMPLES/pi-simple.cpp
76 patching file EXAMPLES/spawn.cpp
77 patching file include/bignum.h
78 patching file include/bignum.h.copy
c6eedb9 @bjpop Updated to hakyll 3 and added notes and notes about sprng
authored
79
80 4. Configure the code:
81
82 ./configure FFLAGS=-fsecond-underscore \
e5b3ab8 @bjpop Added more detail to sprng note. Fixed up the patch file.
authored
83 CXX=/opt/local/bin/g++-mp-4.4 \
84 F77=/opt/local/bin/gfortran-mp-4.4 \
85 MPICXX=/opt/local/bin/g++-mp-4.4 \
86 MPIF77=/opt/local/bin/gfortran-mp-4.4
c6eedb9 @bjpop Updated to hakyll 3 and added notes and notes about sprng
authored
87
e5b3ab8 @bjpop Added more detail to sprng note. Fixed up the patch file.
authored
88 The `-fsecond-underscore` tells the `gfortran` compiler to add an extra underscore at the end of symbols as part of its name mangling scheme. The code doesn't seem to link properly without this option. Note that we set both `CXX` and `F77` to point to the same things as `MPICXX` and `MPIF77` repsectively. This is a little hack to convince the build system not to try to build the MPI version of the library. See the MPI notes below about why this is done.
c6eedb9 @bjpop Updated to hakyll 3 and added notes and notes about sprng
authored
89
90 I think the default is to try to install to `/usr/local/`. This is probably a bad place on OS X, and you should think about putting it somewhere else. To pick another location, use the `--prefix=` option to `./configure`. For example, amend the previous `./configure` line to be something like:
91
92 ./configure --prefix=/my/install/path/ ...
93
94 5. Build and install the code:
95
96 make
97 make install
e5b3ab8 @bjpop Added more detail to sprng note. Fixed up the patch file.
authored
98
99 ## Remaining problems
100
101 Here are some problems which remain unsolved:
102
103 1. The SPRNG site suggests that you can time the various random number generators by running the command:
104
105 check/timesprng
106
107 When I do this for versions built with gcc 4.3, it crashes with:
108
109 pmlcg: Timing FORTRAN interface:
110 terminate called after throwing an instance of 'std::bad_alloc'
111 what(): std::bad_alloc
112 ./timesprng: line 36: 98557 Abort trap ././pmlcg/time.fpmlcg
113
114 The same problem does not appear to happen when SPRNG is built with gcc 4.4.
115
116 2. SPRNG comes with some support for distributed parallel programming using the MPI interface.
117 By default the build system for SPRNG will try to compile the MPI version, but on my machine
118 the build fails like so:
119
120 Undefined symbols:
121 "std::ctype<char>::_M_widen_init() const", referenced from:
122 mult_48_32(int*, int*, int*)in libsprng.a(libsprng_a-lcg.o)
123 operator<<(std::basic_ostream<char, std::char_traits<char> >&, BigNum const&)in libsprng.a(libsprng_a-bignum.o)
124 operator<<(std::basic_ostream<char, std::char_traits<char> >&, BigNum const&)in libsprng.a(libsprng_a-bignum.o)
125
126 This appears to be a bug in g++ 4.4 regarding inlining of `std::endl`. Problem does not
127 appear to be present in gcc 4.3. However, if you build with gcc 4.3 then you get the bug mentioned above
128 and the MPI build fails at a later stage when building the test cases.
129
130 In the end I decided I don't really need the MPI support, so I didn't bother investigating further.
131
132 Note: there didn't seem to be an obvious way to stop the default build of SPRNG from
133 using MPI. Looking at `configure.ac` we see this test:
134
135 AC_CHECK_PROGS(MPICXX, mpic++ mpicxx mpiCC hcp mpxlC_r mpxlC mpCC cmpic++, $CXX)
136 AC_CHECK_PROGS(MPIF77, mpif77 hf77 mpxlf_r mpxlf mpf77 cmpifc, $F77)
137
138 if test $CXX != $MPICXX; then--
139 can_use_mpi=y
140 else
141 can_use_mpi=n
142 fi
143
144 AM_CONDITIONAL(USE_MPI, test $can_use_mpi = y)
145
146 if test $can_use_mpi = y; then
147 MPI_DEF="-DSPRNG_MPI"
148 else
149 MPI_DEF=""
150 fi
151
152 So we can see that by setting `$CXX` to equal `$MPICXX` we will cause the MPI version to not be built.
153 This explains my `./configure` line above which sets them both to `/opt/local/bin/g++-mp-4.4`.
Something went wrong with that request. Please try again.