YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
MpiComm.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-FileCopyrightText: 2010 Daniel Krieg <krieg@fias.uni-frankfurt.de>
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#ifndef YARP_MPICOMM_H
8#define YARP_MPICOMM_H
9
10#include <string>
11#include <yarp/os/Semaphore.h>
12#include <yarp/os/SystemClock.h>
13#include <yarp/os/Thread.h>
14
15#include <string>
16#include <iostream>
17
18#include <mpi.h>
19
20#include "MpiLogComponent.h"
21
23 public yarp::os::Thread
24{
25 bool terminate;
26public:
27 MpiControlThread() : terminate(false) {}
28 void finalize() {
29 terminate = true;}
30 bool threadInit() override;
31 void run() override {
32 while (!terminate) {yarp::os::SystemClock::delaySystem(1);}
33 }
34 void threadRelease() override;
35};
36
38
39
40
50{
51 std::string name;
52
53public:
54 char port_name[MPI_MAX_PORT_NAME];
55 char unique_id[10+MPI_MAX_PROCESSOR_NAME];
56 MPI_Comm comm;
58
59
60 MpiComm(std::string name);
62 yCTrace(MPI_CARRIER, "[MpiComm @ %s] Destructor", name.c_str() );
63 MPI_Comm_disconnect(&comm);
64 }
65 bool connect(std::string port);
66 bool accept();
67 void disconnect(bool disconn);
68 bool notLocal(std::string other);
69
70 void openPort() {
71 MPI_Open_port(MPI_INFO_NULL, port_name);
72 }
73 void closePort() {
74 MPI_Close_port(port_name);
75 }
76 int rank() {
77 int rank;
78 MPI_Comm_rank(comm, &rank);
79 return rank;
80 }
81};
82
83
84#endif // YARP_MPICOMM_H
MpiControlThread * MpiControl
Definition MpiComm.cpp:22
const yarp::os::LogComponent & MPI_CARRIER()
Wrapper for MPI_Comm communicator.
Definition MpiComm.h:50
bool accept()
Definition MpiComm.cpp:143
bool connect(std::string port)
Definition MpiComm.cpp:113
void closePort()
Definition MpiComm.h:73
yarp::os::Semaphore sema
Definition MpiComm.h:57
int rank()
Definition MpiComm.h:76
MPI_Comm comm
Definition MpiComm.h:56
bool notLocal(std::string other)
Definition MpiComm.cpp:105
char unique_id[10+MPI_MAX_PROCESSOR_NAME]
Definition MpiComm.h:55
void disconnect(bool disconn)
Definition MpiComm.cpp:165
void openPort()
Definition MpiComm.h:70
char port_name[MPI_MAX_PORT_NAME]
Definition MpiComm.h:54
~MpiComm()
Definition MpiComm.h:61
void finalize()
Definition MpiComm.h:28
bool threadInit() override
Initialization method.
Definition MpiComm.cpp:50
void run() override
Main body of the new thread.
Definition MpiComm.h:31
void threadRelease() override
Release method.
Definition MpiComm.cpp:44
A class for thread synchronization and mutual exclusion.
Definition Semaphore.h:25
static void delaySystem(double seconds)
An abstraction for a thread of execution.
Definition Thread.h:21
#define yCTrace(component,...)