]> https://gitweb.dealii.org/ - dealii.git/commitdiff
use std::string instead of char * 7329/head
authorBenjamin Brands <benjamin.brands@fau.de>
Thu, 11 Oct 2018 08:47:39 +0000 (10:47 +0200)
committerBenjamin Brands <benjamin.brands@fau.de>
Thu, 11 Oct 2018 09:12:39 +0000 (11:12 +0200)
include/deal.II/lac/scalapack.h
source/lac/scalapack.cc
tests/scalapack/scalapack_10.cc
tests/scalapack/scalapack_10_a.cc
tests/scalapack/scalapack_10_b.cc
tests/scalapack/scalapack_10_c.cc
tests/scalapack/scalapack_10_d.cc

index 693f1b4217126f9445a9b36d333a78b096e7c6aa..f5d9d0a8f70f2bd23e2bac87b3bce4941325c8db 100644 (file)
@@ -467,6 +467,17 @@ public:
    * and <tt>chunk_size.second</tt> the number of columns.
    */
   void
+  save(const std::string &                          filename,
+       const std::pair<unsigned int, unsigned int> &chunk_size =
+         std::make_pair(numbers::invalid_unsigned_int,
+                        numbers::invalid_unsigned_int)) const;
+
+  /**
+   * Same as above but takes a filename as a <code>char</code> pointer.
+   *
+   * @deprecated This function is deprecated. Use the one taking <code>std::string</code> instead.
+   */
+  DEAL_II_DEPRECATED void
   save(const char *                                 filename,
        const std::pair<unsigned int, unsigned int> &chunk_size =
          std::make_pair(numbers::invalid_unsigned_int,
@@ -484,6 +495,14 @@ public:
    * and distribute the content to the other processes subsequently.
    */
   void
+  load(const std::string &filename);
+
+  /**
+   * Same as above but takes a filename as a <code>char</code> pointer.
+   *
+   * @deprecated This function is deprecated. Use the one taking <code>std::string</code> instead.
+   */
+  DEAL_II_DEPRECATED void
   load(const char *filename);
 
   /**
@@ -867,7 +886,7 @@ private:
    * using serial routines
    */
   void
-  save_serial(const char *                                 filename,
+  save_serial(const std::string &                          filename,
               const std::pair<unsigned int, unsigned int> &chunk_size) const;
 
   /*
@@ -875,14 +894,14 @@ private:
    * using serial routines
    */
   void
-  load_serial(const char *filename);
+  load_serial(const std::string &filename);
 
   /*
    * Stores the distributed matrix in @p filename
    * using parallel routines
    */
   void
-  save_parallel(const char *                                 filename,
+  save_parallel(const std::string &                          filename,
                 const std::pair<unsigned int, unsigned int> &chunk_size) const;
 
   /*
@@ -890,7 +909,7 @@ private:
    * using parallel routines
    */
   void
-  load_parallel(const char *filename);
+  load_parallel(const std::string &filename);
 
   /**
    * Since ScaLAPACK operations notoriously change the meaning of the matrix
index 96275b41557781ed3fad02e32f9eed20ae7495a9..be71ea82a014834df794849a0fb23c7bc39bf57d 100644 (file)
@@ -2610,7 +2610,7 @@ namespace internal
 template <typename NumberType>
 void
 ScaLAPACKMatrix<NumberType>::save(
-  const char *                                 filename,
+  const std::string &                          filename,
   const std::pair<unsigned int, unsigned int> &chunk_size) const
 {
 #  ifndef DEAL_II_WITH_HDF5
@@ -2651,9 +2651,20 @@ ScaLAPACKMatrix<NumberType>::save(
 
 template <typename NumberType>
 void
-ScaLAPACKMatrix<NumberType>::save_serial(
+ScaLAPACKMatrix<NumberType>::save(
   const char *                                 filename,
   const std::pair<unsigned int, unsigned int> &chunk_size) const
+{
+  save(std::string(filename), chunk_size);
+}
+
+
+
+template <typename NumberType>
+void
+ScaLAPACKMatrix<NumberType>::save_serial(
+  const std::string &                          filename,
+  const std::pair<unsigned int, unsigned int> &chunk_size) const
 {
 #  ifndef DEAL_II_WITH_HDF5
   (void)filename;
@@ -2687,7 +2698,7 @@ ScaLAPACKMatrix<NumberType>::save_serial(
 
       // create a new file using default properties
       hid_t file_id =
-        H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
+        H5Fcreate(filename.c_str(), H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
 
       // modify dataset creation properties, i.e. enable chunking
       hsize_t chunk_dims[2];
@@ -2809,7 +2820,7 @@ ScaLAPACKMatrix<NumberType>::save_serial(
 template <typename NumberType>
 void
 ScaLAPACKMatrix<NumberType>::save_parallel(
-  const char *                                 filename,
+  const std::string &                          filename,
   const std::pair<unsigned int, unsigned int> &chunk_size) const
 {
 #  ifndef DEAL_II_WITH_HDF5
@@ -2865,8 +2876,9 @@ ScaLAPACKMatrix<NumberType>::save_parallel(
   AssertThrow(status >= 0, ExcIO());
 
   // create a new file collectively and release property list identifier
-  hid_t file_id = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, plist_id);
-  status        = H5Pclose(plist_id);
+  hid_t file_id =
+    H5Fcreate(filename.c_str(), H5F_ACC_TRUNC, H5P_DEFAULT, plist_id);
+  status = H5Pclose(plist_id);
   AssertThrow(status >= 0, ExcIO());
 
   // As ScaLAPACK, and therefore the class ScaLAPACKMatrix, uses column-major
@@ -2967,7 +2979,8 @@ ScaLAPACKMatrix<NumberType>::save_parallel(
   if (tmp.grid->this_mpi_process == 0)
     {
       // open file using default properties
-      hid_t file_id_reopen = H5Fopen(filename, H5F_ACC_RDWR, H5P_DEFAULT);
+      hid_t file_id_reopen =
+        H5Fopen(filename.c_str(), H5F_ACC_RDWR, H5P_DEFAULT);
 
       // create HDF5 enum type for LAPACKSupport::State and
       // LAPACKSupport::Property
@@ -3041,7 +3054,7 @@ ScaLAPACKMatrix<NumberType>::save_parallel(
 
 template <typename NumberType>
 void
-ScaLAPACKMatrix<NumberType>::load(const char *filename)
+ScaLAPACKMatrix<NumberType>::load(const std::string &filename)
 {
 #  ifndef DEAL_II_WITH_HDF5
   (void)filename;
@@ -3062,7 +3075,16 @@ ScaLAPACKMatrix<NumberType>::load(const char *filename)
 
 template <typename NumberType>
 void
-ScaLAPACKMatrix<NumberType>::load_serial(const char *filename)
+ScaLAPACKMatrix<NumberType>::load(const char *filename)
+{
+  load(std::string(filename));
+}
+
+
+
+template <typename NumberType>
+void
+ScaLAPACKMatrix<NumberType>::load_serial(const std::string &filename)
 {
 #  ifndef DEAL_II_WITH_HDF5
   (void)filename;
@@ -3093,7 +3115,7 @@ ScaLAPACKMatrix<NumberType>::load_serial(const char *filename)
       herr_t status;
 
       // open the file in read-only mode
-      hid_t file_id = H5Fopen(filename, H5F_ACC_RDONLY, H5P_DEFAULT);
+      hid_t file_id = H5Fopen(filename.c_str(), H5F_ACC_RDONLY, H5P_DEFAULT);
 
       // open the dataset in the file
       hid_t dataset_id = H5Dopen2(file_id, "/matrix", H5P_DEFAULT);
@@ -3240,7 +3262,7 @@ ScaLAPACKMatrix<NumberType>::load_serial(const char *filename)
 
 template <typename NumberType>
 void
-ScaLAPACKMatrix<NumberType>::load_parallel(const char *filename)
+ScaLAPACKMatrix<NumberType>::load_parallel(const std::string &filename)
 {
 #  ifndef DEAL_II_WITH_HDF5
   (void)filename;
@@ -3282,7 +3304,7 @@ ScaLAPACKMatrix<NumberType>::load_parallel(const char *filename)
 
   // open file collectively in read-only mode and release property list
   // identifier
-  hid_t file_id = H5Fopen(filename, H5F_ACC_RDONLY, plist_id);
+  hid_t file_id = H5Fopen(filename.c_str(), H5F_ACC_RDONLY, plist_id);
   status        = H5Pclose(plist_id);
   AssertThrow(status >= 0, ExcIO());
 
index 869bb28cc2eb4b21e4553df751b7150a738f7549..b1c5b4ee1dbdf0f3b820ff791da385b0811ac673 100644 (file)
@@ -60,8 +60,8 @@ test(const unsigned int size, const unsigned int block_size)
     size, size, grid, block_size, block_size);
 
   scalapack_matrix = full;
-  scalapack_matrix.save(filename.c_str());
-  scalapack_matrix_copy.load(filename.c_str());
+  scalapack_matrix.save(filename);
+  scalapack_matrix_copy.load(filename);
 
   FullMatrix<NumberType> copy(size);
   scalapack_matrix_copy.copy_to(copy);
index 4a6341317866e4d2d85781cac65f2deb5cdc0187..03d7aa5101e4cf2723185ae9ea59b55a5357c981 100644 (file)
@@ -72,11 +72,11 @@ test(const unsigned int size, const unsigned int block_size)
   matrix     = full;
   matrix_one = full;
 
-  matrix.save(filename_parallel.c_str());
-  matrix_one.save(filename_serial.c_str());
+  matrix.save(filename_parallel);
+  matrix_one.save(filename_serial);
 
-  matrix.load(filename_serial.c_str());
-  matrix_one.load(filename_parallel.c_str());
+  matrix.load(filename_serial);
+  matrix_one.load(filename_parallel);
 
   std::remove(filename_serial.c_str());
   std::remove(filename_parallel.c_str());
index 958e12f39e58e39ac0490e10c54806f471b51a1f..48e064e6b019dadd3ffae685d1dc8c798f560a71 100644 (file)
@@ -59,8 +59,8 @@ test(const std::pair<unsigned int, unsigned int> &size,
     size.first, size.second, grid, block_size, block_size);
 
   scalapack_matrix = full;
-  scalapack_matrix.save(filename.c_str(), chunk_size);
-  scalapack_matrix_copy.load(filename.c_str());
+  scalapack_matrix.save(filename, chunk_size);
+  scalapack_matrix_copy.load(filename);
 
   FullMatrix<NumberType> copy(size.first, size.second);
   scalapack_matrix_copy.copy_to(copy);
index 9ded2e2dae2683fc1a9ce7432bc72fc16f1a45d0..a8060a7de991944bcadfe07a74efab0c099e594a 100644 (file)
@@ -63,64 +63,64 @@ test()
     size, size, grid, block_size, block_size);
 
   scalapack_matrix.set_property(LAPACKSupport::Property::diagonal);
-  scalapack_matrix.save(filename.c_str());
-  scalapack_matrix_copy.load(filename.c_str());
+  scalapack_matrix.save(filename);
+  scalapack_matrix_copy.load(filename);
   std::remove(filename.c_str());
   AssertThrow(scalapack_matrix.get_property() ==
                 scalapack_matrix_copy.get_property(),
               ExcInternalError());
 
   scalapack_matrix.set_property(LAPACKSupport::Property::general);
-  scalapack_matrix.save(filename.c_str());
-  scalapack_matrix_copy.load(filename.c_str());
+  scalapack_matrix.save(filename);
+  scalapack_matrix_copy.load(filename);
   std::remove(filename.c_str());
   AssertThrow(scalapack_matrix.get_property() ==
                 scalapack_matrix_copy.get_property(),
               ExcInternalError());
 
   scalapack_matrix.set_property(LAPACKSupport::Property::hessenberg);
-  scalapack_matrix.save(filename.c_str());
-  scalapack_matrix_copy.load(filename.c_str());
+  scalapack_matrix.save(filename);
+  scalapack_matrix_copy.load(filename);
   std::remove(filename.c_str());
   AssertThrow(scalapack_matrix.get_property() ==
                 scalapack_matrix_copy.get_property(),
               ExcInternalError());
 
   scalapack_matrix.set_property(LAPACKSupport::Property::lower_triangular);
-  scalapack_matrix.save(filename.c_str());
-  scalapack_matrix_copy.load(filename.c_str());
+  scalapack_matrix.save(filename);
+  scalapack_matrix_copy.load(filename);
   std::remove(filename.c_str());
   AssertThrow(scalapack_matrix.get_property() ==
                 scalapack_matrix_copy.get_property(),
               ExcInternalError());
 
   scalapack_matrix.set_property(LAPACKSupport::Property::symmetric);
-  scalapack_matrix.save(filename.c_str());
-  scalapack_matrix_copy.load(filename.c_str());
+  scalapack_matrix.save(filename);
+  scalapack_matrix_copy.load(filename);
   std::remove(filename.c_str());
   AssertThrow(scalapack_matrix.get_property() ==
                 scalapack_matrix_copy.get_property(),
               ExcInternalError());
 
   scalapack_matrix.set_property(LAPACKSupport::Property::upper_triangular);
-  scalapack_matrix.save(filename.c_str());
-  scalapack_matrix_copy.load(filename.c_str());
+  scalapack_matrix.save(filename);
+  scalapack_matrix_copy.load(filename);
   std::remove(filename.c_str());
   AssertThrow(scalapack_matrix.get_property() ==
                 scalapack_matrix_copy.get_property(),
               ExcInternalError());
 
   // after construction the matrix state is LAPACKSupport::State::unusable
-  scalapack_matrix.save(filename.c_str());
-  scalapack_matrix_copy.load(filename.c_str());
+  scalapack_matrix.save(filename);
+  scalapack_matrix_copy.load(filename);
   std::remove(filename.c_str());
   AssertThrow(scalapack_matrix.get_state() == scalapack_matrix_copy.get_state(),
               ExcInternalError());
 
   // the assignment operator changes the state to LAPACKSupport::State::matrix
   scalapack_matrix = full;
-  scalapack_matrix.save(filename.c_str());
-  scalapack_matrix_copy.load(filename.c_str());
+  scalapack_matrix.save(filename);
+  scalapack_matrix_copy.load(filename);
   std::remove(filename.c_str());
   AssertThrow(scalapack_matrix.get_state() == scalapack_matrix_copy.get_state(),
               ExcInternalError());
@@ -128,8 +128,8 @@ test()
   // calling invert changes the state to LAPACKSupport::inverse_matrix
   scalapack_matrix.set_property(LAPACKSupport::Property::symmetric);
   scalapack_matrix.invert();
-  scalapack_matrix.save(filename.c_str());
-  scalapack_matrix_copy.load(filename.c_str());
+  scalapack_matrix.save(filename);
+  scalapack_matrix_copy.load(filename);
   std::remove(filename.c_str());
   AssertThrow(scalapack_matrix.get_state() == scalapack_matrix_copy.get_state(),
               ExcInternalError());
index 7d27c7efd329f327dc6ed50a80ac6b4c43aae3cc..79722256223dcd863d2991c4be9a0d7f334e09ec 100644 (file)
@@ -62,7 +62,7 @@ test(const unsigned int size, const unsigned int block_size)
     size, size, grid_1, block_size, block_size);
 
   scalapack_matrix_1 = full;
-  scalapack_matrix_1.save(filename.c_str());
+  scalapack_matrix_1.save(filename);
 
   ScaLAPACKMatrix<NumberType> scalapack_matrix(filename,
                                                grid,

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.