OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
 
Loading...
Searching...
No Matches
main.cpp
1#include "Grid/grid_dist_id.hpp"
2#include "data_type/aggregate.hpp"
3#include "Decomposition/CartDecomposition.hpp"
4#include "VCluster/VCluster.hpp"
5
20#define N_NEXT 3
21#define N_NUMBERS 5
22
23int main(int argc, char* argv[])
24{
40
41 openfpm_init(&argc,&argv);
42 Vcluster<> & v_cl = create_vcluster();
43
45
64
65 // id of the processor calling this function
66 long int proc_id = v_cl.getProcessUnitID();
67
68 // number of processors executing this program
69 long int n_proc = v_cl.getProcessingUnits();
70
71 // List of processors we communicate with
73
74 // For each processor we want to send a vector of doubles
75 // in this case each processor send N_NEXT vectors.
76 // In general we can think to openfpm::vector<T> as a set of objects T.
77 // where we want to send one object T to each processor in out sending list.
78 // In this case T is a list of double or (openfpm::vector<double>)
79 openfpm::vector<openfpm::vector<double>> messages_send(N_NEXT);
80
81 // Here we prepare the senbding buffer
82 for (size_t i = 0, m = 0 ; i < N_NEXT ; i++, m++)
83 {
84 // create the sending processor list
85 prc_send.add(openfpm::math::positive_modulo(proc_id + i + 1,n_proc));
86
87 // Fill with soma data the vectors
88 for (size_t j = 0 ; j < N_NUMBERS ; j++)
89 messages_send.get(m).add(j+N_NUMBERS*proc_id);
90
91 }
92
93 // Buffer that receive messages
94 openfpm::vector<double> messages_recv2;
95
96 // List of processor from which we receove
98
99 // number of elements we receive from each processors
101
102 v_cl.SSendRecv(messages_send,messages_recv2,prc_send,prc_recv2,sz_recv2);
103
104 // here each processor print the received message
105
106 std::cout << "Processor " << proc_id << " received ";
107 for (size_t i = 0 ; i < messages_recv2.size() ; i++)
108 std::cout << messages_recv2.get(i) << " ";
109
110 std::cout << std::endl;
111
113
126
127 openfpm_finalize();
128
130}
size_t getProcessUnitID()
Get the process unit id.
size_t getProcessingUnits()
Get the total number of processors.
Implementation of VCluster class.
Definition VCluster.hpp:59
bool SSendRecv(openfpm::vector< T > &send, S &recv, openfpm::vector< size_t > &prc_send, openfpm::vector< size_t > &prc_recv, openfpm::vector< size_t > &sz_recv, size_t opt=NONE)
Semantic Send and receive, send the data to processors and receive from the other processors.
Definition VCluster.hpp:797
Implementation of 1-D std::vector like structure.
size_t size()
Stub size.