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
00028
00029 #include "Teuchos_Utils.hpp"
00030 #include "Teuchos_GlobalMPISession.hpp"
00031
00032 namespace Teuchos {
00033
00034 double Utils::chopVal_ = 1.0e-16;
00035
00036 double Utils::chop(const double& x)
00037 {
00038 if (fabs(x) < chopVal_) return 0;
00039 return x;
00040 }
00041
00042 string Utils::getParallelExtension(
00043 int procRank_in
00044 ,int numProcs_in
00045 )
00046 {
00047
00048 int procRank = -1;
00049 int numProcs = -1;
00050 if( numProcs_in > 0 ) {
00051 procRank = procRank_in;
00052 numProcs = numProcs_in;
00053 }
00054 else {
00055 procRank = Teuchos::GlobalMPISession::getRank();
00056 numProcs = Teuchos::GlobalMPISession::getNProc();
00057 }
00058
00059 int maxProcOrder = 1;
00060 double tmp = numProcs;
00061 for( int i = 0; i < 10; ++i, tmp *= 0.1 ) {
00062 if(tmp >= 1.0)
00063 ++maxProcOrder;
00064 else
00065 break;
00066 }
00067
00068 std::ostringstream parallelExtension;
00069 parallelExtension
00070 << std::setfill('0')
00071 << std::right << std::setw(maxProcOrder)
00072 << numProcs
00073 << "."
00074 << std::setfill('0')
00075 << std::right << std::setw(maxProcOrder)
00076 << procRank;
00077 return parallelExtension.str();
00078 }
00079
00080 string Utils::toString(const int& x)
00081 {
00082 char s[100];
00083 sprintf(s, "%d", x);
00084 return string(s);
00085 }
00086
00087 string Utils::toString(const unsigned int& x)
00088 {
00089 char s[100];
00090 sprintf(s, "%d", x);
00091 return string(s);
00092 }
00093
00094 string Utils::toString(const double& x)
00095 {
00096 char s[100];
00097 sprintf(s, "%g", x);
00098 return string(s);
00099 }
00100
00101
00102 }