OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
FieldDataSource.hpp
Go to the documentation of this file.
1 // -*- C++ -*-
2 /***************************************************************************
3  *
4  * The IPPL Framework
5  *
6  * This program was prepared by PSI.
7  * All rights in the program are reserved by PSI.
8  * Neither PSI nor the author(s)
9  * makes any warranty, express or implied, or assumes any liability or
10  * responsibility for the use of this software
11  *
12  * Visit www.amas.web.psi for more details
13  *
14  ***************************************************************************/
15 
16 // -*- C++ -*-
17 /***************************************************************************
18  *
19  * The IPPL Framework
20  *
21  *
22  * Visit http://people.web.psi.ch/adelmann/ for more details
23  *
24  ***************************************************************************/
25 
26 // include files
28 #include "Field/Field.h"
29 #include "Message/Communicate.h"
30 #include "Utility/IpplInfo.h"
31 
32 
33 
35 // constructor: the name, the connection, the transfer method,
36 // the field to connect, and the parent node
37 template<class T, unsigned Dim, class M, class C>
39  int tm, Field<T,Dim,M,C>& F)
40  : DataSourceObject(nm, &F, dc, tm), MyField(F) {
41  // nothing more to do here
42 }
43 
44 
46 // destructor
47 template<class T, unsigned Dim, class M, class C>
49  // nothing to do here
50 }
51 
52 
54 // draw all the data together onto the Parent process
55 template<class T, unsigned Dim, class M, class C >
57 
58 
59 
60  // the tag used to send data, my node, and total number of nodes
61  int n, tag = Ippl::Comm->next_tag(DS_FIELD_TAG, DS_CYCLE);
62  unsigned N = Ippl::getNodes();
63  unsigned myN = Ippl::myNode();
64 
65  // First loop over all the local vnodes and send them to the connected
66  // nodes (0 ... connected - 1). Plus, on the connected nodes,
67  // we put the data directly into the vtk structure.
68  typename Field<T,Dim,M,C>::iterator_if local = MyField.begin_if();
69  typename Field<T,Dim,M,C>::iterator_if endvn = MyField.end_if();
70  for ( ; local != endvn ; ++local) {
71  for (n = 0; n < getConnection()->getNodes(); ++n) {
72  // Cache some information about this local field.
73  LField<T,Dim>& l = *((*local).second);
74  NDIndex<Dim>& lo = (NDIndex<Dim>&) l.getOwned();
75  typename LField<T,Dim>::iterator rhs = l.begin();
76 
77  // We only need to send messages if there is more than one node.
78  if (n != myN) {
79  // Build and send a message containing the owned LocalField data
80  Message *mess = new Message();
81  lo.putMessage(*mess); // send the local domain of the LField
82  rhs.putMessage(*mess); // send the data itself
83  Ippl::Comm->send(mess, n, tag);
84  } else {
85  insert_data(lo, rhs); // on the parent node, just copy in data
86  }
87  }
88  }
89 
90  // Receive all the messages.
91  if (N > 1 && getConnection()->onConnectNode()) {
92  // we expect to receive one message from each remote vnode
93  int remaining = MyField.getLayout().size_rdv();
94 
95  // keep receiving messages until they're all here
96  for ( ; remaining > 0; --remaining) {
97  // Receive the generic message.
98  int any_node = COMM_ANY_NODE;
99  Message *mess = Ippl::Comm->receive_block(any_node, tag);
100 
101  // Extract the domain size and LField iterator from the message
102  NDIndex<Dim> localBlock;
103  T lfdata;
104  typename LField<T,Dim>::iterator rhs(lfdata);
105  localBlock.getMessage(*mess);
106  rhs.getMessage(*mess);
107 
108  // copy the data from the iterator to the vtk storage
109  insert_data(localBlock, rhs);
110 
111  // Free the memory.
112  delete mess;
113  }
114  }
115 }
116 
117 /***************************************************************************
118  * $RCSfile: FieldDataSource.cpp,v $ $Author: adelmann $
119  * $Revision: 1.1.1.1 $ $Date: 2003/01/23 07:40:25 $
120  * IPPL_VERSION_ID: $Id: FieldDataSource.cpp,v 1.1.1.1 2003/01/23 07:40:25 adelmann Exp $
121  ***************************************************************************/
static int getNodes()
Definition: IpplInfo.cpp:773
Message & putMessage(Message &m, bool makecopy=true)
FieldDataSource(const char *, DataConnect *, int, Field< T, Dim, M, C > &)
Definition: rbendmap.h:8
const NDIndex< Dim > & getOwned() const
Definition: LField.h:93
Message & getMessage(Message &m)
Definition: NDIndex.h:147
const int COMM_ANY_NODE
Definition: Communicate.h:40
static int myNode()
Definition: IpplInfo.cpp:794
Definition: FFT.h:31
int next_tag(int t, int s=1000)
Definition: TagMaker.h:43
const iterator & begin() const
Definition: LField.h:104
iterator_if end_if()
Definition: BareField.h:100
virtual ~FieldDataSource()
Message & getMessage(Message &m)
Message & putMessage(Message &m) const
Definition: NDIndex.h:139
iterator_if begin_if()
Definition: BareField.h:99
Message * receive_block(int &node, int &tag)
static Communicate * Comm
Definition: IpplInfo.h:93
bool send(Message *, int node, int tag, bool delmsg=true)