Main Page | Namespace List | Class Hierarchy | Class List | File List | Class Members | File Members

src/DataSource/FieldDataSource.cpp

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 /***************************************************************************
00003  *
00004  * The IPPL Framework
00005  * 
00006  * This program was prepared by PSI. 
00007  * All rights in the program are reserved by PSI.
00008  * Neither PSI nor the author(s)
00009  * makes any warranty, express or implied, or assumes any liability or
00010  * responsibility for the use of this software
00011  *
00012  * Visit http://www.acl.lanl.gov/POOMS for more details
00013  *
00014  ***************************************************************************/
00015 
00016 // -*- C++ -*-
00017 /***************************************************************************
00018  *
00019  * The IPPL Framework
00020  * 
00021  *
00022  * Visit http://people.web.psi.ch/adelmann/ for more details
00023  *
00024  ***************************************************************************/
00025 
00026 // include files
00027 #include "DataSource/FieldDataSource.h"
00028 #include "Field/Field.h"
00029 #include "Message/Communicate.h"
00030 #include "Utility/IpplInfo.h"
00031 #include "Profile/Profiler.h"
00032 
00033 
00035 // constructor: the name, the connection, the transfer method,
00036 // the field to connect, and the parent node
00037 template<class T, unsigned Dim, class M, class C>
00038 FieldDataSource<T,Dim,M,C>::FieldDataSource(const char *nm, DataConnect *dc,
00039                                             int tm, Field<T,Dim,M,C>& F)
00040   : DataSourceObject(nm, &F, dc, tm), MyField(F) {
00041   // nothing more to do here
00042 }
00043 
00044 
00046 // destructor
00047 template<class T, unsigned Dim, class M, class C>
00048 FieldDataSource<T,Dim,M,C>::~FieldDataSource() {
00049   // nothing to do here
00050 }
00051 
00052 
00054 // draw all the data together onto the Parent process
00055 template<class T, unsigned Dim, class M, class C >
00056 void FieldDataSource<T,Dim,M,C>::gather_data(void) {
00057   TAU_TYPE_STRING(taustr, CT(*this) + " void ()" );
00058   TAU_PROFILE("FieldDataSource::gather_data()", taustr, TAU_VIZ);
00059 
00060   // the tag used to send data, my node, and total number of nodes
00061   int n, tag = Ippl::Comm->next_tag(DS_FIELD_TAG, DS_CYCLE);
00062   unsigned N = Ippl::getNodes();
00063   unsigned myN = Ippl::myNode();
00064 
00065   // First loop over all the local vnodes and send them to the connected
00066   // nodes (0 ... connected - 1).  Plus, on the connected nodes,
00067   // we put the data directly into the vtk structure.
00068   typename Field<T,Dim,M,C>::iterator_if local = MyField.begin_if();
00069   typename Field<T,Dim,M,C>::iterator_if endvn = MyField.end_if();
00070   for ( ; local != endvn ; ++local) {
00071     for (n = 0; n < getConnection()->getNodes(); ++n) {
00072       // Cache some information about this local field.
00073       LField<T,Dim>&  l           = *((*local).second);
00074       NDIndex<Dim>&  lo           = (NDIndex<Dim>&) l.getOwned();
00075       typename LField<T,Dim>::iterator rhs = l.begin();
00076 
00077       // We only need to send messages if there is more than one node.  
00078       if (n != myN) {
00079         // Build and send a message containing the owned LocalField data
00080         Message *mess = new Message();
00081         lo.putMessage(*mess);         // send the local domain of the LField
00082         rhs.putMessage(*mess);        // send the data itself
00083         Ippl::Comm->send(mess, n, tag);
00084       } else {
00085         insert_data(lo, rhs);         // on the parent node, just copy in data
00086       }
00087     }
00088   }
00089 
00090   // Receive all the messages.
00091   if (N > 1 && getConnection()->onConnectNode()) {
00092     // we expect to receive one message from each remote vnode
00093     int remaining = MyField.getLayout().size_rdv();
00094 
00095     // keep receiving messages until they're all here
00096     for ( ; remaining > 0; --remaining) {
00097       // Receive the generic message.
00098       int any_node = COMM_ANY_NODE;
00099       Message *mess = Ippl::Comm->receive_block(any_node, tag);
00100 
00101       // Extract the domain size and LField iterator from the message
00102       NDIndex<Dim> localBlock;
00103       T lfdata;
00104       typename LField<T,Dim>::iterator rhs(lfdata);
00105       localBlock.getMessage(*mess);
00106       rhs.getMessage(*mess);
00107 
00108       // copy the data from the iterator to the vtk storage
00109       insert_data(localBlock, rhs);
00110 
00111       // Free the memory.
00112       delete mess;
00113     }
00114   }
00115 }
00116 
00117 /***************************************************************************
00118  * $RCSfile: FieldDataSource.cpp,v $   $Author: adelmann $
00119  * $Revision: 1.1.1.1 $   $Date: 2003/01/23 07:40:25 $
00120  * IPPL_VERSION_ID: $Id: FieldDataSource.cpp,v 1.1.1.1 2003/01/23 07:40:25 adelmann Exp $ 
00121  ***************************************************************************/

Generated on Fri Nov 2 01:25:55 2007 for IPPL by doxygen 1.3.5