src/Utility/FieldPrint.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 "Utility/FieldPrint.h"
00028 #include "Utility/IpplInfo.h"
00029 #include "Utility/PAssert.h"
00030 #include "Field/BrickExpression.h"
00031 #include "Profile/Profiler.h"
00032 
00033 #ifdef IPPL_USE_STANDARD_HEADERS
00034 #include <iomanip>
00035 using namespace std;
00036 #else
00037 #include <iomanip.h>
00038 #endif
00039 
00040 
00041 //------------------------------------------------------------------
00042 template<class T, unsigned Dim >
00043 void 
00044 FieldPrint<T,Dim>::print(NDIndex<Dim>& view) {
00045   TAU_TYPE_STRING(taustr, CT(*this) + " void (" + CT(view) + " )" );
00046   TAU_PROFILE("FieldPrint::print()", taustr, 
00047     TAU_UTILITY | TAU_FIELD | TAU_IO);
00048 
00049   // check that the view is contained inside of the Field's domain
00050   NDIndex<Dim>& domain = (NDIndex<Dim>&) MyField.getDomain();
00051   if( ! domain.contains(view) ) {
00052     ERRORMSG("FieldPrint::print - the domain of the field: " << domain<<endl);
00053     ERRORMSG(" must contain the selected view: " << view << endl);
00054     return;
00055   }
00056 
00057   // Loop over all the local nodes and send the intersecting data to the
00058   // parent node
00059   int tag = Ippl::Comm->next_tag(FP_GATHER_TAG, FP_TAG_CYCLE);
00060   typedef typename LField<T,Dim>::iterator LFI;
00061   typename BareField<T,Dim>::iterator_if local;
00062   if (Ippl::Comm->myNode() != Parent) {
00063     // prepare a message to send to parent node
00064     Message *mess = new Message();
00065     int datahere;
00066 
00067     // put data for each local LField in the message
00068     for (local = MyField.begin_if(); local != MyField.end_if(); ++local) {
00069       // find the intersection of this lfield with the view, and put data in
00070       // message.
00071       LField<T,Dim> &l = *(*local).second;
00072       NDIndex<Dim>& lo = (NDIndex<Dim>&) l.getOwned();
00073       if (view.touches(lo)) {
00074         datahere = 1;
00075         NDIndex<Dim> intersection = lo.intersect(view);
00076         T compressed_data;
00077         LFI rhs = l.begin(intersection, compressed_data);
00078         rhs.TryCompress();
00079 	::putMessage(*mess, datahere);
00080         intersection.putMessage(*mess);
00081         rhs.putMessage(*mess);
00082       }
00083     }
00084 
00085     // Send the message.
00086     datahere = 0;
00087     ::putMessage(*mess, datahere);
00088     Ippl::Comm->send(mess, Parent, tag);
00089   } else {
00090     // on parent, first copy all local blocks into a single LField
00091     LField<T,Dim> myLField(view,view);
00092     myLField.Uncompress();
00093     
00094     for (local = MyField.begin_if(); local != MyField.end_if(); ++local) {
00095       // find the intersection of this lfield with the view
00096       LField<T,Dim> &l = *(*local).second;
00097       NDIndex<Dim>& lo = (NDIndex<Dim>&) l.getOwned();
00098       if (view.touches(lo)) {
00099         NDIndex<Dim> intersection = lo.intersect(view);
00100         LFI lhs = myLField.begin(intersection);
00101         LFI rhs = l.begin(intersection);
00102         BrickExpression<Dim,LFI,LFI,OpAssign>(lhs,rhs).apply();
00103       }
00104     }
00105 
00106     // Receive all the messages, one from each node.
00107     for (int remaining = Ippl::getNodes() - 1; remaining > 0; --remaining) {
00108       // Receive the generic message.
00109       int any_node = COMM_ANY_NODE;
00110       Message *mess = Ippl::Comm->receive_block(any_node, tag);
00111       PAssert(mess != 0);
00112 
00113       // keep getting blocks until we're done with the message
00114       int datahere;
00115       ::getMessage(*mess, datahere);
00116       while (datahere != 0) {
00117         // Extract the intersection domain from the message.
00118         NDIndex<Dim> localBlock;
00119         localBlock.getMessage(*mess);
00120 
00121         // Extract the rhs iterator from it.
00122         T compressed_value;
00123         LFI rhs(compressed_value);
00124         rhs.getMessage(*mess);
00125 
00126         // copy the data into our local LField
00127         LFI lhs = myLField.begin(localBlock);
00128         BrickExpression<Dim,LFI,LFI,OpAssign>(lhs,rhs).apply();
00129 
00130         // see if there is another block
00131 	::getMessage(*mess, datahere);
00132       }
00133 
00134       // done with the message now
00135       delete mess;
00136     }
00137 
00138     // now that we have populated the localfield with the view, we print
00139     Inform out("");
00140 
00141     int f0, f1, f2, n0, n1, n2, i0, i1, i2;
00142     LFI liter = myLField.begin();
00143     switch(Dim) {
00144     case 1:
00145       f0 = view[0].first();
00146       n0 = view[0].length();
00147       for (i0=0; i0<n0; ++i0) {
00148         out << "["<<f0+i0<<"]= "<< liter.offset(i0) << endl;
00149       }
00150       break;
00151 
00152     case 2:
00153       f0 = view[0].first();
00154       f1 = view[1].first();
00155       n0 = view[0].length();
00156       n1 = view[1].length();
00157       for (i0=0; i0<n0; ++i0) {
00158         for (i1=0; i1<n1; ++i1) {
00159           out << "["<<f0+i0<<"]["<<f1+i1<<"]= "<< liter.offset(i0,i1)<< endl;
00160         }
00161       }
00162       break;
00163 
00164     case 3:
00165       f0 = view[0].first();
00166       f1 = view[1].first();
00167       f2 = view[2].first();
00168       n0 = view[0].length();
00169       n1 = view[1].length();
00170       n2 = view[2].length();
00171       if(Scientific) {
00172         out.setf(ios::scientific);
00173       }
00174       for (i0=0; i0<n0; ++i0) {
00175         for (i1=0; i1<n1; ++i1) {
00176           out << "["<<setw(IndexWidth)<<f0+i0<<"]["<<setw(IndexWidth)<<f1+i1<<"]["
00177               <<setw(IndexWidth)<<f2<<":"<<setw(IndexWidth)<<f2+n2-1<<"] ";
00178           for (i2=0; i2<n2; ++i2) {
00179             out << setprecision(DataPrecision) << setw(DataWidth)
00180                 << liter.offset(i0,i1,i2)<<" ";
00181             if( CarReturn > 0 ) {
00182               if( i2 != 0 && i2 != ( n2-1) && !( (i2+1) % CarReturn) ) {
00183                 out << endl << "                    ";
00184               }
00185             }
00186           }
00187           out << endl;
00188         }
00189       }
00190       break;
00191 
00192     default:
00193       ERRORMSG("bad Dimension \""<<Dim<<"\" in FieldPrint::print()"<< endl);
00194       return;
00195     }
00196   }
00197 }
00198 
00199 
00200 /***************************************************************************
00201  * $RCSfile: FieldPrint.cpp,v $   $Author: adelmann $
00202  * $Revision: 1.1.1.1 $   $Date: 2003/01/23 07:40:33 $
00203  * IPPL_VERSION_ID: $Id: FieldPrint.cpp,v 1.1.1.1 2003/01/23 07:40:33 adelmann Exp $ 
00204  ***************************************************************************/

Generated on Mon Jan 16 13:23:58 2006 for IPPL by  doxygen 1.4.6