Once you're logged in, you'll want to create your own directory to work in, so you don't interfere with others sharing the common account. To do this, use the Unix mkdir command and your username, and then the cd command to change to that directory. For example, I would type (in bold):
[cs102@HBAR ~]$ mkdir levys
[cs102@HBAR ~]$ cd levys
[cs102@HBAR levys]$ vi hello.cTo help avoid typos, I suggest copying and pasting the commands from your web browser to your hbar shell, too – then you can just up-arrow to retrieve them. (In fact, if I see people struggling to type commands into the shell, I'm going to get angry and put Taylor Swift on the speakers or something.) This will open up an empty file, into which you can insert text by typing a single i, putting you in insert mode. Now you can copy-and-paste from the example into your vi session. You can just copy-and-paste everything between the first two paragraphs – i.e, from the /*The Parallel Hello World Program*/ comment line through the closing }. Once you're done pasting, hit ESC to get out of insert mode, hit : (colon, i.e. shift-semicolon) to get into file mode, and type wq to write (save) the file and quit.
[cs102@HBAR levys]$ mpicc -o hello hello.c(If you get all kinds of crazy errors, it's probably because you didn't copy and paste the code correctly – perhaps you left out the initial or final character or line. In typical Unix fashion, if everything's okay you get no message, just the prompt.) The mpicc command invokes the MPI C Compiler. The -o option specifies the name of the output file, which is usually the same as the name of the .c file, but without the .c extension.
[cs102@HBAR levys]$ mpirun -np 8 helloIf everything is working, you should see an output something like this:
Hello World from Node 0 Hello World from Node 3 Hello World from Node 4 Hello World from Node 5 Hello World from Node 1 Hello World from Node 2 Hello World from Node 6 Hello World from Node 7(The output may be preceded and followed by some warnings or other messages, but don't worry about those right now.) Repeat the run several times (up-arrow!), and you'll see that the node order isn't always the same. This is because MPI is executing each process (copy of the program) concurrently (simultaneously, independently), with no guarantee of who finishes first. MPI decides internally how to dole out the processes to the processors (individual computing nodes), but to a first approximation we can assume one processor per process.
[cs102@HBAR levys]$ mpirun -np 4 cpi 1000uses four processes and 1000 intervals. Now you can experiment to see how long it takes to execute the program under various combinations of these parameters, using the Unix time command:
[cs102@HBAR levys]$ time mpirun -np 4 cpi 1000One interesting experiment is to start with just one processor and increase the number of intervals by a factor of 10 until it starts to take a non-trivial amount of time (several seconds) to compute the result. Then add more processors and see what happens. Then, conversely, keep the number of intervals small (like 1000) and see what happens as you increase the number of processors. Does using more processors always give you a faster result? Why not? (Hint: Look at the slides starting at #23 in the lectures notes for this week.)
If you've been paying attention, you'll naturally be wondering how Moore's Law fits into this.
Well, I ran the program with 1000000000 intervals on our one of our Mac Minis without MPI, and it took around 11.8 seconds.
So you should try to see how many processes you need to beat that on HBAR, and how much better you can do,
and include that info in your writeup. While you're at it, find the average price of a Mac Mini at Apple's online
store, and compare it to the approximately $70,000 dollars that HBAR cost back in 2010. (Of course, HBAR is probably used
for more than just computing the digits of Pi!)
In your writeup, include plots for these two experiments, as well as your explanation of the results.
To get started, download this file to your Mac. Open up another terminal on the Mac, and type
Now you'll use scp, the companion program to ssh, to securely copy the file to your directory on hbar. For example, I would do:
scp galaxSeeHPC_source.tar email@example.com:~/levys
Every character counts, so type carefully!
Back on hbar, unpack the new file:
[cs102@HBAR levys]$ tar xvf galaxSeeHPC_source.tar
You'll see a list of new files scroll by, after which you can cd to the new directory containing them:
[cs102@HBAR levys]$ cd GalaxSeeHPC
Now use vi to edit the file named Makefile. Look for the section starting with ###### FFTW OPTIONS, and edit the second and third lines of that section so they look exactly like this:
CFLAGS += -I/export/apps/fftw/3.2.2/include
LIBS += -L/export/apps/fftw/3.2.2/lib
Save the Makefile file and type
[cs102@HBAR levys]$ make
You'll see a much longer compilation session scroll by, after which you can run the program like this (for one processor):
[cs102@HBAR levys]$ mpirun -np 1 galaxsee simple.galYou should see some old-school-style ASCII art scrolling by, representing various stages in the evolution of the galaxy. As with the cpi program, try timing with different numbers of processors, and report / plot your results.