F21DP FAQ
This page discusses frequently asked questions in the context of the course on Distributed and Parallel Technologies.
How do I compile (sequential) C programs?
See the slides on C Revision Part I
How do I use the gdb debugger on (sequential) C programs?
See the slides on C Revision Part I and the GDB quick reference card.
How do I get a picture of the hardware architecture (including information om cores, caches etc)?
You need to download the hwloc package from the hwloc web page (it is part of the OpenMPI project, but this tool is independent of OpenMPI implementation). It provides a command lstopo, eg:
lstopo --of png > topo.png
How do I get memory latency information on a NUMA multi-core machine?
The following command should be available on any Linux-based multi-core server:
numactl -H
How do I get started with MPI?
Use one of the hello-world examples, and go through the steps listed below. See the rest of the page for explanations on these steps.
> wget http://www.macs.hw.ac.uk/~hwloidl/Courses/F21DP/srcs/hello2.c > mpicc -Wall -O -o hello2 hello2.c > mpiexec -n 4 hello2
You should see something like this as output:
Hello, I am 0 of 4 (hostname is bwlf01) Hello, I am 1 of 4 (hostname is bwlf01) Hello, I am 3 of 4 (hostname is bwlf01) Hello, I am 2 of 4 (hostname is bwlf01)
Read on to learn how to configure MPI to use several hosts. Note that each host is an 8-core machine, so you can run parallel programs with up to 8 tasks and obtain speedups in this local configuration already.
How do I configure MPI?
Check the slides of Lecture 4. In short
- Use the machines in our Beowulf cluster: bwlf01 up to bwlf31
- You must have /usr/lib64/mpich/bin in your PATH
- Compile (mpicc) and run (mpiexec) as shown in the previous question, but additionally add -f hostfile, where hostfile lists all machines to be included in the configuration.
E.g:
> wget http://www.macs.hw.ac.uk/~hwloidl/Courses/F21DP/srcs/hello2.c > wget http://www.macs.hw.ac.uk/~hwloidl/Courses/F21DP/srcs/mpi4 > mpicc -Wall -O -o hello2 hello2.c > mpiexec -n 4 -f mpi4 hello2
You should see something like this as output:
Hello, I am 0 of 4 (hostname is bwlf01) Hello, I am 3 of 4 (hostname is bwlf04) Hello, I am 1 of 4 (hostname is bwlf02) Hello, I am 2 of 4 (hostname is bwlf03)
How do I compile C + MPI programs?
Check the slides of Lecture 4. In short, if your program is in file.c, type mpicc -Wall -O -o file file.c.
If you get an mpicc: command not found error, add the directory with mpich-3 programs to your path:
export PATH=$PATH:/usr/lib64/mpich/bin
How do I run C + MPI programs?
Check the slides of Lecture 4. In short, if your executable is file and you have configured MPI (see above), type mpiexec -n 4 file to run the program on 4 machines.
See mpiexec -h for help.
Why can't I run hello2 as above?
If you get an error message like this
> mpiexec -n 4 -f mpi4 hello2 [proxy:0:0@bwlf01] HYDU_create_process (utils/launch/launch.c:75): execvp error on file hello2 (No such file or directory)it means that the system can't find the executable hello2 because you don't have the the current directory in your path. (This is not an MPI issue: If you have a sequential C program hello.c and try to compile like this gcc -o h hello.c and run like this h, you'll get a similar error; you need to run like this instead: ./h).
To fix this, add the current directory to your path like this:
> export PATH=$PATH:.A good place for these shell commands is your .bashrc file (see this section of the Linux Introduction).
How do I launch an MPI configuration with several hosts?
Assuming that the file ${HOME}/etc/mpi4 contains a list of all hostnames, just type
mpiexec -n 4 -f ${HOME}/etc/mpi4 file
For more detailed documentation see Using the Hydra Process Manager, which describes the process manager underlying the mpich-3.1 installation that we use.
Or, as a complete example, go into an empty directory and to this:
wget http://www.macs.hw.ac.uk/~hwloidl/Courses/F21DP/srcs/hello2.c wget http://www.macs.hw.ac.uk/~hwloidl/Courses/F21DP/srcs/mpi4 mpicc -Wall -O -o hello2 hello2.c mpiexec -n 4 -f mpi4 hello2
As a result you should see this output:
Hello, I am 0 of 4 (hostname is bwlf01) Hello, I am 2 of 4 (hostname is bwlf03) Hello, I am 1 of 4 (hostname is bwlf02) Hello, I am 3 of 4 (hostname is bwlf04)
How do I get rid of the password prompt when launching my MPI configuration?
You have to set up a password-less ssh login to do so. There are many good web pages discussing this, for example here or here. In short, generate a password-less ssh key using
> ssh-keygen(accept the defaults for the filenames and just type return for the password) and then do is:
> ssh-copy-id `whoami`@bwlf01.macs.hw.ac.uk(this will ask you for your user password to put the public key onto the other machine). Now, you should be able to log in without using a password:
> ssh `whoami`@bwlf01.macs.hw.ac.uk
How do I run a shell command on all cluster nodes?
Set the environment variable BEONODES and then call /home/hwloidl/bin/beotools/brsh, eg:
bwlf01[102](3.2)> export BEONODES="bwlf01 bwlf02 bwlf03 bwlf05" bwlf01[103](3.2)> echo $BEONODES bwlf01 bwlf02 bwlf03 bwlf05 bwlf01[104](3.2)> which brsh /home/hwloidl/bin/beotools/brsh bwlf01[105](3.2)> brsh w | fgrep "average" bwlf01 21:05:37 up 13 days, 16:18, 5 users, load average: 0.03, 0.01, 0.00 bwlf02 21:05:37 up 13 days, 16:27, 0 users, load average: 1.43, 2.16, 2.32 bwlf03 21:05:39 up 13 days, 15:16, 0 users, load average: 1.09, 1.96, 2.15 bwlf05 21:05:41 up 10 days, 17:57, 0 users, load average: 0.68, 1.75, 2.29
Alternatively, if you can't access brsh, run this loop, which should give you the same kind of output:
for i in `cat ~hwloidl/etc/mpi32` ; do echo "$i `ssh $i w | fgrep average`" ; doneThe file mpi32 contains a list of all machines in the cluster and can be downloaded here (mpi32)
How do I check whether all cluster nodes are up?
Use bping to contact all machines listed in the BEONODES variable.
How do I get a list of all cluster nodes that are currently up?
echo -n > bwlfLive for host in `cat ~hwloidl/etc/mpi32`; do ping -q -c 1 -w 1 $host && echo $host >> bwlfLive done
How do I get a list of cluster nodes with a load of, say, less than 1?
for i in `cat ~hwloidl/etc/mpi32` ; do if [ `ssh $i w | sed -ne '/average/!d;s/^.*average: \([0-9]*\).*$/\1/;p' ` -lt 1 ] ; then echo $i ; fi ; doneThe file mpi32 contains a list of all machines in the cluster and can be downloaded here (mpi32)
How do I generate speedup graphs and such?
A simple tool for producing speedup graphs, histograms and such is Gnuplot (see also this quick reference card). It is a command-line based tool. Typically, you feed it a file, that contains x and y values on each line, eg. It then produces a graph, either interactively in a window or in a file, which you can then import in your report.
You can automate the generation of this data file, using Unix command such as sed to extract the relevant data from a log of several executions. For example, if you run tests on 2 to 8 processors like this
for ((i=2; i<9; i++)) ; do echo "mpiexec -n $i matrix8 2MAT_2000_10_65536" >>LOG ; mpiexec -n $i matrix8 2MAT_2000_10_65536 >> LOG ; doneyou can use the following commands to extract the relevant data and show a graph of runtimes:
cat LOG | sed -e '/secs/a\X' | sed -e 's/^.*np \([0-9]*\).*$/\1/;s/^.* \([.0-9]*\) secs.*$/\1/' | sed ':a;N;$!ba;s/\n/ /g' | sed 's/X/\n/g' >rt.dat echo "set term x11; plot \"rt.dat\" with lines; pause 10 " | gnuplot
This will show a graph of runtimes over varying numbers of processors in a new window. More commonly, you put all gnuplot commands in a file (eg. speedups.gp) and feed it to gnuplot
gnuplot speedups.gp
This will generate a file speedups.pdf, which you can include in your report discussing the parallelisation.
Can you repeat the matrix8.c tutorial for measuring and displaying parallel performance?
Below are the commands I used in class to demonstrate the parallel matrix multiplication (version matrix8.c):
Download and setup:
# download the sequential as baseline for comparison > wget -q http://www.macs.hw.ac.uk/~hwloidl/Courses/F21DP/srcs/matrix3.c # download input data > wget -q http://www.macs.hw.ac.uk/~hwloidl/Courses/F21DP/srcs/2MAT_2000_10_65536 # compile sequential version (with optimisation!) > gcc -Wall -O -o matrix3 matrix3.c # run sequential version > ./matrix3 2MAT_2000_10_65536 2000 * 2000; SEQUENTIAL; 12.240000 secs # download parallel version > wget -q http://www.macs.hw.ac.uk/~hwloidl/Courses/F21DP/srcs/matrix8.c # compile parallel version > mpicc -Wall -O -o matrix8 matrix8.c
Sequential and individual parallel runs:
# sequential run > ./matrix3 2MAT_2000_10_65536 2000 * 2000; SEQUENTIAL; 12.240000 secs # now you can run the parallel MPI program, using 1 worker and 1 master > mpiexec -n 2 matrix8 2MAT_2000_10_65536 2000 * 2000; 2 processors; 12.554089 secs # run it on 2 workers > mpiexec -n 3 matrix8 2MAT_2000_10_65536 2000 * 2000; 3 processors; 6.468304 secs # NB: speedup of almost 2, good! # run it on 4 workers > mpiexec -n 5 matrix8 2MAT_2000_10_65536 2000 * 2000; 5 processors; 3.260149 secs
Batch job of executions on 1 to 16 workers (put this into a shell script!):
> echo "Workers 1">LOG ; ./matrix3 2MAT_2000_10_65536 >> LOG ; for ((i=1;i<17;i++)) ; do w=$[ 2*i ] ; p=$[ $w + 1 ] ; echo "PEs $p" >>LOG; echo "Workers $w" >> LOG ; mpiexec -n $p matrix8 2MAT_2000_10_65536 >> LOG ; done > cat LOG | sed -e '/secs/a\X' | sed -e 's/^.*np \([0-9]*\).*$/\1/;/PEs/d;s/^.*Workers \([0-9]*\).*$/\1/;s/^.* \([.0-9]*\) secs.*$/\1/' | sed ':a;N;$!ba;s/\n/ /g' | sed 's/X/\n/g' >rt.dat > echo "set term x11; plot \"rt.dat\" with lines; pause 10 " | gnuplot
How do I access the Robotarium cluster?
Follow this link to How Tos about the Robotarium cluster.
How do I run parallel Haskell programs on the Robotarium cluster?
You should find a current version of ghc in your path, that can be used to compile parallel Haskell programs. If you use evaluation strategies, you may need to install the parallel package using cabal, and then compile with the usual options. For example:
# check that ghc is available > ghc --version # try things in a separate directory > cd tmp # get one of the parallel Haskell sample programs from the course > wget http://www.macs.hw.ac.uk/~hwloidl/Courses/F21DP/srcs/parsum.hs # initialise cabal > cabal update # install the package with evaluation strategies > cabal install parallel # now, compile for parallel execution > ghc -rtsopts -threaded -O2 parsum.hs # and run the program on 12 cores > ./parsum 900M 100 +RTS -N12 -sstderr
How can I profile OpenMP programs?
The necessary steps are discussed in more detail on the OpenMP Lab pages.
How can I profile OpenMP programs?
A slightly dated, but detailed, OpenMP profiler is OmpP. It can be downloaded here and documentation is here. In short, to profile an OpenMP program in file c_simple.c, do
export PATH=/u1/staff/dsg/OPT/x86_64-unknown-linux/bin:$PATH kinst-ompp gcc -fopenmp -o c c_simple.c ./c less c.4-1.ompp.txt
How do I get started with Haskell?
A good way to get started with Haskell, is to use the web-based IDE at the School of Haskell, where you can also find an entire course on Introduction to Haskell. Do exercises from that course at your own pace to get a deep understanding of the concepts that were covered in class.
You can also directly do the smaller Haskell exercises in this web-based IDE.
How do I use Haskell on the lab machines?
From the command line, on any of the Linux machines, type
ghcito launch the Haskell interpreter. Inside the interpreter you can type Haskell expressions to evaluate them, eg.
Prelude> 3*5 15You can also define values and functions to use them later on
Prelude> let inc n = n+1 Prelude> let x = 9 Prelude> inc x 10
To get help on basic ghci usage type:
> :help Commands available from the prompt:evaluate/run : repeat last command :{\n ..lines.. \n:}\n multiline command ...
Detailed documentation on using ghci is available here.
Then, follow the instructions on the slides and do the Haskell exercises. A lot of useful information is in the early chapters of the Real World Haskell book.
GHCi usage in a nutshell
Basic commands:
- <statement> evaluate/run <statement>
- :quit exit GHCi
- :reload reload the current module set
- :load <filename> loads Haskell module(s) <filename>
- :help prints all commands
- :info prints the type info about a name
- :type <expr> show the type of <expr>
For details see the GHCi documentation and the GHC documentation in general.
GHCi sample session
A very simple sample session:
Prelude> let inc n = n+1 Prelude> let x = 9 Prelude> :type inc inc :: Num a => a -> a Prelude> inc x 10
How can I run the Haskell sample sources?
Download the sample sources for sum-of-squares (from slides). Launch the interpreter with this file as input:
ghci sqs.hsInside the interpreter, check that all versions of sqs_even give the same result, e.g.
*Main> sqs_even [1..10] 220Continue with these Haskell exercises.
How do I profile sequential Haskell programs?
Detailed information is available here. In short, to download, compile and profile two versions of the Taylor series example (power.hs, power_circ.hs) do
# download the examples wget http://www.macs.hw.ac.uk/~hwloidl/Courses/F21DP/srcs/power.hs wget http://www.macs.hw.ac.uk/~hwloidl/Courses/F21DP/srcs/power_circ.hs # compile the first program; note the -prof and -auto-all options ghc -cpp -O2 -rtsopts -prof -auto-all -o p_hs power.hs # run the program ./p_hs 2000 10 +RTS -pT -hC -sstderr # this file contains a summary and split up of execution time less p_hs.prof # display the heap consumption profile hp2ps p_hs.hp ps2pdf p_hs.ps evince p_hs.ps # compile the second program; note the -prof and -auto-all options ghc -cpp -O2 -rtsopts -prof -auto-all -o p_circ power_circ.hs # run the program ./p_circ 2000 10 +RTS -pT -hC -sstderr # compare the summary of execution time with the previous one less p_circ.prof # display the heap consumption profile hp2ps p_circ.hp ps2pdf p_circ.ps evince p_circ.pdf
This has been tested with this ghc version:
which ghc /u1/staff/dsg/OPT/x86_64-unknown-linux/bin/ghc
How do I compile and run a (parallel) Haskell program?
Before the first compilation only, you need to install the parallelism libraries needed for these examples. GHC uses its own package manager for libraries, called cabal, and for larger projects this is the recommended way of using libraries. This is an alternative to downloading the .tar.gz bundles above. Detailed documentation for Cabal is available here.
To tell GHC that it should use the latest parallel package, available from the online database of Haskell packages, Hackage, do the following:
cabal update cabal install deepseq cabal install parallelThis should download and install the libraries in local directory (usually somewhere under ~/.cabal). Now, Control.Parallel.Strategies etc are in scope and you should be able to compile a parallel program like this:
ghc -cpp -O2 -threaded -rtsopts -o p parfib.hsThis has been tested with GHC 7.6.3:
bwlf17[447](4.1)> which ghc /usr/bin/ghc bwlf17[448](4.1)> ghc --version The Glorious Glasgow Haskell Compilation System, version 7.6.3
Is there an easier way of compiling Haskell programs?
The recommended way of compiling parallel Haskell programs is summarised here
.Alternatively, to get your own copies of the required libraries and use them to compile and run parfib, follow these steps (either on lxpara3 or any of the bwlf machines):
wget http://www.macs.hw.ac.uk/~hwloidl/Courses/F21DP/srcs/parfib.hs wget http://hackage.haskell.org/packages/archive/deepseq/1.3.0.1/deepseq-1.3.0.1.tar.gz tar xfz deepseq-1.3.0.1.tar.gz wget http://hackage.haskell.org/packages/archive/parallel/3.2.0.3/parallel-3.2.0.3.tar.gz tar xfz parallel-3.2.0.3.tar.gz wget http://hackage.haskell.org/packages/archive/haskell98/2.0.0.2/haskell98-2.0.0.2.tar.gz tar xfz haskell98-2.0.0.2.tar.gz ghc -cpp -ideepseq-1.3.0.1 -iparallel-3.2.0.3 -ihaskell98-2.0.0.2 -XBangPatterns -threaded -rtsopts -o parfib parfib.hs ./parfib 37 +RTS -N6 -sstderr
How do I install threadscope?
Most recent Linux distributions have a package called threadscope, so use your favourite package manager to download and install it. For example, on an Ubuntu 14.10 machine do the following:
apt-get install threadscope
I can't find a threadscope package for my distro. How do I install threadscope from sources?
You can use GHC's package manager, cabal, to install threadscope from sources, but it needs the right version of GHC and some other graphics packages locally to succeed. You will need the pango and gtk libraries at least, and these can be installed on an Ubuntu 14.04 distro like this (for more detailed installation instructions see the Threadscope Wiki):
# check whether you have the pango libraries > pkg-config --list-all | fgrep pango # if not, install them like this > sudo apt-get install libpango1.0-dev # check whether you have the gtk libraries > pkg-config --list-all | fgrep gtk # if not, install them like this > sudo apt-get install gtk+-2.0
Now, to install threadscope follow the steps below:
# check that ghc is in your path > which ghc # check that you have the right ghc version: it should be at least 7.6 > ghc --version # you first need to install some Haskell tools, to interface with the GTK graphics library # you'll also need the developers versions of the GTK libraries on your distro > cabal install gtk2hs-buildtools # with these installed, you can now install threadscope, # and cabal will automatically install required packages > cabal install threadscope # to use threadscope, you will need to add the following dir to your path > export PATH=$HOME/.cabal/bin:$PATH # now, check that threadscope is in your path > which threadscope
How do I use threadscope for visualisation?
To enable parallel profiling on a program that uses evaluation strategies or explicit pars, compile like this:
ghc -O2 -rtsopts -threaded -eventlog -o parsum_thr_l parsum.hs
and run the program with these extra runtime options:
./parsum_thr_l 500M +RTS -N6 -ls
This will generate a file parsum_thr_l.eventlog and you can visualise its data by calling:
/home/hwloidl/.cabal/bin/threadscope parsum_thr_l.eventlog
How to run threadscope (and ghc) on your laptop using a docker image
You can use a docker image, which is in essence a virtual machine pre-configured with all software needed for these exercises. Once installed and started, you work as if on a separate machine.
Start a docker container like this:
sudo docker run -i -t -e DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix -v $HOME/.Xauthority:/$HOME/.Xauthority -v $HOME/GPH:$HOME/GPH --net=host hwloidl/milan15_gph_ubuntu:devel
Inside the container, create a user with the same name and id as on your laptop (use the command id to print both). This is needed if you want to use threadscope for visualisation. For example, in my setup I do the following (as root):
root> groupadd -g 1701 hwloidl root> useradd -u 1701 -g 1701 -G sudo -s /bin/bash -m hwloidl root> passwd hwloidl
This container already has a user milan15, with the Haskell examples in the directory GPH. Use this this user to compile and run your programs like this (starting as root):
# su -l milan15 > cd GPH/ > ghc -O2 -rtsopts -threaded -eventlog -o parsum_thr_l parsum.hs > ./parsum_thr_l 90M 100 +RTS -N6 -ls Workers: 6 Running ... done parallel sum up to 90000000 using 6 cores is OK? True
To visualise the data with threadscope you need to log in as the user, that you created above:
> su -l hwloidl > cd GPH > which threadscope /home/milan15/.cabal/bin/threadscope > cd ~milan15/GPH > threadscope parsum_thr_l.eventlog
How do I install Haskell (GHC) packages, such as threadscope
You can automatically install GHC packages, by using its own package manager: cabal (detailed documentation for Cabal is available here).
As an example, type this to download, compile and install threadscope:
cabal install threadscopeBy default, this will put the binary into ~/.cabal/bin. To use it, add the directory to your path:
> export PATH=$PATH:~/.cabal/binand then just call threadscope like this:
threadscope parsum_thr_l.eventlogand enjoy the warm and fluffy feeling of using your own copy of the parallel profiler.
How do I compile and run UPC code?
You need to login to lxpara3 to get full UPC support. First, adjust your environment to pick up the installed upcc compiler:
> export PATH=$PATH:/home/dsg/OPT/x86_64-unknown-linux/opt/binThen, you can compile a UPC program in file vecadd4.c like this:
> upcc --pthreads -o v4 vecadd4.cand run like this (on 8 cores)
> export UPC_PTHREADS_PER_PROC=1; upcrun -n=8 v4 555555See the documentation on statically or dynamically fixing the number of processors etc. To launch a sequence of measurements, do
> for ((n=1; n<9; n++)) ; do upcrun -n=$n v4 555555 ; done
How do I compile and run code under the Hadoop system for MapReduce?
See the notes in the Hadoop Lab for details. In short, the sequence of steps is this:
To set up the Hadoop infrastructure do the following:
export HADOOP_HOME=/scratch/hadoop-0.23.0 export JAVA_HOME=/usr/java/default export PATH=${HADOOP_HOME}/bin:${JAVA_HOME}/bin:${PATH}
To compile a simple example, download the WordCount.java example, put into a fresh directory and compile it:
wget http://www.macs.hw.ac.uk/~hwloidl/Courses/F21DP/srcs/WordCount.java mkdir wordcount_classes javac -classpath "${HADOOP_HOME}/lib/*:${HADOOP_HOME}/share/hadoop/common/*:${HADOOP_HOME}/share/hadoop/common/lib/*" -d wordcount_classes WordCount.java jar -cvf wordcount.jar -C wordcount_classes .
You need to provide input like this:
mkdir input wget http://www.macs.hw.ac.uk/~hwloidl/Courses/F21DP/srcs/WaD.txt mv WaD.txt input/file01 wget http://www.macs.hw.ac.uk/~hwloidl/Courses/F21DP/srcs/TMM.txt mv TMM.txt input/file02
Now, you can run a single-node Hadoop application like this:
java -cp wordcount.jar:${HADOOP_HOME}/*:${HADOOP_HOME}/lib/*:${HADOOP_HOME}/share/hadoop/common/*:${HADOOP_HOME}/share/hadoop/common/lib/* org.myorg.WordCount input output
You can view the result, i.e. the number of occurrences for each word in the input files, like this:
less output/part-00000
Make sure to delete, or rename, the output directory before you re-run the same application.
How do I compile and run Eden programs?
Full instructions can be found here: http://www.mathematik.uni-marburg.de/~eden/?content=build_progs&navi=build
Preferably use the compiler in the main DSG directory and download the sample code from the Eden tutorial section:
export PATH=/u1/staff/dsg/OPT/x86_64-unknown-linux/bin:$PATH wget http://www.macs.hw.ac.uk/~hwloidl/Courses/F21DP/srcs/ParMap.hs wget http://www.macs.hw.ac.uk/~hwloidl/Courses/F21DP/srcs/mandel.hsThen compile the mandelbrot example like this:
ghc-7.6.2-eden -parcp -eventlog -O2 -rtsopts --make mandel.hsand run it like this
./mandel 0 200 1 -out +RTS -qp4 > out.ppmThis generates a mandelbrot picture in the file out.ppm which you can view like this:
display out.ppm
Follow the instructions at the end of the Eden slide-set and do some of the exercises.
To run on the cluster (i.e. more than one node) e.g. bwlf01-04 do the following:
- list the nodes in a file (e.g. mpihosts):
bwlf01 bwlf02 bwlf03 bwlf04
- add current directory to path:
PATH=`pwd`:$PATH
- start mpd (mpi process) with 4 nodes (i.e 8x4=32 processors in total):
mpdboot -n 4 -f mpihosts
Note: you might need to run `mpdallexit` first to exit existing running mpd instances. - run program as in step 4, specifying -N up to 32 processors.
You can find many more examples, and an in-depth Eden tutorial on this Eden CEFP tutorial page.
How do I get started with Haskell?
On the Linux lab machines you can use the command ghci to start the Haskell interpreter. In the interpreter you can type Haskell expressions to evaluate them. This is sufficient for the first Haskell exercises.
> ghci GHCi, version 7.6.3: http://www.haskell.org/ghc/ :? for help Loading package ghc-prim ... linking ... done. Loading package integer-gmp ... linking ... done. Loading package base ... linking ... done. Prelude> 2+3 5 Prelude> let n=5 Prelude> n^2 25
How do I write Haskell programs?
You can write functions and programs directly in the interpreter, using multi-line syntax, like this:
Prelude> let { mysum 0 = 0 ; mysum n = if even n then n^2 + (mysum (n-1)) else mysum (n-1) } Prelude> mysum 10 220
However, usually it is more convenient to use an editor and write the functions line by line (as shown on the slides). Once you have completed the file, eg. called lab.hs, you can load it into the interpreter like this:
> :load "lab.hs"
Can I get a graphical IDE for developing Haskell programs?
There is a web-based IDE available, together with basic Haskell tutorials: School of Haskell. You can use their tutorials to complement your Haskell learning.