diff --git a/exercice_bcast_Nicolas_FLEY/execution.png b/exercice_bcast_Nicolas_FLEY/execution.png deleted file mode 100644 index 8deec2296c65f13dad1a6a8357f9278648296117..0000000000000000000000000000000000000000 Binary files a/exercice_bcast_Nicolas_FLEY/execution.png and /dev/null differ diff --git a/exercice_bcast_Nicolas_FLEY/mpi_bcast.c b/exercice_bcast_Nicolas_FLEY/mpi_bcast.c deleted file mode 100644 index da46f20a0ef8b6916074a65df903c3036daf5e31..0000000000000000000000000000000000000000 --- a/exercice_bcast_Nicolas_FLEY/mpi_bcast.c +++ /dev/null @@ -1,35 +0,0 @@ -#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 deleted file mode 100644 index d08a2d1cf05af6e5765ece042ef95374e4f4a83a..0000000000000000000000000000000000000000 --- a/exercice_bcast_Nicolas_FLEY/mpi_bcast_log.c +++ /dev/null @@ -1,77 +0,0 @@ -#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/prod_mat_vec/main.c b/prod_mat_vec/main.c new file mode 100644 index 0000000000000000000000000000000000000000..e8fd89df701968c88e0d284c69ed3b99ed9e6fd9 --- /dev/null +++ b/prod_mat_vec/main.c @@ -0,0 +1,43 @@ +#include <stdio.h> +#include <mpi.h> + +/* +Commands : +cd 'B:\Mes Documents\progra\calcInt\' +C:\MPICH2\bin\mpiexec.exe -localonly 10 +*/ + +/* +* The reference book says we should use all_gather and all_gatherv to make all the processor +* access the x vector. BUT, x isn't going to be modified in the process. Moreover +* the website http://mpitutorial.com say that MPI_Allgather should be used "only" +* if all the processes contains a part of the data and EACH ONE want the entire data +* dispatched through the processes. +* This image :http://mpitutorial.com/tutorials/mpi-scatter-gather-and-allgather/allgather.png +* Show this point. +* More over according to the problematic given MPI_Scatter and MPI_Gather seems to be +* more usable in this specific context of a dense matrix vector product. +* +* Moreover, it is said that we should use allgatherv to get the final matrix but, if we consider +* this stackoverflow answer : +* http://stackoverflow.com/questions/15049190/difference-between-mpi-allgather-and-mpi-alltoall-functions#answer-34113431 +* We see that using all gatherv will, more than duplicate the data through each processor. +* Using gather seems more appropriated. +*/ + +int main (int argc, char *argv[]) { + int rank, size; + MPI_Status status; + + int test=0; + + MPI_Init (&argc, &argv); /* starts MPI */ + + MPI_Comm_rank(MPI_COMM_WORLD, &rank); /* get current process id */ + MPI_Comm_size(MPI_COMM_WORLD, &size); /* get number of processes */ + + MPI_Send(&test,1,MPI_DOUBLE,0,10,MPI_COMM_WORLD); + MPI_Recv(&test,1,MPI_DOUBLE,0,10,MPI_COMM_WORLD,&status); + + MPI_Finalize(); +} diff --git a/prod_mat_vec/prod_mat_vec.cbp b/prod_mat_vec/prod_mat_vec.cbp new file mode 100644 index 0000000000000000000000000000000000000000..685b6583da3e7631a468db11516b8b04b1d5ad26 --- /dev/null +++ b/prod_mat_vec/prod_mat_vec.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="prod_mat_vec" /> + <Option pch_mode="2" /> + <Option compiler="gcc" /> + <Build> + <Target title="Debug"> + <Option output="bin/Debug/prod_mat_vec" 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/prod_mat_vec" 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>