GALib-Parallel
Header-only C++ library for parallel evolutionary algorithms
Loading...
Searching...
No Matches
Communicator.h
Go to the documentation of this file.
1#ifndef COMMUNICATOR_H
2#define COMMUNICATOR_H
3
4#pragma once
5
6#include "core/Individual.h"
8#include <vector>
9#include <cstddef>
10
11namespace galib::internal {
12
21 template <typename GeneType>
23 public:
24 virtual ~Communicator() = default;
25
30 virtual void startReceiving(MigrationBuffer<GeneType>& target_buffer) = 0;
31
35 virtual void update() = 0;
36
40 virtual void stopReceiving() = 0;
41
47 virtual void send(const std::vector<Individual<GeneType>>& deme, std::size_t destination_rank) = 0;
48
54 virtual void broadcast(const std::vector<Individual<GeneType>>& deme,
55 const std::vector<std::size_t>& destination_ranks) = 0;
56
64
69 [[nodiscard]] virtual std::size_t getRank() const = 0;
70
75 [[nodiscard]] virtual std::size_t getSize() const = 0;
76 };
77}
78
79#endif // COMMUNICATOR_H
Represents a single candidate solution in the population.
Definition Individual.h:23
Interface for network communication between islands.
virtual void broadcast(const std::vector< Individual< GeneType > > &deme, const std::vector< std::size_t > &destination_ranks)=0
Sends a deme to multiple destination islands.
virtual std::size_t getSize() const =0
Gets the total number of islands in the network.
virtual ~Communicator()=default
virtual void update()=0
Processes any pending network events (e.g. polls for incoming messages).
virtual Individual< GeneType > allReduceBest(Individual< GeneType > individual) const =0
Global reduction to find the best individual across all islands.
virtual void startReceiving(MigrationBuffer< GeneType > &target_buffer)=0
Begins asynchronous background receiving of migrants.
virtual std::size_t getRank() const =0
Gets the network rank of the local node.
virtual void send(const std::vector< Individual< GeneType > > &deme, std::size_t destination_rank)=0
Sends a deme to a specific destination island.
virtual void stopReceiving()=0
Stops background communication activities.
Interface for a thread-safe buffer that stores incoming migrants.