Reference documentation for deal.II version 8.4.1
utilities.cc
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2005 - 2015 by the deal.II authors
4 //
5 // This file is part of the deal.II library.
6 //
7 // The deal.II library is free software; you can use it, redistribute
8 // it, and/or modify it under the terms of the GNU Lesser General
9 // Public License as published by the Free Software Foundation; either
10 // version 2.1 of the License, or (at your option) any later version.
11 // The full text of the license can be found in the file LICENSE at
12 // the top level of the deal.II distribution.
13 //
14 // ---------------------------------------------------------------------
15 
16 
17 #include <deal.II/base/utilities.h>
18 #include <deal.II/base/exceptions.h>
19 #include <deal.II/base/thread_local_storage.h>
20 
21 DEAL_II_DISABLE_EXTRA_DIAGNOSTICS
22 #include <boost/math/special_functions/erf.hpp>
23 #include <boost/lexical_cast.hpp>
24 #include <boost/random.hpp>
26 
27 #include <algorithm>
28 #include <cctype>
29 #include <cerrno>
30 #include <cmath>
31 #include <cstddef>
32 #include <cstdio>
33 #include <ctime>
34 #include <fstream>
35 #include <iomanip>
36 #include <iostream>
37 #include <limits>
38 #include <sstream>
39 
40 #ifndef DEAL_II_MSVC
41 # include <stdlib.h>
42 #endif
43 
44 #ifdef DEAL_II_MSVC
45 # include <winsock2.h>
46 #endif
47 
48 
49 #ifdef DEAL_II_WITH_TRILINOS
50 # ifdef DEAL_II_WITH_MPI
51 # include <Epetra_MpiComm.h>
52 # include <deal.II/lac/vector_memory.h>
53 # include <deal.II/lac/trilinos_vector.h>
54 # include <deal.II/lac/trilinos_block_vector.h>
55 # endif
56 # include "Teuchos_RCP.hpp"
57 # include "Epetra_SerialComm.h"
58 #endif
59 
60 
61 
62 DEAL_II_NAMESPACE_OPEN
63 
64 
65 namespace Utilities
66 {
67 
68 
69  DeclException2 (ExcInvalidNumber2StringConversersion,
70  unsigned int, unsigned int,
71  << "When trying to convert " << arg1
72  << " to a string with " << arg2 << " digits");
73  DeclException1 (ExcInvalidNumber,
74  unsigned int,
75  << "Invalid number " << arg1);
76  DeclException1 (ExcCantConvertString,
77  std::string,
78  << "Can't convert the string " << arg1
79  << " to the desired type");
80 
81  std::string
82  int_to_string (const unsigned int value, const unsigned int digits)
83  {
84  return to_string(value,digits);
85  }
86 
87  template <typename number>
88  std::string
89  to_string (const number value, const unsigned int digits)
90  {
91  std::string lc_string = boost::lexical_cast<std::string>(value);
92 
93  if (digits == numbers::invalid_unsigned_int)
94  return lc_string;
95  else if (lc_string.size() < digits)
96  {
97  // We have to add the padding zeroes in front of the number
98  const unsigned int padding_position = (lc_string[0] == '-')
99  ?
100  1
101  :
102  0;
103 
104  const std::string padding(digits - lc_string.size(), '0');
105  lc_string.insert(padding_position, padding);
106  }
107  return lc_string;
108  }
109 
110 
111  std::string
112  replace_in_string(const std::string &input,
113  const std::string &from,
114  const std::string &to)
115  {
116  if (from.empty())
117  return input;
118 
119  std::string out = input;
120  std::string::size_type pos = out.find(from);
121 
122  while (pos != std::string::npos)
123  {
124  out.replace(pos, from.size(), to);
125  pos = out.find(from, pos + to.size());
126  }
127  return out;
128  }
129 
130  std::string
131  trim(const std::string &input)
132  {
133  std::string::size_type left = 0;
134  std::string::size_type right = input.size() - 1;
135 
136  for (; left < input.size(); ++left)
137  {
138  if (!std::isspace(input[left]))
139  {
140  break;
141  }
142  }
143 
144  for (; right >= left; --right)
145  {
146  if (!std::isspace(input[right]))
147  {
148  break;
149  }
150  }
151 
152  return std::string(input, left, right - left + 1);
153  }
154 
155 
156 
157  std::string
158  dim_string(const int dim, const int spacedim)
159  {
160  if (dim == spacedim)
161  return int_to_string(dim);
162  else
163  return int_to_string(dim)+","+int_to_string(spacedim);
164  }
165 
166 
167  unsigned int
168  needed_digits (const unsigned int max_number)
169  {
170  if (max_number < 10)
171  return 1;
172  if (max_number < 100)
173  return 2;
174  if (max_number < 1000)
175  return 3;
176  if (max_number < 10000)
177  return 4;
178  if (max_number < 100000)
179  return 5;
180  if (max_number < 1000000)
181  return 6;
182  AssertThrow (false, ExcInvalidNumber(max_number));
183  return 0;
184  }
185 
186 
187 
188  int
189  string_to_int (const std::string &s_)
190  {
191  // trim whitespace on either side of the text if necessary
192  std::string s = s_;
193  while ((s.size() > 0) && (s[0] == ' '))
194  s.erase (s.begin());
195  while ((s.size() > 0) && (s[s.size()-1] == ' '))
196  s.erase (s.end()-1);
197 
198  // now convert and see whether we succeed. note that strtol only
199  // touches errno if an error occurred, so if we want to check
200  // whether an error happened, we need to make sure that errno==0
201  // before calling strtol since otherwise it may be that the
202  // conversion succeeds and that errno remains at the value it
203  // was before, whatever that was
204  char *p;
205  errno = 0;
206  const int i = std::strtol(s.c_str(), &p, 10);
207  AssertThrow ( !((errno != 0) || (s.size() == 0) || ((s.size()>0) && (*p != '\0'))),
208  ExcMessage ("Can't convert <" + s + "> to an integer."));
209 
210  return i;
211  }
212 
213 
214 
215  std::vector<int>
216  string_to_int (const std::vector<std::string> &s)
217  {
218  std::vector<int> tmp (s.size());
219  for (unsigned int i=0; i<s.size(); ++i)
220  tmp[i] = string_to_int (s[i]);
221  return tmp;
222  }
223 
224 
225 
226  double
227  string_to_double (const std::string &s_)
228  {
229  // trim whitespace on either side of the text if necessary
230  std::string s = s_;
231  while ((s.size() > 0) && (s[0] == ' '))
232  s.erase (s.begin());
233  while ((s.size() > 0) && (s[s.size()-1] == ' '))
234  s.erase (s.end()-1);
235 
236  // now convert and see whether we succeed. note that strtol only
237  // touches errno if an error occurred, so if we want to check
238  // whether an error happened, we need to make sure that errno==0
239  // before calling strtol since otherwise it may be that the
240  // conversion succeeds and that errno remains at the value it
241  // was before, whatever that was
242  char *p;
243  errno = 0;
244  const double d = std::strtod(s.c_str(), &p);
245  AssertThrow ( !((errno != 0) || (s.size() == 0) || ((s.size()>0) && (*p != '\0'))),
246  ExcMessage ("Can't convert <" + s + "> to an integer."));
247 
248  return d;
249  }
250 
251 
252 
253  std::vector<double>
254  string_to_double (const std::vector<std::string> &s)
255  {
256  std::vector<double> tmp (s.size());
257  for (unsigned int i=0; i<s.size(); ++i)
258  tmp[i] = string_to_double (s[i]);
259  return tmp;
260  }
261 
262 
263 
264  std::vector<std::string>
265  split_string_list (const std::string &s,
266  const char delimiter)
267  {
268  // keep the currently remaining part of the input string in 'tmp' and
269  // keep chopping elements of the list off the front
270  std::string tmp = s;
271 
272  // as discussed in the documentation, eat whitespace from the end
273  // of the string
274  while (tmp.length() != 0 && tmp[tmp.length()-1] == ' ')
275  tmp.erase (tmp.length()-1, 1);
276 
277  // split the input list until it is empty. since in every iteration
278  // 'tmp' is what's left of the string after the next delimiter,
279  // and since we've stripped trailing space already, 'tmp' will
280  // be empty at one point if 's' ended in a delimiter, even if
281  // there was space after the last delimiter. this matches what's
282  // discussed in the documentation
283  std::vector<std::string> split_list;
284  split_list.reserve (std::count (tmp.begin(), tmp.end(), delimiter)+1);
285  while (tmp.length() != 0)
286  {
287  std::string name;
288  name = tmp;
289 
290  if (name.find(delimiter) != std::string::npos)
291  {
292  name.erase (name.find(delimiter), std::string::npos);
293  tmp.erase (0, tmp.find(delimiter)+1);
294  }
295  else
296  tmp = "";
297 
298  // strip spaces from this element's front and end
299  while ((name.length() != 0) && (name[0] == ' '))
300  name.erase (0,1);
301  while (name.length() != 0 && name[name.length()-1] == ' ')
302  name.erase (name.length()-1, 1);
303 
304  split_list.push_back (name);
305  }
306 
307  return split_list;
308  }
309 
310 
311 
312  std::vector<std::string>
313  break_text_into_lines (const std::string &original_text,
314  const unsigned int width,
315  const char delimiter)
316  {
317  std::string text = original_text;
318  std::vector<std::string> lines;
319 
320  // remove trailing spaces
321  while ((text.length() != 0) && (text[text.length()-1] == delimiter))
322  text.erase(text.length()-1,1);
323 
324  // then split the text into lines
325  while (text.length() != 0)
326  {
327  // in each iteration, first remove
328  // leading spaces
329  while ((text.length() != 0) && (text[0] == delimiter))
330  text.erase(0, 1);
331 
332  std::size_t pos_newline = text.find_first_of("\n", 0);
333  if (pos_newline != std::string::npos && pos_newline <= width)
334  {
335  std::string line (text, 0, pos_newline);
336  while ((line.length() != 0) && (line[line.length()-1] == delimiter))
337  line.erase(line.length()-1,1);
338  lines.push_back (line);
339  text.erase (0, pos_newline+1);
340  continue;
341  }
342 
343  // if we can fit everything into one
344  // line, then do so. otherwise, we have
345  // to keep breaking
346  if (text.length() < width)
347  {
348  // remove trailing spaces
349  while ((text.length() != 0) && (text[text.length()-1] == delimiter))
350  text.erase(text.length()-1,1);
351  lines.push_back (text);
352  text = "";
353  }
354  else
355  {
356  // starting at position width, find the
357  // location of the previous space, so
358  // that we can break around there
359  int location = std::min<int>(width,text.length()-1);
360  for (; location>0; --location)
361  if (text[location] == delimiter)
362  break;
363 
364  // if there are no spaces, then try if
365  // there are spaces coming up
366  if (location == 0)
367  for (location = std::min<int>(width,text.length()-1);
368  location<static_cast<int>(text.length());
369  ++location)
370  if (text[location] == delimiter)
371  break;
372 
373  // now take the text up to the found
374  // location and put it into a single
375  // line, and remove it from 'text'
376  std::string line (text, 0, location);
377  while ((line.length() != 0) && (line[line.length()-1] == delimiter))
378  line.erase(line.length()-1,1);
379  lines.push_back (line);
380  text.erase (0, location);
381  }
382  }
383 
384  return lines;
385  }
386 
387 
388 
389  bool
390  match_at_string_start (const std::string &name,
391  const std::string &pattern)
392  {
393  if (pattern.size() > name.size())
394  return false;
395 
396  for (unsigned int i=0; i<pattern.size(); ++i)
397  if (pattern[i] != name[i])
398  return false;
399 
400  return true;
401  }
402 
403 
404 
405  std::pair<int, unsigned int>
406  get_integer_at_position (const std::string &name,
407  const unsigned int position)
408  {
409  Assert (position < name.size(), ExcInternalError());
410 
411  const std::string test_string (name.begin()+position,
412  name.end());
413 
414  std::istringstream str(test_string);
415 
416  int i;
417  if (str >> i)
418  {
419  // compute the number of
420  // digits of i. assuming it
421  // is less than 8 is likely
422  // ok
423  if (i<10)
424  return std::make_pair (i, 1U);
425  else if (i<100)
426  return std::make_pair (i, 2U);
427  else if (i<1000)
428  return std::make_pair (i, 3U);
429  else if (i<10000)
430  return std::make_pair (i, 4U);
431  else if (i<100000)
432  return std::make_pair (i, 5U);
433  else if (i<1000000)
434  return std::make_pair (i, 6U);
435  else if (i<10000000)
436  return std::make_pair (i, 7U);
437  else
438  {
439  Assert (false, ExcNotImplemented());
440  return std::make_pair (-1, numbers::invalid_unsigned_int);
441  }
442  }
443  else
444  return std::make_pair (-1, numbers::invalid_unsigned_int);
445  }
446 
447 
448 
449  double
451  const double sigma)
452  {
453  // if no noise: return now
454  if (sigma == 0)
455  return a;
456 
457  // we would want to use rand(), but that function is not reentrant
458  // in a thread context. one could use rand_r, but this does not
459  // produce reproducible results between threads either (though at
460  // least it is reentrant). these two approaches being
461  // non-workable, use a thread-local random number generator here
462  static Threads::ThreadLocalStorage<boost::mt19937> random_number_generator;
463  return boost::normal_distribution<>(a,sigma)(random_number_generator.get());
464  }
465 
466 
467 
468  std::vector<unsigned int>
469  reverse_permutation (const std::vector<unsigned int> &permutation)
470  {
471  const unsigned int n = permutation.size();
472 
473  std::vector<unsigned int> out (n);
474  for (unsigned int i=0; i<n; ++i)
475  out[i] = n - 1 - permutation[i];
476 
477  return out;
478  }
479 
480 
481 
482  std::vector<unsigned int>
483  invert_permutation (const std::vector<unsigned int> &permutation)
484  {
485  const unsigned int n = permutation.size();
486 
487  std::vector<unsigned int> out (n, numbers::invalid_unsigned_int);
488 
489  for (unsigned int i=0; i<n; ++i)
490  {
491  Assert (permutation[i] < n, ExcIndexRange (permutation[i], 0, n));
492  out[permutation[i]] = i;
493  }
494 
495  // check that we have actually reached
496  // all indices
497  for (unsigned int i=0; i<n; ++i)
499  ExcMessage ("The given input permutation had duplicate entries!"));
500 
501  return out;
502  }
503 
504  std::vector<unsigned long long int>
505  reverse_permutation (const std::vector<unsigned long long int> &permutation)
506  {
507  const unsigned long long int n = permutation.size();
508 
509  std::vector<unsigned long long int> out (n);
510  for (unsigned long long int i=0; i<n; ++i)
511  out[i] = n - 1 - permutation[i];
512 
513  return out;
514  }
515 
516 
517 
518  std::vector<unsigned long long int>
519  invert_permutation (const std::vector<unsigned long long int> &permutation)
520  {
521  const unsigned long long int n = permutation.size();
522 
523  std::vector<unsigned long long int> out (n, numbers::invalid_unsigned_int);
524 
525  for (unsigned long long int i=0; i<n; ++i)
526  {
527  Assert (permutation[i] < n, ExcIndexRange (permutation[i], 0, n));
528  out[permutation[i]] = i;
529  }
530 
531  // check that we have actually reached
532  // all indices
533  for (unsigned long long int i=0; i<n; ++i)
535  ExcMessage ("The given input permutation had duplicate entries!"));
536 
537  return out;
538  }
539 
540 
541  template <typename Integer>
542  std::vector<Integer>
543  reverse_permutation (const std::vector<Integer> &permutation)
544  {
545  const unsigned int n = permutation.size();
546 
547  std::vector<Integer> out (n);
548  for (unsigned int i=0; i<n; ++i)
549  out[i] = n - 1 - permutation[i];
550 
551  return out;
552  }
553 
554 
555 
556  template <typename Integer>
557  std::vector<Integer>
558  invert_permutation (const std::vector<Integer> &permutation)
559  {
560  const unsigned int n = permutation.size();
561 
562  std::vector<Integer> out (n, numbers::invalid_unsigned_int);
563 
564  for (unsigned int i=0; i<n; ++i)
565  {
566  Assert (permutation[i] < n, ExcIndexRange (permutation[i], 0, n));
567  out[permutation[i]] = i;
568  }
569 
570  // check that we have actually reached
571  // all indices
572  for (unsigned int i=0; i<n; ++i)
574  ExcMessage ("The given input permutation had duplicate entries!"));
575 
576  return out;
577  }
578 
579 
580 
581 
582  namespace System
583  {
584 #if defined(__linux__)
585 
586  double get_cpu_load ()
587  {
588  std::ifstream cpuinfo;
589  cpuinfo.open("/proc/loadavg");
590 
591  AssertThrow(cpuinfo, ExcIO());
592 
593  double load;
594  cpuinfo >> load;
595 
596  return load;
597  }
598 
599 #else
600 
601  double get_cpu_load ()
602  {
603  return 0.;
604  }
605 
606 #endif
607 
608 
609 
611  {
612  stats.VmPeak = stats.VmSize = stats.VmHWM = stats.VmRSS = 0;
613 
614  // parsing /proc/self/stat would be a
615  // lot easier, but it does not contain
616  // VmHWM, so we use /status instead.
617 #if defined(__linux__)
618  std::ifstream file("/proc/self/status");
619  std::string line;
620  std::string name;
621  while (!file.eof())
622  {
623  file >> name;
624  if (name == "VmPeak:")
625  file >> stats.VmPeak;
626  else if (name == "VmSize:")
627  file >> stats.VmSize;
628  else if (name == "VmHWM:")
629  file >> stats.VmHWM;
630  else if (name == "VmRSS:")
631  {
632  file >> stats.VmRSS;
633  break; //this is always the last entry
634  }
635 
636  getline(file, line);
637  }
638 #endif
639  }
640 
641 
642 
643  std::string get_hostname ()
644  {
645 #if defined(DEAL_II_HAVE_UNISTD_H) && defined(DEAL_II_HAVE_GETHOSTNAME)
646  const unsigned int N=1024;
647  char hostname[N];
648  gethostname (&(hostname[0]), N-1);
649 #else
650  std::string hostname("unknown");
651 #endif
652  return hostname;
653  }
654 
655 
656 
657  std::string get_time ()
658  {
659  std::time_t time1= std::time (0);
660  std::tm *time = std::localtime(&time1);
661 
662  std::ostringstream o;
663  o << time->tm_hour << ":"
664  << (time->tm_min < 10 ? "0" : "") << time->tm_min << ":"
665  << (time->tm_sec < 10 ? "0" : "") << time->tm_sec;
666 
667  return o.str();
668  }
669 
670 
671 
672  std::string get_date ()
673  {
674  std::time_t time1= std::time (0);
675  std::tm *time = std::localtime(&time1);
676 
677  std::ostringstream o;
678  o << time->tm_year + 1900 << "/"
679  << time->tm_mon + 1 << "/"
680  << time->tm_mday;
681 
682  return o.str();
683  }
684 
685 
686 
687  void posix_memalign (void **memptr, size_t alignment, size_t size)
688  {
689 #ifndef DEAL_II_MSVC
690  const int ierr = ::posix_memalign (memptr, alignment, size);
691 
692  AssertThrow (ierr == 0, ExcOutOfMemory());
693  AssertThrow (*memptr != 0, ExcOutOfMemory());
694 #else
695  // Windows does not appear to have posix_memalign. just use the
696  // regular malloc in that case
697  *memptr = malloc (size);
698  (void)alignment;
699  AssertThrow (*memptr != 0, ExcOutOfMemory());
700 #endif
701  }
702 
703 
704 
706  {
708  }
709  }
710 
711 
712 #ifdef DEAL_II_WITH_TRILINOS
713 
714  namespace Trilinos
715  {
716  const Epetra_Comm &
718  {
719 #ifdef DEAL_II_WITH_MPI
720  static Teuchos::RCP<Epetra_MpiComm>
721  communicator = Teuchos::rcp (new Epetra_MpiComm (MPI_COMM_WORLD), true);
722 #else
723  static Teuchos::RCP<Epetra_SerialComm>
724  communicator = Teuchos::rcp (new Epetra_SerialComm (), true);
725 #endif
726 
727  return *communicator;
728  }
729 
730 
731 
732  const Epetra_Comm &
734  {
735 #ifdef DEAL_II_WITH_MPI
736  static Teuchos::RCP<Epetra_MpiComm>
737  communicator = Teuchos::rcp (new Epetra_MpiComm (MPI_COMM_SELF), true);
738 #else
739  static Teuchos::RCP<Epetra_SerialComm>
740  communicator = Teuchos::rcp (new Epetra_SerialComm (), true);
741 #endif
742 
743  return *communicator;
744  }
745 
746 
747 
748  Epetra_Comm *
749  duplicate_communicator (const Epetra_Comm &communicator)
750  {
751 #ifdef DEAL_II_WITH_MPI
752 
753  // see if the communicator is in fact a
754  // parallel MPI communicator; if so,
755  // return a duplicate of it
756  const Epetra_MpiComm
757  *mpi_comm = dynamic_cast<const Epetra_MpiComm *>(&communicator);
758  if (mpi_comm != 0)
759  return new Epetra_MpiComm(Utilities::MPI::
760  duplicate_communicator(mpi_comm->GetMpiComm()));
761 #endif
762 
763  // if we don't support MPI, or if the
764  // communicator in question was in fact
765  // not an MPI communicator, return a
766  // copy of the same object again
767  Assert (dynamic_cast<const Epetra_SerialComm *>(&communicator)
768  != 0,
769  ExcInternalError());
770  return new Epetra_SerialComm(dynamic_cast<const Epetra_SerialComm &>(communicator));
771  }
772 
773 
774 
775  void destroy_communicator (Epetra_Comm &communicator)
776  {
777  // save the communicator, reset the map, and delete the communicator if
778  // this whole thing was created as an MPI communicator
779 #ifdef DEAL_II_WITH_MPI
780  Epetra_MpiComm
781  *mpi_comm = dynamic_cast<Epetra_MpiComm *>(&communicator);
782  if (mpi_comm != 0)
783  {
784  MPI_Comm comm = mpi_comm->GetMpiComm();
785  *mpi_comm = Epetra_MpiComm(MPI_COMM_SELF);
786  MPI_Comm_free (&comm);
787  }
788 #endif
789  }
790 
791 
792 
793  unsigned int get_n_mpi_processes (const Epetra_Comm &mpi_communicator)
794  {
795  return mpi_communicator.NumProc();
796  }
797 
798 
799  unsigned int get_this_mpi_process (const Epetra_Comm &mpi_communicator)
800  {
801  return (unsigned int)mpi_communicator.MyPID();
802  }
803 
804 
805 
806  Epetra_Map
807  duplicate_map (const Epetra_BlockMap &map,
808  const Epetra_Comm &comm)
809  {
810  if (map.LinearMap() == true)
811  {
812  // each processor stores a
813  // contiguous range of
814  // elements in the
815  // following constructor
816  // call
817  return Epetra_Map (map.NumGlobalElements(),
818  map.NumMyElements(),
819  map.IndexBase(),
820  comm);
821  }
822  else
823  {
824  // the range is not
825  // contiguous
826  return Epetra_Map (map.NumGlobalElements(),
827  map.NumMyElements(),
828  map.MyGlobalElements (),
829  0,
830  comm);
831  }
832  }
833  }
834 
835 #endif
836 
837  template std::string to_string<int> (int, unsigned int);
838  template std::string to_string<long int> (long int, unsigned int);
839  template std::string to_string<long long int> (long long int, unsigned int);
840  template std::string to_string<unsigned int> (unsigned int, unsigned int);
841  template std::string to_string<unsigned long int> (unsigned long int, unsigned int);
842  template std::string to_string<unsigned long long int> (unsigned long long int, unsigned int);
843  template std::string to_string<float> (float, unsigned int);
844  template std::string to_string<double> (double, unsigned int);
845  template std::string to_string<long double> (long double, unsigned int);
846 
847 }
848 
849 DEAL_II_NAMESPACE_CLOSE
static const unsigned int invalid_unsigned_int
Definition: types.h:164
#define DeclException2(Exception2, type1, type2, outsequence)
Definition: exceptions.h:552
A class that provides a separate storage location on each thread that accesses the object...
unsigned int get_n_mpi_processes(const Epetra_Comm &mpi_communicator)
Definition: utilities.cc:793
::ExceptionBase & ExcMessage(std::string arg1)
std::string trim(const std::string &input)
Definition: utilities.cc:131
std::pair< int, unsigned int > get_integer_at_position(const std::string &name, const unsigned int position)
Definition: utilities.cc:406
#define AssertThrow(cond, exc)
Definition: exceptions.h:358
const Epetra_Comm & comm_self()
Definition: utilities.cc:733
bool job_supports_mpi() DEAL_II_DEPRECATED
Definition: utilities.cc:705
std::string get_date()
Definition: utilities.cc:672
std::string to_string(const number value, const unsigned int digits=numbers::invalid_unsigned_int)
Definition: utilities.cc:89
void get_memory_stats(MemoryStats &stats)
Definition: utilities.cc:610
double string_to_double(const std::string &s)
Definition: utilities.cc:227
double get_cpu_load()
Definition: utilities.cc:601
Epetra_Comm * duplicate_communicator(const Epetra_Comm &communicator)
Definition: utilities.cc:749
#define DeclException1(Exception1, type1, outsequence)
Definition: exceptions.h:542
double generate_normal_random_number(const double a, const double sigma)
Definition: utilities.cc:450
#define Assert(cond, exc)
Definition: exceptions.h:294
unsigned long int VmSize
Definition: utilities.h:394
bool match_at_string_start(const std::string &name, const std::string &pattern)
Definition: utilities.cc:390
void posix_memalign(void **memptr, size_t alignment, size_t size)
Definition: utilities.cc:687
std::vector< unsigned int > invert_permutation(const std::vector< unsigned int > &permutation)
Definition: utilities.cc:483
std::string int_to_string(const unsigned int value, const unsigned int digits=numbers::invalid_unsigned_int)
Definition: utilities.cc:82
std::string replace_in_string(const std::string &input, const std::string &from, const std::string &to)
Definition: utilities.cc:112
std::string dim_string(const int dim, const int spacedim)
Definition: utilities.cc:158
void destroy_communicator(Epetra_Comm &communicator)
Definition: utilities.cc:775
Definition: mpi.h:55
std::vector< std::string > break_text_into_lines(const std::string &original_text, const unsigned int width, const char delimiter= ' ')
Definition: utilities.cc:313
std::string get_hostname()
Definition: utilities.cc:643
unsigned long int VmHWM
Definition: utilities.h:395
const Epetra_Comm & comm_world()
Definition: utilities.cc:717
std::vector< std::string > split_string_list(const std::string &s, const char delimiter= ',')
Definition: utilities.cc:265
int string_to_int(const std::string &s)
Definition: utilities.cc:189
std::vector< unsigned int > reverse_permutation(const std::vector< unsigned int > &permutation)
Definition: utilities.cc:469
unsigned long int VmRSS
Definition: utilities.h:396
unsigned int get_this_mpi_process(const Epetra_Comm &mpi_communicator)
Definition: utilities.cc:799
Epetra_Map duplicate_map(const Epetra_BlockMap &map, const Epetra_Comm &comm)
Definition: utilities.cc:807
std::string get_time()
Definition: utilities.cc:657
bool job_supports_mpi()
Definition: mpi.h:746
unsigned int needed_digits(const unsigned int max_number)
Definition: utilities.cc:168