std::vector<int>
string_to_int (const std::vector<std::string> &s);
+ /**
+ * Given a string, convert it to an
+ * double. Throw an assertion if that is
+ * not possible.
+ */
+ double
+ string_to_double (const std::string &s);
+
+
+ /**
+ * Given a list of strings, convert it to a
+ * list of doubles. Throw an assertion if
+ * that is not possible.
+ */
+ std::vector<double>
+ string_to_double (const std::vector<std::string> &s);
+
/**
* Given a string that contains text
* separated by a @p delimiter, split it into
lower_bound (Iterator first,
Iterator last,
const T &val);
-
+
/**
* The same function as above, but taking
Iterator last,
const T &val,
const Comp comp);
-
+
/**
* Given a permutation vector (i.e. a
* vector $p_0\ldots p_{N-1}$ where each
unsigned long int VmHWM; /** peak resident memory size in kB */
unsigned long int VmRSS; /** current resident memory size in kB */
};
-
-
+
+
/**
* Fills the @param stats structure with
* information about the memory
* only implemented on Linux.
*/
void get_memory_stats (MemoryStats & stats);
-
+
/**
* Return the name of the host this
void calculate_collective_mpi_min_max_avg(const MPI_Comm &mpi_communicator,
const double my_value,
MinMaxAvg & result);
-
-
+
+
/**
* A class that is used to initialize the
* MPI system at the beginning of a
{
return Utilities::lower_bound (first, last, val,
std::less<T>());
- }
+ }
else
len = half;
}
- }
+ }
}
/**
}
return first;
}
-
+
DEAL_II_NAMESPACE_CLOSE
// $Id$
// Version: $Name$
//
-// Copyright (C) 2005, 2006, 2008, 2009, 2010 by the deal.II authors
+// Copyright (C) 2005, 2006, 2008, 2009, 2010, 2011 by the deal.II authors
//
// This file is subject to QPL and may not be distributed
// without copyright and license information. Please refer
+ double
+ string_to_double (const std::string &s)
+ {
+ std::istringstream ss(s);
+
+#ifdef HAVE_STD_NUMERIC_LIMITS
+ static const double max_double = std::numeric_limits<double>::max();
+#else
+ static const double max_double = DBL_MAX;
+#endif
+
+ double i = max_double;
+ ss >> i;
+
+ // check for errors
+ AssertThrow (i != max_double, ExcCantConvertString (s));
+
+ return i;
+ }
+
+
+
+ std::vector<double>
+ string_to_double (const std::vector<std::string> &s)
+ {
+ std::vector<double> tmp (s.size());
+ for (unsigned int i=0; i<s.size(); ++i)
+ tmp[i] = string_to_double (s[i]);
+ return tmp;
+ }
+
+
+
std::vector<std::string>
split_string_list (const std::string &s,
const char delimiter)
#endif
-
+
void get_memory_stats (MemoryStats & stats)
{
stats.VmPeak = stats.VmSize = stats.VmHWM = stats.VmRSS = 0;
// parsing /proc/self/stat would be a
// lot easier, but it does not contain
// VmHWM, so we use /status instead.
-#if defined(__linux__)
+#if defined(__linux__)
std::ifstream file("/proc/self/status");
std::string line;
std::string name;
file >> stats.VmRSS;
break; //this is always the last entry
}
-
+
getline(file, line);
}
#endif
}
-
-
+
+
std::string get_hostname ()
{
}
- namespace
+ namespace
{
// custom MIP_Op for
// calculate_collective_mpi_min_max_avg
{
const MinMaxAvg * in_lhs = static_cast<const MinMaxAvg*>(in_lhs_);
MinMaxAvg * inout_rhs = static_cast<MinMaxAvg*>(inout_rhs_);
-
+
Assert(*len==1, ExcInternalError());
-
+
inout_rhs->sum += in_lhs->sum;
if (inout_rhs->min>in_lhs->min)
{
if (inout_rhs->min_index > in_lhs->min_index)
inout_rhs->min_index = in_lhs->min_index;
}
-
+
if (inout_rhs->max < in_lhs->max)
{
inout_rhs->max = in_lhs->max;
}
-
+
void calculate_collective_mpi_min_max_avg(const MPI_Comm &mpi_communicator,
double my_value,
MinMaxAvg & result)
= dealii::Utilities::System::get_this_mpi_process(mpi_communicator);
const unsigned int numproc
= dealii::Utilities::System::get_n_mpi_processes(mpi_communicator);
-
+
MPI_Op op;
int ierr = MPI_Op_create((MPI_User_function *)&max_reduce, true, &op);
AssertThrow(ierr == MPI_SUCCESS, ExcInternalError());
-
+
MinMaxAvg in;
in.sum = in.min = in.max = my_value;
in.min_index = in.max_index = my_id;
-
+
MPI_Datatype type;
int lengths[]={3,2};
MPI_Aint displacements[]={0,offsetof(MinMaxAvg, min_index)};
MPI_Datatype types[]={MPI_DOUBLE, MPI_INT};
-
+
ierr = MPI_Type_struct(2, lengths, displacements, types, &type);
AssertThrow(ierr == MPI_SUCCESS, ExcInternalError());
-
+
ierr = MPI_Type_commit(&type);
ierr = MPI_Allreduce ( &in, &result, 1, type, op, mpi_communicator );
AssertThrow(ierr == MPI_SUCCESS, ExcInternalError());
-
+
ierr = MPI_Type_free (&type);
AssertThrow(ierr == MPI_SUCCESS, ExcInternalError());
-
+
ierr = MPI_Op_free(&op);
AssertThrow(ierr == MPI_SUCCESS, ExcInternalError());
result.avg = result.sum / numproc;
}
-
+
std::vector<unsigned int>
compute_point_to_point_communication_pattern (const MPI_Comm & mpi_comm,
const std::vector<unsigned int> & destinations)
return 0;
}
-
+
void calculate_collective_mpi_min_max_avg(const MPI_Comm &,
double my_value,
MinMaxAvg & result)
result.min = my_value;
result.max = my_value;
result.min_index = 0;
- result.max_index = 0;
+ result.max_index = 0;
}
-
+
MPI_Comm duplicate_communicator (const MPI_Comm &mpi_communicator)
{
MPI_has_been_started != 0)
{
if (std::uncaught_exception())
- {
+ {
std::cerr << "ERROR: Uncaught exception in MPI_InitFinalize on proc "
<< get_this_mpi_process(MPI_COMM_WORLD)
<< ". Skipping MPI_Finalize() to avoid a deadlock."
else
mpi_err = MPI_Finalize();
}
-
+
AssertThrow (mpi_err == 0,
ExcMessage ("An error occurred while calling MPI_Finalize()"));