Skip to content
Snippets Groups Projects
Select Git revision
  • bcdd84c0f53ad0f6e262d8c2d45502f4229e04b3
  • master default
  • clement
  • fix_requirements
  • new_signup
  • interface_admin
  • hamza
  • dev
  • test
  • melissa
  • context_sheet
  • sorties_new
  • Seon82-patch-2
  • export_bdd
  • refactor/participation-user-link
15 results

serializers.py

  • main.c 2.36 KiB
    #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;
    }