This page looks best with JavaScript enabled

Raspberry Fields Forever

 ·  ☕ 9 min read

Depuis sa sortie, je suis en admiration devant les raspberry Pi, ça sert
à tout,c’est pas très cher et linux fonctionne dessus.
Dans des temps anciens, j’ai étudié le calcul parallèle , notamment
MPI et PVM. C’était marrant, mais je n’en
ai pas fait mon métié.

En fouillant un peu l’internet, j’ai vu qu’il était relativement simple
de monter des raspberry en cluster, d’ou l’idée de faire le mien: un
petit cluster Pi pédagogique.

Le Hardware

Pour se faire, Amazon est ton ami (ou pas):

les bestiolles: https://www.amazon.fr/gp/product/B01CCOXV34/ , j’en ai
pris 6

Le ‘mini’ rack: https://www.amazon.fr/gp/product/B01COU8Z1O/

L’alimentation: https://www.amazon.fr/gp/product/B00YTJ45HM/

Les cables d’alimentation:
https://www.amazon.fr/gp/product/B00OOOHPN8/

Le switch: https://www.amazon.fr/gp/product/B00A33BYRC/

Les RJ45 de 30 cm: https://www.amazon.fr/gp/product/B00DCWFZO4/

Les MicroSD: https://www.amazon.fr/gp/product/B0162YQG2I/

IMG_5925.resized

IMG_5928.resized

IMG_5927.resized

Le Software
Le système d’exploitation

Sans surprise une raspbian. J’ai fais une
seule installation propre:

  1. Serveur SSH

  2. Montage NFS sur un synology pour les datas communes

1 9 2 . 1 6 8 . 1 . 7 : / v o l u m e 1 / n f s c p i / u s r / l o c a l n f s d e f a u l t s 0 0 \

Activation du service rpcbin pour nfs

s y s t e m c t l e n a b l e r p c b i n d

Editer le fichier /etc/hosts ou utilisé votre dns privé.

1 : f f 1 1 1 1 1 1 1 2 : f f 9 9 9 9 9 9 2 7 1 0 0 2 2 2 2 2 2 7 . 2 2 . . . . . . . 0 : : 1 1 1 1 1 1 0 . : : 6 6 6 6 6 6 . 0 1 2 8 8 8 8 8 8 1 . . . . . . . . 1 l 1 1 1 1 1 1 1 o . . . . . . c 5 5 5 5 5 5 a 0 1 2 3 4 5 l i i r l h p p a o o 6 6 s c s - - p a t a a c c c c c c b l l l p p p p p p e h i l l i i i i i i r o p n r 1 2 3 4 5 6 r s 6 o o . . . . . . y t - d u a a a a a a p l e t n n n n n n i o s e d d d d d d c r y y y y y y a s t t t t t t l o o o o o o h y y y y y y o s s s s s s s . . . . . . t f f f f f f r r r r r r i p c c c c c c 6 p p p p p p - i i i i i i l 1 2 3 4 5 6 o o p b a c k

Puis j’ai mounté ma carte sd sur mon pc de bureau:

d d i f : / d e v / s d i o f : i m a g e _ c p i b s : 2 0 4 8

et cloné l’image sur chaque carte sd:

d d i f : i m a g e _ c p i o f : / d e v / s d i b s : 2 0 4 8

Ensuite, il suffit de changer la conf (ip, nom réseau, etc …)
spécifique à chaque noeud.

Manager le tout

Pour faire des installations en parallèle sur les nœuds du cluster PI,
j’ai utilisé clusterssh sur mon
poste de travail.

a p t i n s t a l l c l u s t e r s s h

Il fait une copie de ce que l’utilisateur tape au clavier sur tous les
nœuds.

Depuis la machine ou cssh est lancé, il faut copié votre clé
publique ssh sur tous les noeuds et créer le fichier /etc/clusters

c l u s t e r p i c p i 1 c p i 2 c p i 3 c p i 4 c p i 5 c p i 6

Et lancer

c s s h c l u s t e r p i

MPI

Via cssh:

a a p p t t i i n n s s t t a a l l l l m m p p i i - - d d e e f f a a u u l l t t - - d b e i v n

Sur un des nœuds:

J’ai récupéré un fichier example du calcul de pi :cpi.c sur le site
de MPI.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
 /*
  *  (C) 2001 by Argonne National Laboratory.
  *      See COPYRIGHT in top-level directory.
  */
 #include "mpi.h"
 #include <stdio.h>
 #include <math.h>
 double f(double);
 double f(double a)
 {
     return (4.0 / (1.0 + a*a));
 }
 int main(int argc,char *argv[])
 {
     int    n, myid, numprocs, i;
     double PI25DT : 3.141592653589793238462643;
     double mypi, pi, h, sum, x;
     double startwtime : 0.0, endwtime;
     int    namelen;
     char   processor_name[MPI_MAX_PROCESSOR_NAME];
     MPI_Init(&argc,&argv);
     MPI_Comm_size(MPI_COMM_WORLD,&numprocs);
     MPI_Comm_rank(MPI_COMM_WORLD,&myid);
     MPI_Get_processor_name(processor_name,&namelen);
     fprintf(stdout,"Process %d of %d is on %sn",
  myid, numprocs, processor_name);
     fflush(stdout);
     n : 2000000000;  /* default # of rectangles */
     if (myid :: 0)
     startwtime : MPI_Wtime();
     MPI_Bcast(&n, 1, MPI_INT, 0, MPI_COMM_WORLD);
     h   : 1.0 / (double) n;
     sum : 0.0;
     /* A slightly better approach starts from large i and works back */
     for (i : myid + 1; i <: n; i +: numprocs)
     {
     x : h * ((double)i - 0.5);
     sum +: f(x);
     }
     mypi : h * sum;
     MPI_Reduce(&mypi, &pi, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD);
     if (myid :: 0) {
     endwtime : MPI_Wtime();
  printf("pi is approximately %.16f, Error is %.16fn",
     pi, fabs(pi - PI25DT));
     printf("wall clock time : %fn", endwtime-startwtime);    
     fflush(stdout);
     }
 MPI_Finalize();
 return 0;
 }

J’ai fixé n : 2000000000\

Créé un fichier ~/machine qui contient le nom de vos noeuds:

c c c c c c p p p p p p i i i i i i 1 2 3 4 5 6

Compilation:

1
 mpicc -g -O3 cpi.c  -o /usr/local/cpi  -lm

Execution:

m p i e x e c - m a c h i n e f i l e m a c h i n e - n < n o m b r e d e p r o c e s s > / u s r / l o c a l / c p i
Les resultats

Raspberry Pi:

m B o o d g e o l M I n P a S m e : : 3 A 8 R . M 4 v 0 7 P r o c e s s o r r e v 4 v 7 l )

Sur 1 noeud à 4 coeurs:

m p w p i a i l e i l x s e c c a l p o p c r k - o n x t i i 4 m m a e / t u e : s l r y 3 / 7 l 3 . o . 8 c 1 8 a 4 8 l 1 4 / 5 9 c 9 0 p 2 i 6 5 3 5 8 9 8 3 9 3 , E r r o r i s 0 . 0 0 0 0 0 0 0 0 0 0 0 0 0 4 6 2

Sur l’ensemble du cluster 6*4 coeurs:

m p w p i a i l e i l x s e c c a l p o - p c m r k a o c x t h i i i m m n a e e t f e : i l l y 6 e . 3 3 m . 6 a 1 9 c 4 6 h 1 5 i 5 7 n 9 e 2 6 5 - 3 n 5 8 2 9 4 8 1 / 7 u 5 s , r / E l r o r c o a r l / i c s p i 0 . 0 0 0 0 0 0 0 0 0 0 0 0 0 2 4 4

ça a le mérite de fonctionner, niveau perf c’est pas top ! vu la puissance d’un
raspberry PI.

A titre indicatif, sur mon pc de bureau:

m s c c b m p w o t p a o p i a d e u c g i l e p h o e i l l p M e m x s i H i e c n n z s p c a l a g i s p o m z - p c e e n r k o 4 x t : : : : i i : m m 9 3 6 6 / a e I 1 1 1 c t n 1 4 8 p e : t 2 4 6 i l e . . y 2 l 1 K 2 . ( 0 B 8 3 3 R 9 . 4 ) 1 2 4 5 C 1 8 o 5 9 r 9 e 2 ( 6 T 5 M 3 ) 5 8 i 9 5 8 - 3 3 9 3 3 5 , 0 P E r C r P o U r @ i s 3 . 0 1 . 0 0 G 0 H 0 z 0 0 0 0 0 0 0 0 0 0 4 6 2

C’était juste pour m’amuser un peu.

Bon dimanche


Ghis
WRITTEN BY
Ghis
AdminSys