diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..0b94922115a24e09fda2e96b429a59457089b239 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +rapports/* diff --git a/exercice_bcast_Nicolas_FLEY/execution.png b/exercice_bcast_Nicolas_FLEY/execution.png new file mode 100644 index 0000000000000000000000000000000000000000..8deec2296c65f13dad1a6a8357f9278648296117 Binary files /dev/null and b/exercice_bcast_Nicolas_FLEY/execution.png differ diff --git a/exercice_bcast_Nicolas_FLEY/mpi_bcast.c b/exercice_bcast_Nicolas_FLEY/mpi_bcast.c new file mode 100644 index 0000000000000000000000000000000000000000..da46f20a0ef8b6916074a65df903c3036daf5e31 --- /dev/null +++ b/exercice_bcast_Nicolas_FLEY/mpi_bcast.c @@ -0,0 +1,35 @@ +#include <stdio.h> +#include <mpi.h> + +/* +Commands : +cd 'B:\Mes Documents\progra\calcInt\' +C:\MPICH2\bin\mpiexec.exe -localonly 10 +*/ + +int main (int argc, char *argv[]) { + int rank, size; + MPI_Status status; + + int test=0; + int message_to_send=7; + + MPI_Init (&argc, &argv); /* starts MPI */ + + if(argc==2){ + message_to_send = atoi(argv[1]); + } + + MPI_Comm_rank(MPI_COMM_WORLD, &rank); /* get current process id */ + MPI_Comm_size(MPI_COMM_WORLD, &size); /* get number of processes */ + + if(rank==0){ + for(int i=1;i!=size;i++) + MPI_Send(&message_to_send,1,MPI_INT,i,10,MPI_COMM_WORLD); + }else{ + MPI_Recv(&message_to_send,1,MPI_INT,0,10,MPI_COMM_WORLD,&status); + printf("%d received by %d\n",message_to_send,rank); + } + + MPI_Finalize(); +} diff --git a/exercice_bcast_Nicolas_FLEY/mpi_bcast_log.c b/exercice_bcast_Nicolas_FLEY/mpi_bcast_log.c new file mode 100644 index 0000000000000000000000000000000000000000..d08a2d1cf05af6e5765ece042ef95374e4f4a83a --- /dev/null +++ b/exercice_bcast_Nicolas_FLEY/mpi_bcast_log.c @@ -0,0 +1,77 @@ +#include <stdio.h> +#include <mpi.h> +#include <math.h> + +/* +Commands : +cd 'B:\Mes Documents\progra\calcInt\' +C:\MPICH2\bin\mpiexec.exe -localonly 10 +*/ + +// explications given at the bottom of this file +int whoSendNext(int loop,int rank); // to know who to send next +int whoSendBef(int rank); // to know who send the message to the process + +int main (int argc, char *argv[]) { + int rank, size, next, numLoopRecv; + MPI_Status status; + + int test=0; + int message_to_send=7; + int numLoop=1; + + MPI_Init (&argc, &argv); /* starts MPI */ + + if(argc==2){ + message_to_send = atoi(argv[1]); + } +/* + for(int i=1;i!=10;i++){ + numLoopRecv=((int)(log2((double)i)+2.01)); + printf("###\n numLoopRecv : %d\n",numLoopRecv); + printf("\nrank %d wait for %d\n",i,whoSendBef(numLoopRecv,i)); + printf("\nrank %d send for %d\n",i,whoSendNext(numLoopRecv,i)); + } + return 0; +*/ + MPI_Comm_rank(MPI_COMM_WORLD, &rank); /* get current process id */ + MPI_Comm_size(MPI_COMM_WORLD, &size); /* get number of processes */ + + int numMaxLoop=((int)log2((double)size)+2.01); // get the rank of the final loop + + if(!(rank==0 && numLoop==1)){ + numLoop=((int)(log2((double)rank)+2.01)); // get the rank of the loop it will be when the process will receive the message + printf("%d wait for reception from %d\n",rank,whoSendBef(numLoopRecv,rank)); + MPI_Recv(&message_to_send,1,MPI_INT,whoSendBef(numLoop,rank),10,MPI_COMM_WORLD,&status); + } + while(numLoop<=numMaxLoop){ + next=whoSendNext(numLoop,rank); + if(next<size){ // will stop broadcast when all process have been reached + printf("%d wait for a sending to %d\n",rank,next); + MPI_Send(&message_to_send,1,MPI_INT,whoSendNext(numLoop,rank),10,MPI_COMM_WORLD); + } + numLoop+=1; + } + MPI_Finalize(); +} + +/* +* Logic used is : +* (turn : 1 2 3 4) +* 0 will send to 1 then 2 then 4 then 8 +* 1 will send to 3 then 5 then 9 +* 2 will send to 6 then 10 +* 3 will send to 7 then 11 +* ... +* n will send to ... n+2^(turn-1) then n+2^(turn) ... +*/ + + +int whoSendNext(int loop,int rank){ // OK + int inc=((int)(pow(2.0,((double)loop)-1.0)+0.01)); + return rank+inc; +} +int whoSendBef(int loop,int rank){ + int inc=((int)(pow(2.0,((int)log2((double)rank)+0.01))+0.01)); + return rank-inc; +} diff --git a/mpi_bcast/bin/Debug/mpi_bcast.exe b/mpi_bcast/bin/Debug/mpi_bcast.exe new file mode 100644 index 0000000000000000000000000000000000000000..654f15b8131563666fdd460a1d6ff1e2635e8add Binary files /dev/null and b/mpi_bcast/bin/Debug/mpi_bcast.exe differ diff --git a/mpi_bcast/main.c b/mpi_bcast/main.c new file mode 100644 index 0000000000000000000000000000000000000000..da46f20a0ef8b6916074a65df903c3036daf5e31 --- /dev/null +++ b/mpi_bcast/main.c @@ -0,0 +1,35 @@ +#include <stdio.h> +#include <mpi.h> + +/* +Commands : +cd 'B:\Mes Documents\progra\calcInt\' +C:\MPICH2\bin\mpiexec.exe -localonly 10 +*/ + +int main (int argc, char *argv[]) { + int rank, size; + MPI_Status status; + + int test=0; + int message_to_send=7; + + MPI_Init (&argc, &argv); /* starts MPI */ + + if(argc==2){ + message_to_send = atoi(argv[1]); + } + + MPI_Comm_rank(MPI_COMM_WORLD, &rank); /* get current process id */ + MPI_Comm_size(MPI_COMM_WORLD, &size); /* get number of processes */ + + if(rank==0){ + for(int i=1;i!=size;i++) + MPI_Send(&message_to_send,1,MPI_INT,i,10,MPI_COMM_WORLD); + }else{ + MPI_Recv(&message_to_send,1,MPI_INT,0,10,MPI_COMM_WORLD,&status); + printf("%d received by %d\n",message_to_send,rank); + } + + MPI_Finalize(); +} diff --git a/mpi_bcast/mpi_bcast.cbp b/mpi_bcast/mpi_bcast.cbp new file mode 100644 index 0000000000000000000000000000000000000000..0fa26058a61867fba8c98b941a531f5fb4981672 --- /dev/null +++ b/mpi_bcast/mpi_bcast.cbp @@ -0,0 +1,43 @@ +<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> +<CodeBlocks_project_file> + <FileVersion major="1" minor="6" /> + <Project> + <Option title="mpi_bcast" /> + <Option pch_mode="2" /> + <Option compiler="gcc" /> + <Build> + <Target title="Debug"> + <Option output="bin/Debug/mpi_bcast" prefix_auto="1" extension_auto="1" /> + <Option object_output="obj/Debug/" /> + <Option type="1" /> + <Option compiler="gcc" /> + <Compiler> + <Add option="-g" /> + </Compiler> + </Target> + <Target title="Release"> + <Option output="bin/Release/mpi_bcast" prefix_auto="1" extension_auto="1" /> + <Option object_output="obj/Release/" /> + <Option type="1" /> + <Option compiler="gcc" /> + <Compiler> + <Add option="-O2" /> + </Compiler> + <Linker> + <Add option="-s" /> + </Linker> + </Target> + </Build> + <Compiler> + <Add option="-Wall" /> + </Compiler> + <Unit filename="main.c"> + <Option compilerVar="CC" /> + </Unit> + <Extensions> + <code_completion /> + <envvars /> + <debugger /> + </Extensions> + </Project> +</CodeBlocks_project_file> diff --git a/mpi_bcast/obj/Debug/main.o b/mpi_bcast/obj/Debug/main.o new file mode 100644 index 0000000000000000000000000000000000000000..a69a3553befa11a2edd9de6a9843336cbe98a1df Binary files /dev/null and b/mpi_bcast/obj/Debug/main.o differ diff --git a/mpi_bcast_log/bin/Debug/mpi_bcast_log.exe b/mpi_bcast_log/bin/Debug/mpi_bcast_log.exe new file mode 100644 index 0000000000000000000000000000000000000000..2347e75675e3a85a4cac60baf7ea8991e0116ba9 Binary files /dev/null and b/mpi_bcast_log/bin/Debug/mpi_bcast_log.exe differ diff --git a/mpi_bcast_log/execution.png b/mpi_bcast_log/execution.png new file mode 100644 index 0000000000000000000000000000000000000000..8deec2296c65f13dad1a6a8357f9278648296117 Binary files /dev/null and b/mpi_bcast_log/execution.png differ diff --git a/mpi_bcast_log/main.c b/mpi_bcast_log/main.c new file mode 100644 index 0000000000000000000000000000000000000000..d08a2d1cf05af6e5765ece042ef95374e4f4a83a --- /dev/null +++ b/mpi_bcast_log/main.c @@ -0,0 +1,77 @@ +#include <stdio.h> +#include <mpi.h> +#include <math.h> + +/* +Commands : +cd 'B:\Mes Documents\progra\calcInt\' +C:\MPICH2\bin\mpiexec.exe -localonly 10 +*/ + +// explications given at the bottom of this file +int whoSendNext(int loop,int rank); // to know who to send next +int whoSendBef(int rank); // to know who send the message to the process + +int main (int argc, char *argv[]) { + int rank, size, next, numLoopRecv; + MPI_Status status; + + int test=0; + int message_to_send=7; + int numLoop=1; + + MPI_Init (&argc, &argv); /* starts MPI */ + + if(argc==2){ + message_to_send = atoi(argv[1]); + } +/* + for(int i=1;i!=10;i++){ + numLoopRecv=((int)(log2((double)i)+2.01)); + printf("###\n numLoopRecv : %d\n",numLoopRecv); + printf("\nrank %d wait for %d\n",i,whoSendBef(numLoopRecv,i)); + printf("\nrank %d send for %d\n",i,whoSendNext(numLoopRecv,i)); + } + return 0; +*/ + MPI_Comm_rank(MPI_COMM_WORLD, &rank); /* get current process id */ + MPI_Comm_size(MPI_COMM_WORLD, &size); /* get number of processes */ + + int numMaxLoop=((int)log2((double)size)+2.01); // get the rank of the final loop + + if(!(rank==0 && numLoop==1)){ + numLoop=((int)(log2((double)rank)+2.01)); // get the rank of the loop it will be when the process will receive the message + printf("%d wait for reception from %d\n",rank,whoSendBef(numLoopRecv,rank)); + MPI_Recv(&message_to_send,1,MPI_INT,whoSendBef(numLoop,rank),10,MPI_COMM_WORLD,&status); + } + while(numLoop<=numMaxLoop){ + next=whoSendNext(numLoop,rank); + if(next<size){ // will stop broadcast when all process have been reached + printf("%d wait for a sending to %d\n",rank,next); + MPI_Send(&message_to_send,1,MPI_INT,whoSendNext(numLoop,rank),10,MPI_COMM_WORLD); + } + numLoop+=1; + } + MPI_Finalize(); +} + +/* +* Logic used is : +* (turn : 1 2 3 4) +* 0 will send to 1 then 2 then 4 then 8 +* 1 will send to 3 then 5 then 9 +* 2 will send to 6 then 10 +* 3 will send to 7 then 11 +* ... +* n will send to ... n+2^(turn-1) then n+2^(turn) ... +*/ + + +int whoSendNext(int loop,int rank){ // OK + int inc=((int)(pow(2.0,((double)loop)-1.0)+0.01)); + return rank+inc; +} +int whoSendBef(int loop,int rank){ + int inc=((int)(pow(2.0,((int)log2((double)rank)+0.01))+0.01)); + return rank-inc; +} diff --git a/mpi_bcast_log/mpi_bcast_log.cbp b/mpi_bcast_log/mpi_bcast_log.cbp new file mode 100644 index 0000000000000000000000000000000000000000..20e7faf0555cf5118778b12565a6d34fff7fb4f0 --- /dev/null +++ b/mpi_bcast_log/mpi_bcast_log.cbp @@ -0,0 +1,43 @@ +<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> +<CodeBlocks_project_file> + <FileVersion major="1" minor="6" /> + <Project> + <Option title="mpi_bcast_log" /> + <Option pch_mode="2" /> + <Option compiler="gcc" /> + <Build> + <Target title="Debug"> + <Option output="bin/Debug/mpi_bcast_log" prefix_auto="1" extension_auto="1" /> + <Option object_output="obj/Debug/" /> + <Option type="1" /> + <Option compiler="gcc" /> + <Compiler> + <Add option="-g" /> + </Compiler> + </Target> + <Target title="Release"> + <Option output="bin/Release/mpi_bcast_log" prefix_auto="1" extension_auto="1" /> + <Option object_output="obj/Release/" /> + <Option type="1" /> + <Option compiler="gcc" /> + <Compiler> + <Add option="-O2" /> + </Compiler> + <Linker> + <Add option="-s" /> + </Linker> + </Target> + </Build> + <Compiler> + <Add option="-Wall" /> + </Compiler> + <Unit filename="main.c"> + <Option compilerVar="CC" /> + </Unit> + <Extensions> + <code_completion /> + <envvars /> + <debugger /> + </Extensions> + </Project> +</CodeBlocks_project_file> diff --git a/mpi_bcast_log/mpi_bcast_log.depend b/mpi_bcast_log/mpi_bcast_log.depend new file mode 100644 index 0000000000000000000000000000000000000000..8580fae2a2ee336c803581b071bca7912a74718d --- /dev/null +++ b/mpi_bcast_log/mpi_bcast_log.depend @@ -0,0 +1,6 @@ +# depslib dependency file v1.0 +1487791165 source:b:\mes documents\progra\calcint\mpi_bcast_log\main.c + <stdio.h> + <mpi.h> + <math.h> + diff --git a/mpi_bcast_log/obj/Debug/main.o b/mpi_bcast_log/obj/Debug/main.o new file mode 100644 index 0000000000000000000000000000000000000000..71b52757c4fccfd537a192f76f1e820b5b05af5d Binary files /dev/null and b/mpi_bcast_log/obj/Debug/main.o differ diff --git a/pi/bin/Debug/pi.exe b/pi/bin/Debug/pi.exe index b224e83c584d6d502308f7cc7c58d75c9c09d203..14d350794a73c4484820bd0b9eae87615d32aa0f 100644 Binary files a/pi/bin/Debug/pi.exe and b/pi/bin/Debug/pi.exe differ diff --git a/pi/main.c b/pi/main.c index f974d96f70fcc268ca51d1d28b529b77ee46d4e7..654b845feea11d86f4c622894d269f2beeb84612 100644 --- a/pi/main.c +++ b/pi/main.c @@ -1,15 +1,31 @@ #include <stdio.h> #include <mpi.h> +#include <time.h> + +#define PI 3.14159265359 double sequential(int bnTrap); double sequential_boucle(int bnTrap, int nbBoucle); -double parralele(int nbTrap); +double f(double x); int main (int argc, char *argv[]) { - //printf("pi = %f\n",sequential(100)); - //printf("pi= %f\n",sequential_boucle(100,10)); - MPI_Init (&argc, &argv); /* starts MPI */ - printf("pi= %f\n",parralele(1000)); + clock_t begin,end = clock(); + printf("pi_seq = %f\n",sequential(10000)); + printf("pi_bouc = %f\n",sequential_boucle(10000,10)); + /*printf("sequential version\n"); + for(int i=1;i!=33554432*8;i*=2){ + begin = clock(); + printf("%d,%.10f,",i,sequential(i)-PI); + end = clock(); + printf("%f\n",(double)(end-begin)/CLOCKS_PER_SEC); + } + printf("sequential ready for parallelisation version\n"); + for(int i=1;i!=33554432*8;i*=2){ + begin = clock(); + printf("%d,%.10f,",i,sequential_boucle(i,10)-PI); + end = clock(); + printf("%.10f\n",(double)(end-begin)/CLOCKS_PER_SEC); + }*/ return 0; } @@ -55,46 +71,3 @@ double sequential_boucle(int nbTrap, int nbBoucle){ } return sum/nbTrap_d/2.0; // reduction } - -double parralele(int nbTrap){ - /* - * Version sequentielle du probleme, appel de n processus calculant une partie - * de l'int�grale d�finie pr�cedemment. Puis renvoie au master (rank==0) qui - * agr�ge tout �a. - */ - // les variables - int rank, size, nbProcess; - double pi_esc,nbProcess_f,h; - MPI_Status status; - - double sum=0; - - // recuperation pour chaque process de son numero et du nombre de process - MPI_Comm_rank(MPI_COMM_WORLD, &rank); /* get current process id */ - MPI_Comm_size(MPI_COMM_WORLD, &size); /* get number of processes */ - - - nbProcess=size-1; - nbProcess_f=(double)size-1.0; - h=1.0/(double)nbTrap; - - if(rank==0){ - printf("\nexecuted with %f processes",nbProcess_f); - for(int i=1;i!=nbProcess+1;i++){ - MPI_Recv(&pi_esc,1,MPI_DOUBLE,i,10,MPI_COMM_WORLD,&status); - printf("\nrecu proc %d = %f",i,pi_esc); - sum+=pi_esc; - } - return sum; - }else{ - double b=(double)rank-1.0; - pi_esc=0; - for(double i=b/nbProcess_f;i<(b+1.0)/nbProcess_f;i+=h){ // s�paration en boucle - pi_esc+=(f(i)+f((i+h))); //somme - } - pi_esc=pi_esc/((double)nbTrap)/2.0; - MPI_Send(&pi_esc,1,MPI_DOUBLE,0,10,MPI_COMM_WORLD); - printf("\nsent proc %d = %f",rank,pi_esc); - } - MPI_Finalize(); -} diff --git a/pi/obj/Debug/main.o b/pi/obj/Debug/main.o index c24005c6db919bf38658415a3c8eada19f5a7fe2..799df3a4d549d5d8cbda33672c857018595222c5 100644 Binary files a/pi/obj/Debug/main.o and b/pi/obj/Debug/main.o differ diff --git a/pi/pi.cbp b/pi/pi.cbp index aca9352d87cdd405f770ab53522ce42402497632..f5aa4c30d2d4d10ea702ad86a04bc5d36e262eaf 100644 --- a/pi/pi.cbp +++ b/pi/pi.cbp @@ -31,6 +31,9 @@ <Compiler> <Add option="-Wall" /> </Compiler> + <Unit filename="main.c"> + <Option compilerVar="CC" /> + </Unit> <Extensions> <code_completion /> <envvars /> diff --git a/pi/pi.depend b/pi/pi.depend index a8680cc0b7f129596e9005fe7e0b9dc4caa8d464..763fba5e4680b42219d48f6b2aeb0e681bae4604 100644 --- a/pi/pi.depend +++ b/pi/pi.depend @@ -1,5 +1,6 @@ # depslib dependency file v1.0 -1487185591 source:b:\mes documents\progra\calcint\pi\main.c +1487441616 source:b:\mes documents\progra\calcint\pi\main.c <stdio.h> <mpi.h> + <time.h> diff --git a/pi/pi.layout b/pi/pi.layout new file mode 100644 index 0000000000000000000000000000000000000000..a8da28c6f1ad07a656180190e03aa251586a0375 --- /dev/null +++ b/pi/pi.layout @@ -0,0 +1,10 @@ +<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> +<CodeBlocks_layout_file> + <FileVersion major="1" minor="0" /> + <ActiveTarget name="Debug" /> + <File name="main.c" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> + <Cursor> + <Cursor1 position="366" topLine="1" /> + </Cursor> + </File> +</CodeBlocks_layout_file> diff --git a/pi_parallele/bin/Debug/hello.txt b/pi_parallele/bin/Debug/hello.txt new file mode 100644 index 0000000000000000000000000000000000000000..46b134b197f35e75e0784bedbf94a8dd124693b1 --- /dev/null +++ b/pi_parallele/bin/Debug/hello.txt @@ -0,0 +1 @@ +�� \ No newline at end of file diff --git a/pi_parallele/bin/Debug/out.csv b/pi_parallele/bin/Debug/out.csv new file mode 100644 index 0000000000000000000000000000000000000000..b151465fc3c2580f8d1d7f1951ded5cb2ca628d2 Binary files /dev/null and b/pi_parallele/bin/Debug/out.csv differ diff --git a/pi_parallele/bin/Debug/out_format.csv b/pi_parallele/bin/Debug/out_format.csv new file mode 100644 index 0000000000000000000000000000000000000000..843f7234aa64efdf1bd80200f0aca3c71a0550f4 --- /dev/null +++ b/pi_parallele/bin/Debug/out_format.csv @@ -0,0 +1,80 @@ +1;1;3.0000000000;0.002776;0.002431;0.141592654 +10;1;3.3304237265;0.002009;0.002196;0.188831073 +100;1;3.1415759869;0.001905;0.002075;1.66667E-05 +1000;1;3.1415924869;0.001869;0.001889;1.6669E-07 +10000;1;3.1417926419;0.002281;0.002298;0.000199988 +100000;1;3.1416126535;0.010285;0.010284;1.99999E-05 +1000000;1;3.1415926536;0.087925;0.088176;1.02069E-11 +10000000;1;3.1415928537;1.140961;1.139678;2.0011E-07 +100000000;1;3.1415926525;5.324940;5.325038;1.08979E-09 +1000000000;1;3.1415926677;34.701836;34.701823;1.41102E-08 +1;2;5.2153846154;0.006529;0.003894;2.073791962 +10;2;3.3304237265;0.005165;0.002693;0.188831073 +100;2;3.1415759869;0.004253;0.002170;1.66667E-05 +1000;2;3.1415924869;0.004271;0.002381;1.6669E-07 +10000;2;3.1421126291;0.008948;0.004584;0.000519976 +100000;2;3.1416126535;0.012799;0.006542;1.99999E-05 +1000000;2;3.1415958536;0.093228;0.047666;3.20001E-06 +10000000;2;3.1415928537;0.868345;0.435831;2.0011E-07 +100000000;2;3.1415926842;6.394075;3.199627;3.06102E-08 +1000000000;2;3.1415926706;36.736932;18.371808;1.70102E-08 +1;3;7.4340271493;0.007434;0.003529;4.292434496 +10;3;3.6829139503;0.008974;0.003590;0.541321297 +100;3;3.1972215114;0.013877;0.005712;0.055628858 +1000;3;3.1471704815;0.009396;0.004194;0.005577828 +10000;3;3.1421505857;0.007247;0.002298;0.000557932 +100000;3;3.1416484483;0.012772;0.004561;5.57947E-05 +1000000;3;3.1415982331;0.080263;0.027466;5.57951E-06 +10000000;3;3.1415932116;0.695535;0.234731;5.5801E-07 +100000000;3;3.1415927087;5.239515;1.753341;5.51102E-08 +1000000000;3;3.1415926714;37.747754;12.595288;1.78102E-08 +1;4;9.6505330537;0.013621;0.005259;6.5089404 +10;4;3.7050355312;0.014594;0.004351;0.563442878 +100;4;3.1415759869;0.011950;0.003406;1.66667E-05 +1000;4;3.1415924869;0.013450;0.003456;1.6669E-07 +10000;4;3.1427450786;0.009154;0.002718;0.001152425 +100000;4;3.1416382534;0.018415;0.006033;4.55998E-05 +1000000;4;3.1415958536;0.087085;0.024931;3.20001E-06 +10000000;4;3.1415931097;0.764657;0.201757;4.5611E-07 +100000000;4;3.1415927225;5.604138;1.472857;6.89102E-08 +1000000000;4;3.1415926768;38.021392;9.976252;2.32102E-08 +1;6;14.0813431291;0.039416;0.009761;10.93975048 +10;6;3.7266329898;0.023265;0.004505;0.585040336 +100;6;3.2009102336;0.022945;0.006244;0.05931758 +1000;6;3.1475323650;0.033673;0.009349;0.005939711 +10000;6;3.1421867041;0.018921;0.004404;0.000594051 +100000;6;3.1416520594;0.024477;0.007387;5.94058E-05 +1000000;6;3.1415985942;0.092125;0.012077;5.94061E-06 +10000000;6;3.1415932477;0.844951;0.173682;5.9411E-07 +100000000;6;3.1415927125;7.321047;1.407685;5.89102E-08 +1000000000;6;3.1415926769;53.732456;11.679479;2.33102E-08 +1;8;18.5110474007;0.045141;0.007943;15.36945475 +10;8;4.8996238766;0.049804;0.008067;1.758031223 +100;8;3.2619236552;0.038501;0.008117;0.120331002 +1000;8;3.1415924869;0.046944;0.010776;1.6669E-07 +10000;8;3.1436099169;0.041878;0.007572;0.002017263 +100000;8;3.1417290566;0.036019;0.006105;0.000136403 +1000000;8;3.1415993604;0.104987;0.012333;6.70681E-06 +10000000;8;3.1415936238;0.848637;0.120166;9.7021E-07 +100000000;8;3.1415927973;7.806384;1.228098;1.4371E-07 +1000000000;8;3.1415926811;61.159385;10.033271;2.75102E-08 +1;10;22.9403083290;0.071704;0.015051;19.79871568 +10;10;3.9098408649;0.064018;0.008267;0.768248211 +100;10;3.1811388603;0.044410;0.006197;0.039546207 +1000;10;3.1415924869;0.050649;0.006728;1.6669E-07 +10000;10;3.1442364376;0.041320;0.005164;0.002643784 +100000;10;3.1417550040;0.043596;0.005375;0.00016235 +1000000;10;3.1416029716;0.149317;0.011670;1.0318E-05 +10000000;10;3.1415938811;0.947148;0.142293;1.22751E-06 +100000000;10;3.1415928346;9.240760;1.063860;1.8101E-07 +1000000000;10;3.1415926822;90.667657;10.553435;2.86102E-08 +1;16;36.2270924590;0.292378;0.031198;33.08549981 +10;16;4.9628498771;0.132403;0.011371;1.821257224 +100;16;3.5100587937;0.097368;0.009710;0.36846614 +1000;16;3.1662158996;0.081464;0.006791;0.024623246 +10000;16;3.1457257114;0.088637;0.010490;0.004133058 +100000;16;3.1418319868;0.099660;0.008354;0.000239333 +1000000;16;3.1416063619;0.186005;0.010593;1.37083E-05 +10000000;16;3.1415946531;1.171111;0.107072;1.99951E-06 +100000000;16;3.1415929062;11.861472;0.814359;2.5261E-07 +1000000000;16;3.1415926960;118.489029;9.503455;4.24102E-08 diff --git a/pi_parallele/bin/Debug/pi_parallele.exe b/pi_parallele/bin/Debug/pi_parallele.exe new file mode 100644 index 0000000000000000000000000000000000000000..12bc47a0736e1f9f1b38599d2a66fadb2d4ac048 Binary files /dev/null and b/pi_parallele/bin/Debug/pi_parallele.exe differ diff --git a/pi_parallele/bin/Debug/test.cmd b/pi_parallele/bin/Debug/test.cmd new file mode 100644 index 0000000000000000000000000000000000000000..674a7b9e4212d8d8d8257ecaf3f8b5b54b5312b9 --- /dev/null +++ b/pi_parallele/bin/Debug/test.cmd @@ -0,0 +1,2 @@ +for /l %%X in (1,1,25) do echo %%X +wait \ No newline at end of file diff --git a/pi_parallele/main.c b/pi_parallele/main.c new file mode 100644 index 0000000000000000000000000000000000000000..5b1d40ed501ca0c8f2ef3c5b95782de1536d43c2 --- /dev/null +++ b/pi_parallele/main.c @@ -0,0 +1,92 @@ +#include <stdio.h> +#include <mpi.h> + +#define PI 3.14159265359 + +/* +Commands : +cd 'B:\Mes Documents\progra\calcInt\' +C:\MPICH2\bin\mpiexec.exe -localonly 10 +*/ + +double f(double x); // la fonction � int�grer entre 0 et 1 + +int main (int argc, char *argv[]) { + /* + * Version parallele du probleme, appel de n processus calculant une partie + * de l'int�grale d�finie pr�cedemment. Puis renvoie au master (rank==0) qui + * agr�ge tout �a. + */ + // les variables + int rank, size, nbProcess; + double pi_esc,nbProcess_f,h,t1,t2,time; + MPI_Status status; + + double sum=0; + double sum_time=0; + + int nbTrap=-1; + + MPI_Init (&argc, &argv); /* starts MPI */ + + t1 = MPI_Wtime(); + // recuperation pour chaque process de son numero et du nombre de process + MPI_Comm_rank(MPI_COMM_WORLD, &rank); /* get current process id */ + MPI_Comm_size(MPI_COMM_WORLD, &size); /* get number of processes */ + + if(argc==2){ // si il y a un argument en plus du nom du programme, on r�cup�re le nombre + nbTrap=atoi(argv[1]); // renvoie zero si aucun nombre d�t�ct� en param�tres + if(rank==0) + //printf("%d trapeze will be used.\n",nbTrap); + ; + } + if(!(nbTrap>0)){ // si pas d'arguments ou argument erron� (atoi a renvoy� 0). + nbTrap=10000; + if(rank==0) + printf("No nb of trapeze given in parameters, a 10000 default value has been used.\n"); + } + + // g�n�ration des constantes. + nbProcess=size-1; + nbProcess_f=(double)size-1.0; + h=1.0/(double)nbTrap; + + if(rank==0){ + /* + * Le process de rang 0 est le maitre, il re�oit les calculs des autres processus, les esclaves. + * On aurait pu faire calculer le processus de rang 0 mais il est communement admis de garder un processus + * en tant que ma�tre (one ring to rule them all). + */ + printf("executed with %f slaves and 1 master\n",nbProcess_f); + for(int i=1;i!=nbProcess+1;i++){ // on re�oit les r�sultat des calculs des esclaves. + MPI_Recv(&pi_esc,1,MPI_DOUBLE,i,10,MPI_COMM_WORLD,&status); + printf("\nrecu proc %d = %f",i,pi_esc); // debug output + sum+=pi_esc; + } + for(int i=1;i!=nbProcess+1;i++){ // on re�oit les temps d'execution des esclaves et on calcul le "temps total" d'execution. + MPI_Recv(&time,1,MPI_DOUBLE,i,11,MPI_COMM_WORLD,&status); + sum_time+=time; + } + t2 = MPI_Wtime(); // le temps r�el d'execution du programme. + printf("###\npi_par = %f, delta = %f\n###\ntemps total : %f\ntemps reel : %f\n",sum,sum-PI,sum_time,t2-t1); // sortie format�e + //printf("%d,%d,%.10f,%f,%f\n",nbTrap,size,sum,sum_time,t2-t1); // sortie pour tableur + }else{ + double b=(double)rank-1.0;// on utilise b pour d�finir l'interval de l'integrale a calculer. + pi_esc=0; + for(double i=b/nbProcess_f;i<(b+1.0)/nbProcess_f;i+=h){ // s�paration en boucle + pi_esc+=(f(i)+f((i+h))); //somme + } + pi_esc=pi_esc/((double)nbTrap)/2.0; + //printf("sent proc %d = %f\n",rank,pi_esc); + MPI_Send(&pi_esc,1,MPI_DOUBLE,0,10,MPI_COMM_WORLD); + t2 = MPI_Wtime(); + time=t2 - t1; // calcul du temps d'execution de cette partie du programme. + MPI_Send(&time,1,MPI_DOUBLE,0,11,MPI_COMM_WORLD); // envoie au master du travail effectu�. + } + MPI_Finalize(); // terminaison de MPI + return 0; +} + +double f(double x){ + return 4.0/(1.0+x*x); +} diff --git a/pi_parallele/obj/Debug/main.o b/pi_parallele/obj/Debug/main.o new file mode 100644 index 0000000000000000000000000000000000000000..0381a5044e17b5270c2f32f9245f858de93570ac Binary files /dev/null and b/pi_parallele/obj/Debug/main.o differ diff --git a/pi_parallele/pi_parallele.cbp b/pi_parallele/pi_parallele.cbp new file mode 100644 index 0000000000000000000000000000000000000000..5a6c4d1aff45fb6cb9792123612383ce60d7d5d1 --- /dev/null +++ b/pi_parallele/pi_parallele.cbp @@ -0,0 +1,43 @@ +<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> +<CodeBlocks_project_file> + <FileVersion major="1" minor="6" /> + <Project> + <Option title="pi_parallele" /> + <Option pch_mode="2" /> + <Option compiler="gcc" /> + <Build> + <Target title="Debug"> + <Option output="bin/Debug/pi_parallele" prefix_auto="1" extension_auto="1" /> + <Option object_output="obj/Debug/" /> + <Option type="1" /> + <Option compiler="gcc" /> + <Compiler> + <Add option="-g" /> + </Compiler> + </Target> + <Target title="Release"> + <Option output="bin/Release/pi_parallele" prefix_auto="1" extension_auto="1" /> + <Option object_output="obj/Release/" /> + <Option type="1" /> + <Option compiler="gcc" /> + <Compiler> + <Add option="-O2" /> + </Compiler> + <Linker> + <Add option="-s" /> + </Linker> + </Target> + </Build> + <Compiler> + <Add option="-Wall" /> + </Compiler> + <Unit filename="main.c"> + <Option compilerVar="CC" /> + </Unit> + <Extensions> + <code_completion /> + <envvars /> + <debugger /> + </Extensions> + </Project> +</CodeBlocks_project_file> diff --git a/pi_parallele/pi_parallele.layout b/pi_parallele/pi_parallele.layout new file mode 100644 index 0000000000000000000000000000000000000000..8677c46e095827e591007b084f3b016eeeceffa5 --- /dev/null +++ b/pi_parallele/pi_parallele.layout @@ -0,0 +1,10 @@ +<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> +<CodeBlocks_layout_file> + <FileVersion major="1" minor="0" /> + <ActiveTarget name="Debug" /> + <File name="main.c" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> + <Cursor> + <Cursor1 position="1633" topLine="51" /> + </Cursor> + </File> +</CodeBlocks_layout_file> diff --git a/token/bin/Debug/token.exe b/token/bin/Debug/token.exe index f828e2c25de6537fca1c29a211f557e58fa7b7aa..623b909131ad59022785e5fc86f72e1d6ee75abb 100644 Binary files a/token/bin/Debug/token.exe and b/token/bin/Debug/token.exe differ diff --git a/token/main.c b/token/main.c index 0abc24b1257d93e69ca1b8cc0528cfc88b2eab3b..9bfc741c0b0d74d773ad8c815b979cb741c74a4c 100644 --- a/token/main.c +++ b/token/main.c @@ -1,43 +1,53 @@ #include <stdio.h> #include <mpi.h> -#define NUM_TURN 3 - int main (int argc, char *argv[]) { int rank,size; + int num_turn_max=0; int num_turn=0; int finished=0; int token=0; MPI_Status status; MPI_Init (&argc, &argv); /* starts MPI */ + + // r�cup�ration du nombre de tour, par d�faut 5 + if(argc==2){ + num_turn_max=atoi(argv[1]); + } + if(num_turn_max==0 || argc==0){ + num_turn_max=5; + } + // recuperation pour chaque process de son numero et du nombre de process MPI_Comm_rank(MPI_COMM_WORLD, &rank); /* get current process id */ MPI_Comm_size(MPI_COMM_WORLD, &size); /* get number of processes */ - while(finished==0){ + while(finished==0){ // le process rentre dans la boucle et y reste tant que le nombre de tour n'est pas atteint if(rank!=0){ MPI_Recv(&token,1,MPI_INT,rank-1,10,MPI_COMM_WORLD,&status); }else{ - if(num_turn>0){ + if(num_turn>0){ // au premier tour le process de rang 0 n'a rien � recevoir ! MPI_Recv(&token,1,MPI_INT,size-1,10,MPI_COMM_WORLD,&status); token+=size; + }else if(argc==1){ + printf("No argument given, 5 as been set as the default max turn."); // pour afficher qu'une seule fois le warning } } - token+=rank+1; + token+=rank+1; // on ajoute au token la valeur du rang actuel (en prenant en compte que le process 0 � la valeur 1) num_turn+=1; if(rank+1==size){ rank=-1; //printf("tour %d\n",num_turn); } - if(num_turn==NUM_TURN){ + if(num_turn==num_turn_max){ // si on a fait le bon nombre de tours on quit finished=1; } if(!(finished==1&&rank==-1)) MPI_Send(&token,1,MPI_INT,rank+1,10,MPI_COMM_WORLD); - else - printf("\nresult : %d\nresult should be : %d\n",token,size*NUM_TURN*(size+1)/2); + else // affichage du r�sultat si rang 0 et dernier tour finit ! + printf("\nnumber of turn : %d\nresult : %d\nresult should be : %d\n",num_turn_max,token,size*num_turn_max*(size+1)/2); } MPI_Finalize(); diff --git a/token/main.h b/token/main.h deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/token/obj/Debug/main.o b/token/obj/Debug/main.o index 04756ef1eef401124520b0c88acc0b3f38b405ab..2f442fa451036f49d382e2af16fc81fa258f840c 100644 Binary files a/token/obj/Debug/main.o and b/token/obj/Debug/main.o differ diff --git a/token/token.cbp b/token/token.cbp index 08763a145254389386deb547bd40cd2ff77bde87..1f7a125d7ac208fa681666052b7428c741db3c2e 100644 --- a/token/token.cbp +++ b/token/token.cbp @@ -31,6 +31,9 @@ <Compiler> <Add option="-Wall" /> </Compiler> + <Unit filename="main.c"> + <Option compilerVar="CC" /> + </Unit> <Extensions> <code_completion /> <envvars /> diff --git a/token/token.depend b/token/token.depend index c1bbe51391dcfa3d48a64d6354d98b26c04937b2..98f2891ecc5f788a0d4d3b58482f275e1ca2ae89 100644 --- a/token/token.depend +++ b/token/token.depend @@ -1,4 +1,5 @@ # depslib dependency file v1.0 -1487277599 source:b:\mes documents\progra\calcint\token\main.c +1487325302 source:b:\mes documents\progra\calcint\token\main.c + <stdio.h> <mpi.h> diff --git a/token/token.layout b/token/token.layout new file mode 100644 index 0000000000000000000000000000000000000000..ade592a292746b974261c13178551c7ab3dd4a55 --- /dev/null +++ b/token/token.layout @@ -0,0 +1,10 @@ +<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> +<CodeBlocks_layout_file> + <FileVersion major="1" minor="0" /> + <ActiveTarget name="Debug" /> + <File name="main.c" open="1" top="1" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> + <Cursor> + <Cursor1 position="1842" topLine="34" /> + </Cursor> + </File> +</CodeBlocks_layout_file>