Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
improve the documentation with regard to the compilation of SimGrid java (finding...
[simgrid.git] / doc / install.doc
1 /*! \page install Java Binding
2
3 \section bindings_binding_java_install How to install Simgrid-java
4
5 To use java with Simgrid you have to install some dependencies:
6  \li Simgrid (see <a href="http://simgrid.gforge.inria.fr/simgrid/latest/doc/install.html">install
7      Simgrid</a>). You should set the SIMGRID_ROOT environment
8      variable to the path where you installed SimGrid.
9  \li Java JDK packages, such as openjdk7 or sun-java6-jdk (with
10      libgcj10-dev or another version of gcj). For maximal performance
11      and scalability, use a coroutine-enabled JVM (see
12      \ref bindings_binding_java_coroutines).
13  
14 Then Download and install package Simgrid-java:
15 \verbatim
16 git clone git://scm.gforge.inria.fr/simgrid/simgrid-java.git
17 cd simgrid-java
18 cmake -DCMAKE_INSTALL_PREFIX=$HOME/Install/simgrid-java/ .
19 make install
20 \endverbatim
21  
22 Cmake output
23 \verbatim
24 -- SITE        : Linux_2.6.38-8-generic_x86_64
25 -- BUILDNAME   : Simgrid-Java
26 -- Looking for lib SimGrid
27 -- Looking for lib SimGrid - found
28 -- Simgrid version : 3.8.1
29 -- Looking for gras.h
30 -- Looking for gras.h - found
31 -- Found Tesh: /home/user/Bureau/simgrid/git/bin/tesh
32 -- Found gras_stub_generator: /home/user/Bureau/simgrid/git/bin/gras_stub_generator
33 -- Java version 1.6.0.22 configured successfully!
34 -- Looking for jni.h
35 -- Looking for jni.h - found
36 -- Add flags -I/usr/lib/jvm/java-6-openjdk/include
37 -- Looking for jni_md.h
38 -- Looking for jni_md.h - found
39 -- Found javac: /usr/bin/javac
40 -- Found jar: /usr/bin/jar
41 -- Configuring done
42 -- Generating done
43 -- Build files have been written to: /home/user/workspace/simgrid-java/build
44 \endverbatim
45
46 If cmake complains that jni could not be found, you need to tell it
47 where JNI header files are located. the following command should tell
48 you:
49
50 \verbatim
51 $ locate jni.h
52 /usr/lib/jvm/java-6-openjdk-amd64/include/jni.h
53 /usr/lib/jvm/java-7-openjdk-amd64/include/jni.h
54 \endverbatim
55
56 If you have several version of jni installed (as in the example
57 above), you need to check the version of java that is used by default
58 on your machine (using javac -version), and pick the right one. Then
59 set the JAVA_INCLUDE_PATH environment variable to the right path (note
60 that we remove the filename jni.h from that path), and relaunch cmake.
61
62 \vebatim
63 export JAVA_INCLUDE_PATH=/usr/lib/jvm/java-6-openjdk-amd64/include/
64 \endverbatim
65
66 \section bindings_binding_java_use How to use Simgrid-java
67
68 To execute the examples you need to add the path where you installed
69 the generated libSG_java library (<build_dir>/lib) and libsimgrid
70 ($SIMGRID_ROOT/lib) into the LD_LIBRARY_PATH.
71
72 Be careful on Mac, this variable is called DYLD_LIBRARY_PATH and not
73 LD_LIBRARY_PATH.
74
75 \verbatim
76 $ export SIMGRID_ROOT="$HOME/Install/simgrid/" # change it to the path where you installed the SimGrid library
77 $ export SIMGRID_JAVA_ROOT="$HOME/Install/simgrid-java" # change it to the path where you installed the java bindings of SimGrid 
78 $ export LD_LIBRARY_PATH=${LD_LIBRARY_PATH:+$LD_LIBRARY_PATH:}$SIMGRID_ROOT/lib:$SIMGRID_JAVA_ROOT/java
79 $ cd examples
80 $ java -cp .:../simgrid.jar basic/BasicTest platform.xml basic/basicDeployment.xml
81 \endverbatim
82
83 If you want to make these settings permanent even after a reboot, you
84 need to add the export lines into your ~/.bashrc file, or equivalent.
85
86
87
88
89 \section bindings_binding_java_coroutines How to use the coroutines context factory
90
91 There is two main motivations to use the coroutine variant of SimGrid
92 Java bindings: it's about 5 times faster than the default thread-based
93 context factory, and the amount of runnable processes is then only
94 limited by the amount of RAM that you have. The drawbacks are that it
95 requires a specific and rather experimental JVM to run, and that this
96 context factory itself remains a bit experimental so far.
97
98 \subsection  bindings_java_coro_install Getting a mlvm JVM
99
100 You need to get a patched JVM from <a href="http://ssw.jku.at/General/Staff/LS/coro/">here</a>
101 (many thanks to Lukas Stadler for this work!). 
102
103 You can either get a prebuilt binary, or recompile your own JVM. Make
104 sure to get a coro-simple version, as we don't need to serialize nor
105 migrate stacks in SimGrid. You should be able to follow the README.txt
106 that you'll get in the repository, but here is how we did it, just in
107 case. The instructions are given for a debian or Ubuntu box, but I
108 think you should manage to convert it to your system quite easily.
109 Finally, if you're really stuck, you can get the version compiled by
110 Jonathan Rouzaud-Cornabas from his web page. This version is known to
111 work with SimGrid for sure!
112 http://graal.ens-lyon.fr/~jrouzaud/files/corosimple-linux-amd64-20120914.tgz
113  
114  -# Install mercurial and some dependencies
115 \verbatim 
116 sudo apt-get install mercurial ksh libfreetype6-dev libcups2-dev libasound2-dev gawk openjdk-7-jdk libxext-dev libxrender-dev libxtst-dev
117 # Grab the forest extension: we need to source-install it
118 hg clone https://bitbucket.org/gxti/hgforest hgforest \endverbatim
119 \endverbatim
120  -# Configure the mercurial extensions: Edit ~/.hgrc and paste the
121     following lines. Don't forget to change the /path/to/forest.py to
122     point to where you just downloaded the source. 
123     
124     Forest extension is needed to download the openjdk source code and
125     patches while the mq line is needed to apply the patches. The
126     username is needed at the step "preparing the sources", not sure why.
127 \verbatim
128 [ui]
129 username = YouUserameWithoutSpaces
130 [extensions]
131 forest=/path/to/forest.py
132 mq=
133 \endverbatim
134  -# Prepare the source code
135 \verbatim 
136 # create a working directory, and enter it
137 mkdir davinci; cd davinci
138
139 # Grab the sources
140 hg fclone http://hg.openjdk.java.net/hsx/hotspot-comp sources
141 # Grab the patches
142 hg fclone http://hg.openjdk.java.net/mlvm/mlvm patches
143
144 # Link the patch directories into the sources
145 bash patches/make/link-patch-dirs.sh sources patches
146 # Test wether the previous command worked with
147 ls -i patches/hotspot/series sources/hotspot/.hg/patches/series
148 # It should display something like the following.
149 # (note that both file share the same inode number)
150 #  9707849 patches/hotspot/series  
151 #  9707849 sources/hotspot/.hg/patches/series
152
153
154 # Specify what to compile. 
155 export davinci=$(pwd) guards="buildable testable coro-simple"
156 # Apply the patches
157 sh patches/make/each-patch-repo.sh hg qselect --reapply $guards '$(sh $davinci/patches/make/current-release.sh)'
158 # Check that it understood that you want the patch applied:
159 grep GLOBAL_GUARDS patches/make/* -r
160 # this should display something like the following (maybe amonst other unrelated lines)
161 # GLOBAL_GUARDS=buildable testable coro-simple
162 # If this does not work, edit patches/make/Makefile,
163 #   manually coro-simple to GLOBAL_GUARDS and then 
164 #   rerun the patches/make/each-patch-repo.sh script as earlier
165
166
167 # Finish the setup
168 (cd patches/make; make setup && make force && make && make FORCE_VERSIONS=1 && echo "Sources are properly setup")
169 # If this last command failed, check your mercurial config within ~/.hgrc (see above)
170 \endverbatim           
171  -# Compile it all
172 \verbatim
173 unset LD_LIBRARY_PATH
174 export ALT_BOOTDIR=/usr/lib/jvm/java-7-openjdk-amd64/
175 cd sources
176 # Check that everything is fine
177 make sanity
178 # Go for it (it takes about half an hour on my machine)
179 make all
180
181 # Check that the coroutine library got compiled in
182 ls sources/build/linux-amd64/classes/java/dyn/
183 # This should display a bunch of class files. If not, something went wrong, you need to investigate further
184 \endverbatim
185
186 \subsection  bindings_java_coro_use Using coroutine contexts
187
188 SimGrid Java will automatically switch to the coroutine context
189 factory if your JVM support it, so you will just need to execute your
190 simulation with the correct JVM. The selected context factory gets
191 displayed automatically.
192 \verbatim
193 export LD_LIBRARY_PATH=/path/to/simgrid.so:/path/to/libSG_java.so
194 cd examples
195 $PATH_TO_COROUTINE_JVM/java -cp .:../simgrid.jar masterslave.Masterslave masterslave/ masterslaveDeployment.xml platform.xml
196 \endverbatim
197
198 Note that you may have to adjust the "coro.stacksPerThread"
199 configuration option to run large simulations. The default is 100 and
200 you want to increase it to run more processes.
201 \verbatim
202 $ $PATH_TO_COROUTINE_JVM/java -Dcoro.stacksPerThread=$STACKS_NUMBER -cp .:../simgrid.jar basic/BasicTest platform.xml basic/basicDeployment.xml
203 \endverbatim
204
205 If you reach the point where the creation of new simulated processes
206 fail with the message "Can't create coroutine object", you may need to
207 increase the relevant system limit with the following command.
208 \verbatim 
209 sysctl -w vm.max_map_count = 131072
210 \endverbatim
211
212 The full story is that each coroutine requires two memory maps, and
213 that Linux puts a limit on the total amount of memory maps that each
214 process can manage (by default, this limit is often at 65535). Since
215 the JVM needs a few dozen of such maps on its own (three maps per
216 dynamic library -- check /proc/the_pid/maps if you don't believe it),
217 this is enough to create over 30,000 simulated processes. But to go
218 futher, that limit must be modified. 
219
220 If you want to make this change permanent on your machine, edit your
221 /etc/sysctl.conf file. Otherwise, you have to redo it by calling
222 sysctl after each reboot.
223
224  */