1 /* Siconos is a program dedicated to modeling, simulation and control
2 * of non smooth dynamical systems.
3 *
4 * Copyright 2021 INRIA.
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18 #include "NM_MPI.h"
19 #include <assert.h>
20 #ifdef SICONOS_HAS_MPI
21 #include "NumericsMatrix.h"
22 #include "numerics_verbose.h"
NM_MPI_comm(NumericsMatrix * A)23 MPI_Comm NM_MPI_comm(NumericsMatrix* A)
24 {
25 assert(A);
26
27 if(NM_internalData(A)->mpi_comm == MPI_COMM_NULL)
28 {
29 if(verbose)
30 {
31 fprintf(stderr, "siconos/numerics: warning, MPI communicator has not been initialized,\n");
32 fprintf(stderr, "siconos/numerics: MPI_COMM_WORLD will be used.\n");
33 }
34 NM_internalData(A)->mpi_comm = MPI_COMM_WORLD;
35 }
36 return NM_internalData(A)->mpi_comm = MPI_COMM_WORLD;
37 }
38
NM_MPI_set_comm(NumericsMatrix * A,MPI_Comm comm)39 void NM_MPI_set_comm(NumericsMatrix* A, MPI_Comm comm)
40 {
41 assert(A);
42 NM_internalData(A)->mpi_comm = comm;
43 }
44
45
46 #endif /* WITH_MPI */
47
NM_MPI_rank(NumericsMatrix * A)48 int NM_MPI_rank(NumericsMatrix* A)
49 {
50 assert(A);
51 int myid;
52 #ifdef SICONOS_HAS_MPI
53 CHECK_MPI(NM_MPI_comm(A), MPI_Comm_rank(NM_MPI_comm(A), &myid));
54 #else
55 myid = 0;
56 #endif
57 return myid;
58 }
59
NM_MPI_copy(const NumericsMatrix * A,NumericsMatrix * B)60 void NM_MPI_copy(const NumericsMatrix* A, NumericsMatrix* B)
61 {
62 assert(A);
63 assert(B);
64 #ifdef SICONOS_HAS_MPI
65 if(A->internalData && A->internalData->mpi_comm)
66 {
67 NM_MPI_set_comm(B, A->internalData->mpi_comm);
68 }
69 #endif
70 }
71