5 #ifndef vtkMaterialInterfaceUtilities_h 6 #define vtkMaterialInterfaceUtilities_h 14 #ifdef vtkMaterialInterfaceFilterDEBUG 15 #include "vtkStringFormatter.h" 24 using std::ostringstream;
38 void ClearVectorOfPointers(vector<T*>& V)
41 for (
size_t i = 0; i < n; ++i)
52 void ClearVectorOfVtkPointers(vector<T*>& V)
55 for (
size_t i = 0; i < n; ++i)
66 void ClearVectorOfArrayPointers(vector<T*>& V)
69 for (
size_t i = 0; i < n; ++i)
80 void ResizeVectorOfVtkPointers(vector<T*>& V,
int n)
82 ClearVectorOfVtkPointers(V);
85 for (
int i = 0; i < n; ++i)
92 void ResizeVectorOfArrayPointers(vector<T*>& V,
int nV,
int nA)
94 ClearVectorOfArrayPointers(V);
97 for (
int i = 0; i < nV; ++i)
104 void ResizeVectorOfVtkArrayPointers(vector<T*>& V,
int nComps,
vtkIdType nTups,
string name,
int nv)
106 ClearVectorOfVtkPointers(V);
109 for (
int i = 0; i < nv; ++i)
112 V[i]->SetNumberOfComponents(nComps);
113 V[i]->SetNumberOfTuples(nTups);
114 V[i]->SetName(name.c_str());
119 void ResizeVectorOfVtkArrayPointers(vector<T*>& V,
int nComps,
int nv)
121 ResizeVectorOfVtkArrayPointers(V, nComps, 0,
"", nv);
125 void ResizeVectorOfVtkArrayPointers(vector<T*>& V,
int nComps,
int nTups,
int nv)
127 ResizeVectorOfVtkArrayPointers(V, nComps, nTups,
"", nv);
132 inline void ReNewVtkPointer(T*& pv)
142 inline void NewVtkArrayPointer(T*& pv,
int nComps,
vtkIdType nTups, std::string name)
145 pv->SetNumberOfComponents(nComps);
146 pv->SetNumberOfTuples(nTups);
147 pv->SetName(name.c_str());
151 inline void ReNewVtkArrayPointer(T*& pv,
int nComps,
vtkIdType nTups, std::string name)
157 NewVtkArrayPointer(pv, nComps, nTups, name);
161 inline void ReNewVtkArrayPointer(T*& pv, std::string name)
163 ReNewVtkArrayPointer(pv, 1, 0, name);
167 inline void ReleaseVtkPointer(T*& pv)
169 assert(
"Attempted to release a 0 pointer." && pv != 0);
175 inline void CheckAndReleaseVtkPointer(T*& pv)
186 inline void CheckAndReleaseArrayPointer(T*& pv)
197 inline void CheckAndReleaseCArrayPointer(T*& pv)
208 inline void FillVector(vector<T>& V,
const T& v)
211 for (
size_t i = 0; i < n; ++i)
221 inline int CopyTuple(T* dest,
227 int srcIndex = nComps * srcCellIndex;
233 float* thisTuple =
dynamic_cast<vtkFloatArray*
>(src)->GetPointer(srcIndex);
234 for (
int q = 0;
q < nComps; ++
q)
236 dest[
q] =
static_cast<T
>(thisTuple[
q]);
242 double* thisTuple =
dynamic_cast<vtkDoubleArray*
>(src)->GetPointer(srcIndex);
243 for (
int q = 0;
q < nComps; ++
q)
245 dest[
q] =
static_cast<T
>(thisTuple[
q]);
251 int* thisTuple =
dynamic_cast<vtkIntArray*
>(src)->GetPointer(srcIndex);
252 for (
int q = 0;
q < nComps; ++
q)
254 dest[
q] =
static_cast<T
>(thisTuple[
q]);
261 for (
int q = 0;
q < nComps; ++
q)
263 dest[
q] =
static_cast<T
>(thisTuple[
q]);
268 assert(
"This data type is unsupported." && 0);
275 #ifdef vtkMaterialInterfaceFilterDEBUG 283 const int hostNameSize = 256;
284 char hostname[hostNameSize] = {
'\0' };
285 gethostname(hostname, hostNameSize);
287 const int hrpSize = 512;
288 auto hrp = vtk::format(
"{} : {} : {}", hostname, myProcId, pid);
293 hrpBuffer =
new char[nProcs * hrpSize];
295 comm->
Gather(hrp.c_str(), hrpBuffer, hrpSize, 0);
301 hrpFile.open(pidFileName.c_str());
302 char* thisHrp = hrpBuffer;
303 if (hrpFile.is_open())
305 for (
int procId = 0; procId < nProcs; ++procId)
307 hrpFile << thisHrp << endl;
315 for (
int procId = 0; procId < nProcs; ++procId)
317 std::cerr << thisHrp << endl;
327 string GetMemoryUsage(
int pid,
int line,
int procId)
329 ostringstream memoryUsage;
331 ostringstream statusFileName;
332 statusFileName <<
"/proc/" << pid <<
"/status";
334 statusFile.open(statusFileName.str().c_str());
335 if (statusFile.is_open())
337 const int cbufSize = 1024;
338 char cbuf[cbufSize] = {
'\0' };
339 while (statusFile.good())
341 statusFile.getline(cbuf, cbufSize);
343 if (
content.find(
"VmSize") != string::npos ||
content.find(
"VmRSS") != string::npos ||
344 content.find(
"VmData") != string::npos)
346 int tabStart =
content.find_first_of(
"\t ");
348 while (content[tabStart + tabSpan] ==
'\t' || content[tabStart + tabSpan] ==
' ')
352 string formattedContent =
353 content.substr(0, tabStart - 1) +
" " +
content.substr(tabStart + tabSpan);
354 memoryUsage <<
"[" << line <<
"] " << procId <<
" " << formattedContent << endl;
361 std::cerr <<
"[" << line <<
"] " << procId <<
" could not open " << statusFileName <<
"." 365 return memoryUsage.str();
369 void writeTuple(ostream& sout, T* tup,
int nComp)
377 sout <<
"(" << tup[0];
378 for (
int q = 1;
q < nComp; ++
q)
380 sout <<
", " << tup[
q];
388 sout <<
"Name: " << da.
GetName() << endl;
393 sout <<
"NumberOfComps: " << nComp << endl;
394 sout <<
"NumberOfTuples:" << nTup << endl;
397 sout <<
"{}" << endl;
403 writeTuple(sout, thisTup, nComp);
404 for (
int i = 1; i < nTup; ++i)
408 writeTuple(sout, thisTup, nComp);
415 ostream& operator<<(ostream& sout, vector<vtkDoubleArray*>& vda)
417 size_t nda = vda.size();
418 for (
size_t i = 0; i < nda; ++i)
420 sout <<
"[" << i <<
"]\n" << *vda[i] << endl;
425 ostream& operator<<(ostream& sout, vector<vector<int>>& vvi)
427 size_t nv = vvi.size();
428 for (
size_t i = 0; i < nv; ++i)
430 sout <<
"[" << i <<
"]{";
431 size_t ni = vvi[i].size();
438 for (
size_t j = 1; j < ni; ++j)
440 sout <<
"," << vvi[i][j];
447 ostream& operator<<(ostream& sout, vector<int>& vi)
450 size_t ni = vi.size();
457 for (
size_t j = 1; j < ni; ++j)
459 sout <<
"," << vi[j];
515 template <
typename TCnt,
typename TLabel>
516 void PrintHistogram(vector<TCnt>& bins, vector<TLabel>& binIds)
518 const int maxWidth = 40;
519 const size_t n = bins.size();
524 int maxBin = *max_element(bins.begin(), bins.end());
525 for (
size_t i = 0; i < n; ++i)
532 int wid = maxBin < maxWidth ? bins[i] : bins[i] * maxWidth / maxBin;
533 std::cerr <<
"{" << setw(12) << std::left << binIds[i] <<
"}*";
534 for (
int j = 1; j < wid; ++j)
538 std::cerr <<
"(" << bins[i] <<
")" << endl;
542 template <
typename TCnt>
543 void PrintHistogram(vector<TCnt>& bins)
546 const int n =
static_cast<int>(bins.size());
547 vector<int> binIds(n);
548 for (
int i = 0; i < n; ++i)
553 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()
T * operator<<(T *LHS, const pqConnect &RHS)
Makes a Qt connection.
virtual int GetLocalProcessId()
VTKWRAPPINGJAVA_EXPORT jlong q(JNIEnv *env, jobject obj)