Difference between revisions of "Tutorial: Running MPI Programs on Hadoop Cluster"

From dftwiki3
Jump to: navigation, search
(Configuration)
(Setup Password-Less ssh to the Hadoop cluster)
 
(38 intermediate revisions by the same user not shown)
Line 1: Line 1:
--[[User:Thiebaut|D. Thiebaut]] ([[User talk:Thiebaut|talk]]) 13:57, 15 October 2013 (EDT)
+
--[[User:Thiebaut|D. Thiebaut]] ([[User talk:Thiebaut|talk]]) 13:57, 15 October 2013 (EDT)<br />
 +
Revised: --[[User:Thiebaut|D. Thiebaut]] ([[User talk:Thiebaut|talk]]) 12:02, 15 March 2017 (EDT)
 
----
 
----
 +
<br />
 +
__TOC__
 +
<br />
 +
=Change your Password=
 +
<br />
 +
* Login to hadoop01 with the accounts provided to you, and change your temporary password:
 +
 +
  passwd
 +
 +
* You should now be all set.
 +
<br />
  
=Setup to run MPI on multiple Linux-Mint computers=
+
=Setup Password-Less '''ssh''' to the Hadoop cluster=
* Follow general directions from [https://source.ggy.bris.ac.uk/wiki/Install_and_configure_MPI this page], or follow the steps summarized below.
+
<br />
 +
[[Image:MPIHapoopClusterStep1.png|600px|center]]
 +
<br />
 +
<onlysmith>
 +
* The directions below are taken from [http://www.linuxproblem.org/art_9.html this page], and summarized here for the hadoop cluster.  In all the steps you will need to replace ''yourusername'' by your actual user name on the hadoop cluster.
 +
<br/>
 +
:* ssh to hadoop01
 +
<br />
 +
:::<source lang="text">
 +
ssh -Y yourusername@hadoop01.dyndns.org
 +
</source>
 +
<br />
 +
:* enter the following commands
  
* First set up password-less login setup
+
<br />
=Setup password-less ssh=
+
:::<source lang="text">
* Follow directions in [https://source.ggy.bris.ac.uk/wiki/Configure_ssh_for_MPI this page], or follow the steps summarized below.
+
  ssh-keygen -t rsa ''(and press ENTER 3 times)''
* We'll use 3 of the Linux-Mint machines for this demo.
 
<onlysmith>
 
** 131.229.103.46 a.k.a. FH345-03
 
** 131.229.103.62 a.k.a. FH345-09
 
** 131.229.103.63 a.k.a. FH345-04
 
</onlysmith>
 
* login to one of the Linux-Mint machines with your 352a-xx account.
 
* enter the following commands:
 
  ssh-keygen -t rsa
 
 
  ls .ssh
 
  ls .ssh
 
  cd .ssh
 
  cd .ssh
  mv id_rsa id_rsa.mpi
+
  ssh yourusername@hadoop02.dyndns.org mkdir -p .ssh
  mv id_rsa.pub id_rsa.mpi.pub
+
  cat ~/.ssh/id_rsa.pub | ssh yourusername@hadoop02.dyndns.org 'cat >> .ssh/authorized_keys'
  ls -l
+
</source>
total 12
+
<br />
-rw------- 1 352a 352a 1675 Oct 15 13:33 id_rsa.mpi
+
   
  -rw------- 1 352a 352a 396 Oct 15 13:33 id_rsa.mpi.pub
+
 
  -rw-r--r-- 1 352a 352a  444 Oct 14 14:26 known_hosts
+
:* Now ssh to '''hadoop02''' and verify that you can ssh without password, as the authentication is now done through rsa keys.
  cat id_rsa.mpi.pub > authorized_keys
+
:* exit from hadoop02 and find yourself again on '''hadoop01'''
  emacs -nw config    ''(and add the next line to the file)''
+
:* repeat the last 2 commands above (ssh and cat) for '''hadoop03''', and '''hadoop04''':
  IdentityFile ~/.ssh/id_rsa.mpi
+
<br />
 +
:::<source lang="text">
 +
  ssh yourusername@hadoop03.dyndns.org mkdir -p .ssh
 +
  cat ~/.ssh/id_rsa.pub | ssh yourusername@hadoop03.dyndns.org 'cat >> .ssh/authorized_keys'
 +
 
 +
  ssh yourusername@hadoop04.dyndns.org mkdir -p .ssh
 +
  cat ~/.ssh/id_rsa.pub | ssh yourusername@hadoop04.dyndns.org 'cat >> .ssh/authorized_keys'
 +
</source>
 +
<br />
 +
 
 +
:* verify that you can ssh to '''hadoop03''' and '''hadoop04''' without password.
 +
* You should now be all set with passwordless ssh to the hadoop01, 02, 03, and 04 cluster.
 +
</onlysmith>
 +
<br />
 +
 
 +
=Setup Aliases=
 +
<br />
 +
* This section is not required, but will save you a lot of typing.
 +
* Edit your .bashrc file
 +
   
 +
  emacs -nw ~/.bashrc
 +
 +
* and add these 3 lines at the end, where you will replace ''yourusername'' by your actual user name.
 +
 +
alias hadoop02='ssh -Y yourusername@hadoop02.dyndns.org'
 +
alias hadoop03='ssh -Y yourusername@hadoop03.dyndns.org'
 +
alias hadoop04='ssh -Y yourusername@hadoop04.dyndns.org'
 +
 +
* Then tell bash to re-read the .bashrc file, since we just modified it.  This way bash will learn the 3 new aliases we've defined.
 +
 +
  source ~/.bashrc
 +
 +
* Now you should be able to connect to the servers using their name only.  For example:
 +
 +
hadoop02     
 +
 
 +
: this should connect you to '''hadoop02''' directly.
 +
* Exit from hadoop02, and try the same thing for '''hadoop03''', and '''hadoop04'''.
 +
* Note, if you like even shorter commands, you could modify the .bashrc file and make the aliases h2, h3, and h4...  Up to you.
 +
 +
<br />
  
* Now login to another Linux-Mint machine.  You should be able to login without having to enter a password.
+
=Create HelloWorld Program &amp; Test MPI=
 +
<br />
 +
[[Image:MPIHapoopClusterStep2.png|600px|center]]
 +
<br />
  
=Configuration=
+
MPI should already be installed, and your account ready to access it.  To verify this, you will create an MPI directory and create a simple MPI "Hello World!" program in it.  You will then compile it, and run it as an MPI application.
  
* create a file called '''hosts''' in the directory where the mpi programs are located.
+
* First create a directory called '''mpi'''
* Store the following IP addresses in it:
+
 +
cd
 +
mkdir mpi
 +
 +
* Then '''cd''' to this directory and create the following C program:
 +
 +
cd mpi
 +
emacs -nw helloWorld.c
 +
 +
:Here's the code:
 +
<br />
 +
::<source lang="C">
 +
// hello.c
 +
// A simple hello world MPI program that can be run
 +
// on any number of computers
 +
#include <mpi.h>
 +
#include <stdio.h>
 +
 
 +
int main( int argc, char *argv[] ) {
 +
  int rank, size, nameLen;
 +
  char hostName[80];
 +
 
 +
  MPI_Init( &argc, &argv);  /* start MPI */
 +
  MPI_Comm_rank( MPI_COMM_WORLD, &rank );  /* get current process Id */
 +
  MPI_Comm_size( MPI_COMM_WORLD, &size );  /* get # of processes */
 +
  MPI_Get_processor_name( hostName, &nameLen);
 +
 
 +
  printf( "Hello from Process %d of %d on Host %s\n", rank, size, hostName );
 +
  MPI_Finalize();
 +
  return 0;
 +
}
 +
 
 +
</source>
 +
<br />
 +
=Compile & Run on 1 Server=
 +
<br />
 +
[[Image:MPIHapoopClusterStep3.png|600px|center]]
 +
<br />
 +
 
 +
* Compile and Run the program:
 +
<br />
 +
 +
'''mpicc -o hello helloWorld.c'''
 +
'''mpirun -np 2 ./hello'''
 +
Hello from Process 1 of 2 on Host Hadoop01
 +
Hello from Process 0 of 2 on Host Hadoop01
 +
 +
* If you see the two lines starting with "Hello world" on your screen, MPI was successfully installed on your system!
 +
 
 +
<br />
 +
 
 +
=Configuration for Running On Multiple Servers=
 
<onlysmith>
 
<onlysmith>
 +
<br />
 +
* You will now create a file called '''hosts''' that contains all the IP addresses of the servers in our cluster.
 +
* The easy way to do is to '''dig''' each server one after the other:
 +
 +
dig +short hadoop01.dyndns.org
 +
dig +short hadoop02.dyndns.org
 +
dig +short hadoop03.dyndns.org
 +
dig +short hadoop04.dyndns.org
 
   
 
   
+----+-------------+-----------------+-----------------+
+
* Create a file called '''hosts''' in the directory where the mpi programs are located, and store the IP addresses you will have obtained with '''dig''' in it.
| id | system_name | ip              | system_location |
+
 
+----+-------------+-----------------+-----------------+
+
* For those of you who are bash enthusiasts, you can do this in one command:
  1 | ford345-09  | 131.229.103.62  | Ford 345        |
+
 
2 | ford345-03  | 131.229.103.46  | Ford 345        |
+
  for i in 1 2 3 4 ; do dig +short hadoop0${i}.dyndns.org ; done > hosts
3 | ford345-04  | 131.229.103.63  | Ford 345        |
+
 
4 | ford345-05  | 131.229.103.64  | Ford 345        |
 
|  5 | ford345-06  | 131.229.103.57  | Ford 345        |
 
|  6 | ford345-L  | 131.229.103.52  | Ford 345        |
 
|  7 | ford345-10  | 131.229.103.186 | Ford 342        |
 
|  8 | ford345-02  | 131.229.103.188 | Ford 342        |
 
|  9 | ford342-07  | 131.229.103.122 | Ford 342        |
 
| 10 | ford342-08  | 131.229.103.109 | Ford 342        |
 
| 11 | ford342-05  | 131.229.103.214 | Ford 342        |
 
| 12 | ford342-02  | 131.229.103.158 | Ford 342        |
 
| 13 | ford342-04  | 131.229.103.174 | Ford 342        |
 
| 14 | ford342-09  | 131.229.103.173 | Ford 342        |
 
| 15 | ford342-10  | 131.229.103.172 | Ford 342        |
 
| 16 | ford342-L  | 131.229.103.143 | Ford 342        |
 
| 17 | ford345-08  | 131.229.100.178 | Ford 342        |
 
| 18 | ford345-07  | 131.229.101.176 | Ford 342        |
 
| 19 | ford342-06  | 131.229.97.201  | Ford 342        |
 
| 20 | ford342-03  | 131.229.101.192 | Ford 342        |
 
+----+-------------+-----------------+-----------------+
 
 
 
 
</onlysmith>
 
</onlysmith>
 +
=Running HelloWorld.c on all Four Servers=
 +
<br />
 +
==Rsync Your Files to Other Servers==
 +
<br />
 +
[[Image:MPIHapoopClusterStep4.png|600px|center]]
 +
<br />
 +
<tanbox>
 +
'''Important Note''': Every time you create a new program on Hadoop01, you will need to replicate it on the other 3 servers.  This is something that is easily forgotten, so make a mental note to always copy your latest files to the other 3 servers.
 +
</tanbox>
 +
<br />
 +
* One powerful command to copy files remotely is '''rsync''':
 +
 +
cd
 +
cd mpi
 +
rsync -azv *  yourusername@hadoop02.dyndns.org:mpi/
 +
rsync -azv *  yourusername@hadoop03.dyndns.org:mpi/
 +
rsync -azv *  yourusername@hadoop04.dyndns.org:mpi/
 +
 +
* Or, if you like bash for-loops:
 +
 +
cd
 +
cd mpi
 +
for i in 2 3 4 ; do rsync -azv * yourusername@hadoop0${i}.dyndns.org:mpi/ ; done
 +
 +
* You are now ready to run '''hello''' on all four servers:
 +
 +
<br />
 +
==Running on All Four Servers==
 +
<br />
 +
[[Image:MPIHapoopClusterStep5.png|600px|center]]
 +
<br />
 +
* Enter the following command:
 +
 +
'''mpirun -np 4 --hostfile hosts ./hello'''
 +
Hello from Process 0 of 4 on Host Hadoop01
 +
Hello from Process 3 of 4 on Host Hadoop04
 +
Hello from Process 2 of 4 on Host Hadoop03
 +
Hello from Process 1 of 4 on Host Hadoop02
 +
 +
* And try running 10 processes on 4 servers:
 +
 +
'''mpirun -np 10 --hostfile hosts ./hello'''
 +
Hello from Process 3 of 10 on Host Hadoop04
 +
Hello from Process 7 of 10 on Host Hadoop04
 +
Hello from Process 1 of 10 on Host Hadoop02
 +
Hello from Process 5 of 10 on Host Hadoop02
 +
Hello from Process 9 of 10 on Host Hadoop02
 +
Hello from Process 2 of 10 on Host Hadoop03
 +
Hello from Process 6 of 10 on Host Hadoop03
 +
Hello from Process 0 of 10 on Host Hadoop01
 +
Hello from Process 8 of 10 on Host Hadoop01
 +
Hello from Process 4 of 10 on Host Hadoop01
 +
 +
 +
<br />
 +
<br />
 +
<br />
 +
<br />
 +
<br />
 +
<br />
 +
<br />
 +
<br />
 +
<br />
 +
<br />
 +
<br />
 +
<br />
 +
<br />
 +
<br />
 +
<br />
 +
[[Category:MPI]][[Category:C]][[Category:CSC352]]

Latest revision as of 13:16, 23 March 2017

--D. Thiebaut (talk) 13:57, 15 October 2013 (EDT)
Revised: --D. Thiebaut (talk) 12:02, 15 March 2017 (EDT)




Change your Password


  • Login to hadoop01 with the accounts provided to you, and change your temporary password:
 passwd 

  • You should now be all set.


Setup Password-Less ssh to the Hadoop cluster


MPIHapoopClusterStep1.png



This section is only visible to computers located at Smith College


Setup Aliases


  • This section is not required, but will save you a lot of typing.
  • Edit your .bashrc file
 emacs -nw ~/.bashrc 

  • and add these 3 lines at the end, where you will replace yourusername by your actual user name.
alias hadoop02='ssh -Y yourusername@hadoop02.dyndns.org'
alias hadoop03='ssh -Y yourusername@hadoop03.dyndns.org'
alias hadoop04='ssh -Y yourusername@hadoop04.dyndns.org'

  • Then tell bash to re-read the .bashrc file, since we just modified it. This way bash will learn the 3 new aliases we've defined.
source ~/.bashrc

  • Now you should be able to connect to the servers using their name only. For example:
hadoop02      
this should connect you to hadoop02 directly.
  • Exit from hadoop02, and try the same thing for hadoop03, and hadoop04.
  • Note, if you like even shorter commands, you could modify the .bashrc file and make the aliases h2, h3, and h4... Up to you.


Create HelloWorld Program & Test MPI


MPIHapoopClusterStep2.png


MPI should already be installed, and your account ready to access it. To verify this, you will create an MPI directory and create a simple MPI "Hello World!" program in it. You will then compile it, and run it as an MPI application.

  • First create a directory called mpi
cd
mkdir mpi

  • Then cd to this directory and create the following C program:
cd mpi
emacs -nw helloWorld.c

Here's the code:


// hello.c
// A simple hello world MPI program that can be run 
// on any number of computers
#include <mpi.h>
#include <stdio.h>

int main( int argc, char *argv[] ) {
  int rank, size, nameLen;
  char hostName[80];

  MPI_Init( &argc, &argv);   /* start MPI */
  MPI_Comm_rank( MPI_COMM_WORLD, &rank );   /* get current process Id */
  MPI_Comm_size( MPI_COMM_WORLD, &size );   /* get # of processes */
  MPI_Get_processor_name( hostName, &nameLen);

  printf( "Hello from Process %d of %d on Host %s\n", rank, size, hostName );
  MPI_Finalize();
  return 0;
}


Compile & Run on 1 Server


MPIHapoopClusterStep3.png


  • Compile and Run the program:


mpicc -o hello helloWorld.c
mpirun -np 2 ./hello
Hello from Process 1 of 2 on Host Hadoop01
Hello from Process 0 of 2 on Host Hadoop01

  • If you see the two lines starting with "Hello world" on your screen, MPI was successfully installed on your system!


Configuration for Running On Multiple Servers


This section is only visible to computers located at Smith College

Running HelloWorld.c on all Four Servers


Rsync Your Files to Other Servers


MPIHapoopClusterStep4.png


Important Note: Every time you create a new program on Hadoop01, you will need to replicate it on the other 3 servers. This is something that is easily forgotten, so make a mental note to always copy your latest files to the other 3 servers.


  • One powerful command to copy files remotely is rsync:
cd 
cd mpi
rsync -azv *  yourusername@hadoop02.dyndns.org:mpi/
rsync -azv *  yourusername@hadoop03.dyndns.org:mpi/
rsync -azv *  yourusername@hadoop04.dyndns.org:mpi/

  • Or, if you like bash for-loops:
cd
cd mpi
for i in 2 3 4 ; do rsync -azv * yourusername@hadoop0${i}.dyndns.org:mpi/ ; done

  • You are now ready to run hello on all four servers:


Running on All Four Servers


MPIHapoopClusterStep5.png


  • Enter the following command:
mpirun -np 4 --hostfile hosts ./hello
Hello from Process 0 of 4 on Host Hadoop01
Hello from Process 3 of 4 on Host Hadoop04
Hello from Process 2 of 4 on Host Hadoop03
Hello from Process 1 of 4 on Host Hadoop02
  • And try running 10 processes on 4 servers:
mpirun -np 10 --hostfile hosts ./hello
Hello from Process 3 of 10 on Host Hadoop04
Hello from Process 7 of 10 on Host Hadoop04
Hello from Process 1 of 10 on Host Hadoop02
Hello from Process 5 of 10 on Host Hadoop02
Hello from Process 9 of 10 on Host Hadoop02
Hello from Process 2 of 10 on Host Hadoop03
Hello from Process 6 of 10 on Host Hadoop03
Hello from Process 0 of 10 on Host Hadoop01
Hello from Process 8 of 10 on Host Hadoop01
Hello from Process 4 of 10 on Host Hadoop01