1 /* -----------------------------------------------------------------
2  * Programmer(s): Cody J. Balos @ LLNL, Daniel R. Reynolds @ SMU
3  * -----------------------------------------------------------------
4  * SUNDIALS Copyright Start
5  * Copyright (c) 2002-2020, Lawrence Livermore National Security
6  * and Southern Methodist University.
7  * All rights reserved.
8  *
9  * See the top-level LICENSE and NOTICE files for details.
10  *
11  * SPDX-License-Identifier: BSD-3-Clause
12  * SUNDIALS Copyright End
13  * -----------------------------------------------------------------
14  * These are test functions for an NVECTOR module implementation
15  * which have MPI symbols.
16  * -----------------------------------------------------------------*/
17 
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <mpi.h>
21 
22 #include <sundials/sundials_nvector.h>
23 
24 #include "test_nvector.h"
25 
26 /* ----------------------------------------------------------------------
27  * Test_N_VGetCommunicator Test (with MPI dependency).
28  * --------------------------------------------------------------------*/
Test_N_VGetCommunicatorMPI(N_Vector W,void * comm,int myid)29 int Test_N_VGetCommunicatorMPI(N_Vector W, void *comm, int myid)
30 {
31   void* wcomm;
32   MPI_Comm* Wcomm;
33   MPI_Comm* Comm;
34   int same;
35 
36   /* ask W for its communicator */
37   wcomm = NULL;
38   wcomm = N_VGetCommunicator(W);
39 
40   /* return with success if both are NULL */
41   if ((wcomm == NULL) && (comm == NULL))  {
42     printf("PASSED test -- N_VGetCommunicator\n");
43     return(0);
44   }
45 
46   /* return with failure if either is NULL */
47   if (wcomm == NULL) {
48     printf(">>> FAILED test -- N_VGetCommunicator, Proc %d (incorrectly reports NULL comm)\n", myid);
49     return(1);
50   }
51   if (comm == NULL) {
52     printf(">>> FAILED test -- N_VGetCommunicator, Proc %d (incorrectly reports non-NULL comm)\n", myid);
53     return(1);
54   }
55 
56   /* call MPI_Comm_compare to check that communicators match or are congruent */
57   Wcomm = (MPI_Comm *) wcomm;
58   Comm  = (MPI_Comm *) comm;
59   if (MPI_Comm_compare(*Comm, *Wcomm, &same) != MPI_SUCCESS) {
60     printf(">>> FAILED test -- N_VGetCommunicator, Proc %d (error in MPI_Comm_compare)\n", myid);
61     return(1);
62   }
63   if ((same != MPI_IDENT) && (same != MPI_CONGRUENT)) {
64     printf(">>> FAILED test -- N_VGetCommunicator, Proc %d (mismatched comms)\n", myid);
65     return(1);
66   }
67   if (myid == 0)
68     printf("PASSED test -- N_VGetCommunicator\n");
69   return(0);
70 }
71