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.
/* -*- 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>doublef(double);doublef(doublea){return(4.0/(1.0+a*a));}intmain(intargc,char*argv[]){intn,myid,numprocs,i;doublePI25DT:3.141592653589793238462643;doublemypi,pi,h,sum,x;doublestartwtime:0.0,endwtime;intnamelen;charprocessor_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();return0;}
J’ai fixé n : 2000000000\
Créé un fichier ~/machine qui contient le nom de vos noeuds:
Compilation:
1
mpicc -g -O3 cpi.c -o /usr/local/cpi -lm
Execution:
Les resultats
Raspberry Pi:
Sur 1 noeud à 4 coeurs:
Sur l’ensemble du cluster 6*4 coeurs:
ça a le mérite de fonctionner, niveau perf c’est pas top ! vu la puissance d’un
raspberry PI.