Cluster com MPICH2 no UBUNTU NOV/2010 Este documento é apenas um resumo, caso seja necessário, ver com mais detalhes os arquivos: mpich2-doc-user.pdf e mpich2-doc-install.pdf. Estes docs vem junto com o pacote de instalação. No ubuntu, é possível instalar o mpich2 - última versão - com o apt-get ou com o Synaptic. Recomendo instalar o mpich2 em todas as máquinas do cluster caso queira evitar depender do NFS para comunicação. Se desejar, poderá testar depois com o NFS, neste caso, tomar cuidado em compartilhar arquivos de sistema das máquinas, pois a instalação padrão do mpich2 pelo Ubuntu é feita em /usr/bin. Neste caso, sugiro instalar manualmente o mpich2 utilizando um diretório de instalação independente, por exemplo /usr/local/mpich2-install. PASSOS DE INSTALAÇÃO 1. Unpack the tar file. (diretório de preferência) Obs: Aqui # significa login com o root # tar xfz mpich2.tar.gz If your tar doesn t accept the z option, use # gunzip -c mpich2.tar.gz tar xf - 2. Choose an installation directory (the default is /usr/local/bin): # mkdir /DIR_LOCAL/mpich2-install 3. Choose a build directory. 4. # mkdir /tmp/you/mpich2 4. Configure MPICH2: # cd /tmp/you/mpich2 # /home/you/libraries/mpich2-1.0.6/configure \ -prefix=/home/you/mpich2-install & tee configure.log 5. Build MPICH2: # make & tee make.log 1/6
6. Install the MPICH2 commands: # make install & tee install.log 8. Add the bin subdirectory of the installation directory to your path: # export PATH=/home/you/mpich2-install/bin:$PATH Ou crie o arquivo /etc/profile.d/mpiconf.sh, com o conteúdo: Obs: Aqui # significa comentário no arquivo. #!bin.bash # #PATH ENVIRONMENT TO MPICH2 # PATH=$PATH:/usr/bin export PATH # END ENVIRONMENT TO MPICH2 # Check that everything is in order at this point by doing: # which mpd # which mpicc # which mpiexec # which mpirun 9. For security reasons, MPD looks in your home directory for a file named.mpd.conf containing the lines: Obs: Aqui # significa comentário no arquivo. # Arquivo.mpd.conf. # Permite que o root rode o MPD # Definição da senha secreta = 1234 # MPD_USE_ROOT_MPD=1 MPD_SECRETWORD=1234 #Fim do arquivo # onde MPD_SECRETWORD não pode ser uma senha do Linux, p. ex. use 1234. Dê permissão somente ao usuário: chmod 700.mpd.conf. Colocar também este arquivo no diretório etc/ mas renomeando-o para mpd.conf (ou seja sem o ponto na frente do nome) 10. The first sanity check consists of bringing up a ring of one MPD on the local machine, testing one MPD command, and bringing the ring down. # mpd & # mpdtrace 2/6
# mpdallexit 11. The next sanity check is to run a non-mpi program using the daemon. # mpd & # mpiexec -n 1 /bin/hostname # mpdallexit 12. Now we will bring up a ring of mpd s on a set of machines. Create a file consisting of a list of machine names, one per line. Name this file /etc/mpd.hosts. Exemplo: # Arquivo mpd.hosts com os hosts usados no MPI. ubuntu suse notebook # Fim do arquivo mpd.hosts Alterar também o arquivo /etc/hosts, principalmente o endereço local, exemplo: 127.0.0.1 localhost #127.0.1.1 ubuntu # ATENÇÃO PARA A MUDANÇA NESTA LINHA! 192.168.0.125 ubuntu 192.168.0.169 suse 192.168.0.176 notebook 13. Check that you can reach these machines with ssh or rsh without entering a password. You can test by doing : or # ssh othermachine date # rsh othermachine date Para configurar o ssh e rsh para evitar a autenticação, fazer as seguintes mudanças: Em /etc/securetty acresentar as linhas: # CLUSTER COM MPICH2 rsh rexec 3/6
rlogin # Em /etc/pam.d/rsh modificar a linha: auth required pam_rhosts_auth.so para: auth sufficient pam_rhosts_auth.so Em /etc/ssh/sshd_config descomente a linha: AuthorizedKeysFile %h/.ssh/authorized_keys Para o ssh fazer autenticação automática, é preciso fazer o compartilhamento de chaves pública entre o servidor (master) e as máquinas escravas. Para gerar uma chave pública em cada máquina, dentro do home do usuário executar o comando: # ssh-keygen -b 1024 -t rsa Serão gerados dois arquivos de chaves, um chamado id_rsa e outro id_rsa.pub. Em seguida transferir id_rsa.pub para o local /usuário/.ssh/ renomeando o arquivo original para authorized_keys, ou seja, pode utilizar o comando: # scp id_rsa.pub ip_destino:/home/usuário/.ssh/authorized_keys e também em /root: # scp id_rsa.pub ip_destino:/root/.ssh/authorized_keys 13. Start the daemons on (some of) the hosts in the file mpd.hosts. # mpdboot -n <number to start> -f /etc/mpd.hosts Check to see if all the hosts you listed in mpd.hosts are in the output of. # mpdtrace There is a workaround if you cannot get mpdboot to work because of difficulties with ssh or rsh setup. You can start the daemons by hand as follows: # mpd & # starts the local daemon # mpdtrace -l # makes the local daemon print its host # and port in the form <host>_<port> # mpdallexit # força o mpd a sair 4/6
Then log into each of the other machines, put the install/bin directory in your path, and do: # -h <hostname> -p <port> & # mpdtrace 14. Now we will run an MPI job, using the mpiexec command. # mpiexec -n 2./cpi O parâmetro n indica o número de processos. O cpi é um exemplo (vem com o pacote em exemplos/) de aplicação para gerar carga de processamento calculando o valor de Pi. Este pode ser compilado a partir do comando: ou # mpicc cpi.c -o cpi # mpicc.mpich2 cpi.c -o cpi EM CASO DE PROBLEMAS: Select a test node, let s call it n1. Login to n1. First, we will run mpdcheck as a server and a client. To run it as a server, get into a window with a command-line and run this: n1# mpdcheck -s It will print something like this: server listening at INADDR_ANY on: n1 1234 Now, run the client side (in another window if convenient) and see if it can find the server and communicate. Be sure to use the same hostname and portnumber printed by the server (above: n1 1234): n1# mpdcheck -c n1 1234 If all goes well, the server will print something like: server has conn on <socket._socketobject object at 0x40200f2c> from ( 192.168.1.1, 1234) server successfully recvd msg from client: hello_from_client_to_server and the client will print: client successfully recvd ack from server: ack_from_server_to_client 5/6
Try a few tests: n1# mpd & n1# mpiexec -n 1 /bin/hostname n1# mpiexec -l -n 4 /bin/hostname n1# mpiexec -n 2 PATH_TO_MPICH2_EXAMPLES/cpi To terminate the mpd: n1# mpdallexit Para mais informação utilize os docs acima relacionados. 6/6