FreeNOS
mpi.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2020 Niek Linnenbank
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #include <Assert.h>
19 #include "MpiBackend.h"
20 #include "mpi.h"
21 
23 
24 extern C int MPI_Init(int *argc, char ***argv)
25 {
27  return mpiBackend->initialize(argc, argv);
28 }
29 
30 extern C int MPI_Finalize(void)
31 {
33  return mpiBackend->terminate();
34 }
35 
36 extern C int MPI_Send(const void *buf,
37  int count,
38  MPI_Datatype datatype,
39  int dest,
40  int tag,
41  MPI_Comm comm)
42 {
44  return mpiBackend->send(buf, count, datatype, dest, tag, comm);
45 }
46 
47 extern C int MPI_Recv(void *buf,
48  int count,
49  MPI_Datatype datatype,
50  int source,
51  int tag,
52  MPI_Comm comm,
53  MPI_Status *status)
54 {
56  return mpiBackend->receive(buf, count, datatype, source, tag, comm, status);
57 }
58 
59 extern C int MPI_Comm_rank(MPI_Comm comm,
60  int *rank)
61 {
63  return mpiBackend->getCommRank(comm, rank);
64 }
65 
66 extern C int MPI_Comm_size(MPI_Comm comm,
67  int *size)
68 {
70  return mpiBackend->getCommSize(comm, size);
71 }
MPI_Finalize
C int MPI_Finalize(void)
Definition: mpi.cpp:30
MPI_Comm
uint MPI_Comm
Communicator identifier.
Definition: mpi.h:38
MPI_Comm_size
C int MPI_Comm_size(MPI_Comm comm, int *size)
Definition: mpi.cpp:66
Assert.h
MPI_Status
uint MPI_Status
Status holder.
Definition: mpi.h:41
MpiBackend::getCommSize
virtual Result getCommSize(MPI_Comm comm, int *size)=0
Retrieve communication size (total cores)
MpiBackend::terminate
virtual Result terminate()=0
Terminate the backend.
MpiBackend::getCommRank
virtual Result getCommRank(MPI_Comm comm, int *rank)=0
Retrieve communication rank (core id)
MpiBackend::initialize
virtual Result initialize(int *argc, char ***argv)=0
Initialize the backend.
C
#define C
Used to define external C functions.
Definition: Macros.h:134
MpiBackend.h
mpi.h
mpiBackend
static MpiBackend * mpiBackend
Definition: mpi.cpp:22
MPI_Init
C int MPI_Init(int *argc, char ***argv)
Definition: mpi.cpp:24
AbstractFactory< MpiBackend >::create
static MpiBackend * create()
Abstract function to create an instance of T.
MPI_Comm_rank
C int MPI_Comm_rank(MPI_Comm comm, int *rank)
Definition: mpi.cpp:59
MPI_Datatype
MPI_Datatype
Named Predefined Datatypes.
Definition: mpi.h:46
MpiBackend
Represents a Message Passing Interface (MPI) implementation backend.
Definition: MpiBackend.h:36
assert
#define assert(exp)
Insert program diagnostics.
Definition: assert.h:60
MPI_Send
C int MPI_Send(const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm)
Definition: mpi.cpp:36
MPI_Recv
C int MPI_Recv(void *buf, int count, MPI_Datatype datatype, int source, int tag, MPI_Comm comm, MPI_Status *status)
Definition: mpi.cpp:47
MpiBackend::receive
virtual Result receive(void *buf, int count, MPI_Datatype datatype, int source, int tag, MPI_Comm comm, MPI_Status *status)=0
Synchronous receive data.
ZERO
#define ZERO
Zero value.
Definition: Macros.h:43
MpiBackend::send
virtual Result send(const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm)=0
Synchronous send data.