16 #ifndef vtkMaterialInterfaceUtilities_h 17 #define vtkMaterialInterfaceUtilities_h 32 using std::ostringstream;
47 void ClearVectorOfPointers(vector<T*>& V)
50 for (
size_t i = 0; i < n; ++i)
61 void ClearVectorOfVtkPointers(vector<T*>& V)
64 for (
size_t i = 0; i < n; ++i)
75 void ClearVectorOfArrayPointers(vector<T*>& V)
78 for (
size_t i = 0; i < n; ++i)
89 void ResizeVectorOfVtkPointers(vector<T*>& V,
int n)
91 ClearVectorOfVtkPointers(V);
94 for (
int i = 0; i < n; ++i)
101 void ResizeVectorOfArrayPointers(vector<T*>& V,
int nV,
int nA)
103 ClearVectorOfArrayPointers(V);
106 for (
int i = 0; i < nV; ++i)
113 void ResizeVectorOfVtkArrayPointers(vector<T*>& V,
int nComps,
vtkIdType nTups,
string name,
int nv)
115 ClearVectorOfVtkPointers(V);
118 for (
int i = 0; i < nv; ++i)
121 V[i]->SetNumberOfComponents(nComps);
122 V[i]->SetNumberOfTuples(nTups);
123 V[i]->SetName(name.c_str());
128 void ResizeVectorOfVtkArrayPointers(vector<T*>& V,
int nComps,
int nv)
130 ResizeVectorOfVtkArrayPointers(V, nComps, 0,
"", nv);
134 void ResizeVectorOfVtkArrayPointers(vector<T*>& V,
int nComps,
int nTups,
int nv)
136 ResizeVectorOfVtkArrayPointers(V, nComps, nTups,
"", nv);
141 inline void ReNewVtkPointer(T*& pv)
151 inline void NewVtkArrayPointer(T*& pv,
int nComps,
vtkIdType nTups, std::string name)
154 pv->SetNumberOfComponents(nComps);
155 pv->SetNumberOfTuples(nTups);
156 pv->SetName(name.c_str());
160 inline void ReNewVtkArrayPointer(T*& pv,
int nComps,
vtkIdType nTups, std::string name)
166 NewVtkArrayPointer(pv, nComps, nTups, name);
170 inline void ReNewVtkArrayPointer(T*& pv, std::string name)
172 ReNewVtkArrayPointer(pv, 1, 0, name);
176 inline void ReleaseVtkPointer(T*& pv)
178 assert(
"Attempted to release a 0 pointer." && pv != 0);
184 inline void CheckAndReleaseVtkPointer(T*& pv)
195 inline void CheckAndReleaseArrayPointer(T*& pv)
206 inline void CheckAndReleaseCArrayPointer(T*& pv)
217 inline void FillVector(vector<T>& V,
const T& v)
220 for (
size_t i = 0; i < n; ++i)
230 inline int CopyTuple(T* dest,
236 int srcIndex = nComps * srcCellIndex;
242 float* thisTuple =
dynamic_cast<vtkFloatArray*
>(src)->GetPointer(srcIndex);
243 for (
int q = 0;
q < nComps; ++
q)
245 dest[
q] =
static_cast<T
>(thisTuple[
q]);
251 double* thisTuple =
dynamic_cast<vtkDoubleArray*
>(src)->GetPointer(srcIndex);
252 for (
int q = 0;
q < nComps; ++
q)
254 dest[
q] =
static_cast<T
>(thisTuple[
q]);
260 int* thisTuple =
dynamic_cast<vtkIntArray*
>(src)->GetPointer(srcIndex);
261 for (
int q = 0;
q < nComps; ++
q)
263 dest[
q] =
static_cast<T
>(thisTuple[
q]);
270 for (
int q = 0;
q < nComps; ++
q)
272 dest[
q] =
static_cast<T
>(thisTuple[
q]);
277 assert(
"This data type is unsupported." && 0);
284 #ifdef vtkMaterialInterfaceFilterDEBUG 292 const int hostNameSize = 256;
293 char hostname[hostNameSize] = {
'\0' };
294 gethostname(hostname, hostNameSize);
296 const int hrpSize = 512;
297 char hrp[hrpSize] = {
'\0' };
298 sprintf(hrp,
"%s : %d : %d", hostname, myProcId, pid);
303 hrpBuffer =
new char[nProcs * hrpSize];
305 comm->
Gather(hrp, hrpBuffer, hrpSize, 0);
311 hrpFile.open(pidFileName.c_str());
312 char* thisHrp = hrpBuffer;
313 if (hrpFile.is_open())
315 for (
int procId = 0; procId < nProcs; ++procId)
317 hrpFile << thisHrp << endl;
325 for (
int procId = 0; procId < nProcs; ++procId)
327 cerr << thisHrp << endl;
337 string GetMemoryUsage(
int pid,
int line,
int procId)
339 ostringstream memoryUsage;
341 ostringstream statusFileName;
342 statusFileName <<
"/proc/" << pid <<
"/status";
344 statusFile.open(statusFileName.str().c_str());
345 if (statusFile.is_open())
347 const int cbufSize = 1024;
348 char cbuf[cbufSize] = {
'\0' };
349 while (statusFile.good())
351 statusFile.getline(cbuf, cbufSize);
353 if (
content.find(
"VmSize") != string::npos ||
content.find(
"VmRSS") != string::npos ||
354 content.find(
"VmData") != string::npos)
356 int tabStart =
content.find_first_of(
"\t ");
358 while (content[tabStart + tabSpan] ==
'\t' || content[tabStart + tabSpan] ==
' ')
362 string formattedContent =
363 content.substr(0, tabStart - 1) +
" " +
content.substr(tabStart + tabSpan);
364 memoryUsage <<
"[" << line <<
"] " << procId <<
" " << formattedContent << endl;
371 cerr <<
"[" << line <<
"] " << procId <<
" could not open " << statusFileName <<
"." << endl;
374 return memoryUsage.str();
378 void writeTuple(ostream& sout, T* tup,
int nComp)
386 sout <<
"(" << tup[0];
387 for (
int q = 1;
q < nComp; ++
q)
389 sout <<
", " << tup[
q];
397 sout <<
"Name: " << da.
GetName() << endl;
402 sout <<
"NumberOfComps: " << nComp << endl;
403 sout <<
"NumberOfTuples:" << nTup << endl;
406 sout <<
"{}" << endl;
412 writeTuple(sout, thisTup, nComp);
413 for (
int i = 1; i < nTup; ++i)
417 writeTuple(sout, thisTup, nComp);
424 ostream& operator<<(ostream& sout, vector<vtkDoubleArray*>& vda)
426 size_t nda = vda.size();
427 for (
size_t i = 0; i < nda; ++i)
429 sout <<
"[" << i <<
"]\n" << *vda[i] << endl;
434 ostream& operator<<(ostream& sout, vector<vector<int> >& vvi)
436 size_t nv = vvi.size();
437 for (
size_t i = 0; i < nv; ++i)
439 sout <<
"[" << i <<
"]{";
440 size_t ni = vvi[i].size();
447 for (
size_t j = 1; j < ni; ++j)
449 sout <<
"," << vvi[i][j];
456 ostream& operator<<(ostream& sout, vector<int>& vi)
459 size_t ni = vi.size();
466 for (
size_t j = 1; j < ni; ++j)
468 sout <<
"," << vi[j];
524 template <
typename TCnt,
typename TLabel>
525 void PrintHistogram(vector<TCnt>& bins, vector<TLabel>& binIds)
527 const int maxWidth = 40;
528 const size_t n = bins.size();
533 int maxBin = *max_element(bins.begin(), bins.end());
534 for (
size_t i = 0; i < n; ++i)
541 int wid = maxBin < maxWidth ? bins[i] : bins[i] * maxWidth / maxBin;
542 cerr <<
"{" << setw(12) << std::left << binIds[i] <<
"}*";
543 for (
int j = 1; j < wid; ++j)
547 cerr <<
"(" << bins[i] <<
")" << endl;
552 template <
typename TCnt>
553 void PrintHistogram(vector<TCnt>& bins)
556 const int n =
static_cast<int>(bins.size());
557 vector<int> binIds(n);
558 for (
int i = 0; i < n; ++i)
563 PrintHistogram(bins, binIds);
int Gather(const int *sendBuffer, int *recvBuffer, vtkIdType length, int destProcessId)
vtkIdType GetNumberOfTuples()
virtual int GetNumberOfProcesses()
virtual double * GetTuple(vtkIdType tupleIdx)=0
virtual int GetDataType()=0
int GetNumberOfComponents()
virtual int GetLocalProcessId()
VTKWRAPPINGJAVA_EXPORT jlong q(JNIEnv *env, jobject obj)
QDebug & operator<<(QDebug debug, const std::string &stdstring)