00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
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
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
00058
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
00064 Message *mess = new Message();
00065 int datahere;
00066
00067
00068 for (local = MyField.begin_if(); local != MyField.end_if(); ++local) {
00069
00070
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
00086 datahere = 0;
00087 ::putMessage(*mess, datahere);
00088 Ippl::Comm->send(mess, Parent, tag);
00089 } else {
00090
00091 LField<T,Dim> myLField(view,view);
00092 myLField.Uncompress();
00093
00094 for (local = MyField.begin_if(); local != MyField.end_if(); ++local) {
00095
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
00107 for (int remaining = Ippl::getNodes() - 1; remaining > 0; --remaining) {
00108
00109 int any_node = COMM_ANY_NODE;
00110 Message *mess = Ippl::Comm->receive_block(any_node, tag);
00111 PAssert(mess != 0);
00112
00113
00114 int datahere;
00115 ::getMessage(*mess, datahere);
00116 while (datahere != 0) {
00117
00118 NDIndex<Dim> localBlock;
00119 localBlock.getMessage(*mess);
00120
00121
00122 T compressed_value;
00123 LFI rhs(compressed_value);
00124 rhs.getMessage(*mess);
00125
00126
00127 LFI lhs = myLField.begin(localBlock);
00128 BrickExpression<Dim,LFI,LFI,OpAssign>(lhs,rhs).apply();
00129
00130
00131 ::getMessage(*mess, datahere);
00132 }
00133
00134
00135 delete mess;
00136 }
00137
00138
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
00202
00203
00204