xumarhu.net xumarhu.net biblioteca
Principal > Biblioteca > Manuales de Instalación > Instalación de un cluster con Raspberry Pi

Instalación de un cluster con Raspberry Pi



Pasos para la construcción del Cluster

1) Material
2) Rack para el Cluster
3) Conexión (Hardware)
4) Configuración (Software)
5) Código de ejemplo



1) Material

Rack
Raspberrys
Switch
Alimentador USB ó cargadores individuales



2) Rack para el Cluster

Compra
Construcción



3) Conexión (Hardware)

Instalación de las Raspberry
Instalación del switch
Comprar cable, cortarlo a la medida y ponchar conectores
Instalar cables
Instalar alimentación a cada dispositivo



4) Configuración (Software)

Asignar dirección IP propia a cada nodo

Generar llave en cada nodo
ssh-keygen -t rsa

Copiar las llaves al nodo maestro:
ssh-copy-id 10.0.0.1

Donde 10.0.0.1 es la IP del nodo maestro (cambiar de acuerdo a las direcciones deseadas en el nodo)

Instalar MPI
sudo apt install mpich python3-mpi4py

En cada nodo correr el siguiente comando para probar el funcionamiento:
mpiexec -n 1 hostname

Para probar todos los nodos del cluster, hay que ejecutar el siguiente comando en el nodo maestro:
mpiexec -n 4 --hosts 10.0.0.1,10.0.0.2,10.0.0.3,10.0.0.4 hostname

Donde se supone el cluster es de 4 nodos y se especifican las IPs de cada nodo y "hostname" es para que imprima los nombres de los nodos



5) Código de ejemplo

A continuación un código de ejemplo para imprimir números primos:

from mpi4py import MPI
import time
import sys

# Attach to the cluster and find out who I am and how big it is
comm = MPI.COMM_WORLD
my_rank = comm.Get_rank()
cluster_size = comm.Get_size()

# Number to start on, based on the node's rank
start_number = (my_rank * 2) + 1

# When to stop. Play around with this value!
end_number = int(sys.argv[1])

# Make a note of the start time
start = time.time()

# List of discovered primes for this node
primes = []

# Loop through the numbers using rank number to divide the work
for candidate_number in range(start_number,
end_number, cluster_size * 2):

# Log progress in steps
# print(candidate_number)

# Assume this number is prime
found_prime = True

# Go through all previous numbers and see if any divide without remainder
for div_number in range(2, candidate_number):
if candidate_number % div_number == 0:
found_prime = False
break

# If we get here, nothing divided, so it's a prime number
if found_prime:
# Uncomment the next line to see the primes as they are found (slower)
# print('Node ' + str(my_rank) + ' found ' + str(candidate_number))
primes.append(candidate_number)

# Once complete, send results to the governing node
results = comm.gather(primes, root=0)

# If I am the governing node, show the results
if my_rank == 0:

# How long did it take?
end = round(time.time() - start, 2)

print('Find all primes up to: ' + str(end_number))
print('Nodes: ' + str(cluster_size))
print('Time elasped: ' + str(end) + ' seconds')

# Each process returned an array, so lets merge them
merged_primes = [item for sublist in results for item in sublist]
merged_primes.sort()
print('Primes discovered: ' + str(len(merged_primes)))
# Uncomment the next line to see all the prime numbers
# print(merged_primes)

Para ejecutar el código anterior:
mpiexec -n 1 python3 prime.py 1000


Usted se encuentra Aquí > Principal > Biblioteca > Manuales de Instalación > Instalación de un cluster con Raspberry Pi
Portal de Tecnología desarrollado por: Rogelio Ferreira Escutia
Valid CSS Valid XHTML 5