LCOV - code coverage report
Current view: top level - mpi/tests - multiple_send.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 41 46 89.1 %
Date: 2013-05-17 Functions: 1 1 100.0 %
Branches: 19 32 59.4 %

           Branch data     Line data    Source code
       1                 :            : /* StarPU --- Runtime system for heterogeneous multicore architectures.
       2                 :            :  *
       3                 :            :  * Copyright (C) 2011, 2012, 2013  Centre National de la Recherche Scientifique
       4                 :            :  *
       5                 :            :  * StarPU is free software; you can redistribute it and/or modify
       6                 :            :  * it under the terms of the GNU Lesser General Public License as published by
       7                 :            :  * the Free Software Foundation; either version 2.1 of the License, or (at
       8                 :            :  * your option) any later version.
       9                 :            :  *
      10                 :            :  * StarPU is distributed in the hope that it will be useful, but
      11                 :            :  * WITHOUT ANY WARRANTY; without even the implied warranty of
      12                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
      13                 :            :  *
      14                 :            :  * See the GNU Lesser General Public License in COPYING.LGPL for more details.
      15                 :            :  */
      16                 :            : 
      17                 :            : #include <starpu_mpi.h>
      18                 :            : #include "helper.h"
      19                 :            : 
      20                 :          2 : int main(int argc, char **argv)
      21                 :            : {
      22                 :            :         int ret, rank, size;
      23                 :          2 :         unsigned send[2] = {42, 11};
      24                 :          2 :         unsigned recv[2] = {33, 33};
      25                 :            :         starpu_mpi_req req[2];
      26                 :            :         starpu_data_handle_t send_handle[2];
      27                 :            :         starpu_data_handle_t recv_handle[2];
      28                 :            : 
      29                 :          2 :         ret = starpu_init(NULL);
      30         [ -  + ]:          2 :         STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
      31                 :          2 :         ret = starpu_mpi_init(&argc, &argv, 1);
      32         [ -  + ]:          2 :         STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_init");
      33                 :          2 :         MPI_Comm_rank(MPI_COMM_WORLD, &rank);
      34                 :          2 :         MPI_Comm_size(MPI_COMM_WORLD, &size);
      35                 :            : 
      36         [ -  + ]:          2 :         if (size < 2)
      37                 :            :         {
      38         [ #  # ]:          0 :                 if (rank == 0)
      39         [ #  # ]:          0 :                         FPRINTF(stderr, "We need at least 2 processes.\n");
      40                 :            : 
      41                 :          0 :                 starpu_mpi_shutdown();
      42                 :          0 :                 starpu_shutdown();
      43                 :          0 :                 return STARPU_TEST_SKIPPED;
      44                 :            :         }
      45                 :            : 
      46                 :          2 :         starpu_variable_data_register(&send_handle[0], 0, (uintptr_t)&send[0], sizeof(unsigned));
      47                 :          2 :         starpu_variable_data_register(&send_handle[1], 0, (uintptr_t)&send[1], sizeof(unsigned));
      48                 :          2 :         starpu_variable_data_register(&recv_handle[0], 0, (uintptr_t)&recv[0], sizeof(unsigned));
      49                 :          2 :         starpu_variable_data_register(&recv_handle[1], 0, (uintptr_t)&recv[1], sizeof(unsigned));
      50                 :            : 
      51         [ +  + ]:          2 :         if (rank == 0)
      52                 :            :         {
      53                 :          1 :                 starpu_mpi_isend(send_handle[0], &(req[0]), 1, 12, MPI_COMM_WORLD);
      54                 :          1 :                 starpu_mpi_isend(send_handle[1], &(req[1]), 1, 13, MPI_COMM_WORLD);
      55                 :            :         }
      56         [ +  - ]:          1 :         else if (rank == 1)
      57                 :            :         {
      58                 :          1 :                 starpu_mpi_irecv(recv_handle[0], &(req[0]), 0, 12, MPI_COMM_WORLD);
      59                 :          1 :                 starpu_mpi_irecv(recv_handle[1], &(req[1]), 0, 13, MPI_COMM_WORLD);
      60                 :            :         }
      61                 :            : 
      62 [ +  + ][ +  - ]:          2 :         if (rank == 0 || rank == 1)
      63                 :            :         {
      64                 :          2 :                 int nb_req=2;
      65         [ +  + ]:        954 :                 while (nb_req)
      66                 :            :                 {
      67                 :        952 :                         int r=0;
      68         [ +  + ]:       2856 :                         for(r=0 ; r<2 ; r++)
      69                 :            :                         {
      70         [ +  - ]:       1904 :                                 if (req[r])
      71                 :            :                                 {
      72                 :       1904 :                                         int finished = 0;
      73                 :            :                                         MPI_Status status;
      74                 :       1904 :                                         starpu_mpi_test(&req[r], &finished, &status);
      75         [ -  + ]:       1904 :                                         STARPU_ASSERT(finished != -1);
      76         [ +  + ]:       1904 :                                         if (finished)
      77                 :            :                                         {
      78         [ +  - ]:          4 :                                                 FPRINTF(stderr, "[%d] Request %d finished\n", rank, r);
      79                 :          4 :                                                 req[r] = NULL;
      80                 :       1904 :                                                 nb_req--;
      81                 :            :                                         }
      82                 :            :                                 }
      83                 :            :                         }
      84                 :            :                 }
      85                 :            :         }
      86         [ +  - ]:          2 :         FPRINTF(stderr, "[%d] All requests finished\n", rank);
      87                 :            : 
      88                 :          2 :         starpu_data_unregister(send_handle[0]);
      89                 :          2 :         starpu_data_unregister(send_handle[1]);
      90                 :          2 :         starpu_data_unregister(recv_handle[0]);
      91                 :          2 :         starpu_data_unregister(recv_handle[1]);
      92                 :            : 
      93                 :          2 :         starpu_mpi_shutdown();
      94                 :          2 :         starpu_shutdown();
      95                 :            : 
      96                 :          2 :         return 0;
      97                 :            : }

Generated by: LCOV version 1.9