]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Use [io]stream.write instead of operator<< or operator>> in
authorwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Thu, 14 Sep 2000 08:35:33 +0000 (08:35 +0000)
committerwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Thu, 14 Sep 2000 08:35:33 +0000 (08:35 +0000)
block_{read,write}, since in some cases the operators seem to get us
into problem when doing io in parallel (using gcc2.95).

git-svn-id: https://svn.dealii.org/trunk@3321 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/lac/include/lac/vector.templates.h

index c303a580ba8cd598702fd297a999668ee8b8b62d..9c7d8901732a1f48fd4cefad6e550b1dc6f51930 100644 (file)
@@ -478,6 +478,7 @@ void Vector<Number>::equ (const Number a, const Vector<Number>& u,
 }
 
 
+
 template <typename Number>
 void Vector<Number>::equ (const Number a, const Vector<Number>& u)
 {
@@ -491,8 +492,10 @@ void Vector<Number>::equ (const Number a, const Vector<Number>& u)
 }
 
 
+
 template <typename Number>
-void Vector<Number>::ratio (const Vector<Number> &a, const Vector<Number> &b) {
+void Vector<Number>::ratio (const Vector<Number> &a, const Vector<Number> &b)
+{
   Assert (dim!=0, ExcEmptyVector());
   Assert (a.dim == b.dim, ExcDimensionsDontMatch (a.dim, b.dim));
 
@@ -508,6 +511,7 @@ void Vector<Number>::ratio (const Vector<Number> &a, const Vector<Number> &b) {
 };
 
 
+
 template <typename Number>
 Vector<Number>& Vector<Number>::operator = (const Number s)
 {
@@ -517,6 +521,7 @@ Vector<Number>& Vector<Number>::operator = (const Number s)
 }
 
 
+
 template <typename Number>
 Vector<Number>&
 Vector<Number>::operator = (const Vector<Number>& v)
@@ -530,6 +535,7 @@ Vector<Number>::operator = (const Vector<Number>& v)
 }
 
 
+
 template <typename Number>
 template<typename Number2>
 Vector<Number>&
@@ -544,6 +550,7 @@ Vector<Number>::operator = (const Vector<Number2>& v)
 }
 
 
+
 template <typename Number>
 void Vector<Number>::print (FILE* f, const char* format) const
 {
@@ -555,6 +562,7 @@ void Vector<Number>::print (FILE* f, const char* format) const
 }
 
 
+
 template <typename Number>
 void Vector<Number>::print (const char* format) const
 {
@@ -566,6 +574,7 @@ void Vector<Number>::print (const char* format) const
 }
 
 
+
 template <typename Number>
 void Vector<Number>::print (ostream &out,
                            unsigned int precision,
@@ -594,39 +603,65 @@ void Vector<Number>::print (ostream &out,
 };
 
 
+
 template <typename Number>
-void Vector<Number>::block_write (ostream &out) const {
+void Vector<Number>::block_write (ostream &out) const
+{
   AssertThrow (out, ExcIO());
-    
-  out << size() << endl << '[';
+
+                                  // other version of the following
+                                  //  out << size() << endl << '[';
+                                  // reason: operator<< seems to use
+                                  // some resources that lead to
+                                  // problems in a multithreaded
+                                  // environment
+  const unsigned int sz = size();
+  out.write (reinterpret_cast<const char*>(&sz),
+            reinterpret_cast<const char*>(&sz+1)
+            - reinterpret_cast<const char*>(&sz));
+  const char intro = '[';
+  out.write (&intro, 1);
   out.write (reinterpret_cast<const char*>(begin()),
             reinterpret_cast<const char*>(end())
             - reinterpret_cast<const char*>(begin()));
-  out << ']';
+  
+                                  // out << ']';
+  const char outro = ']';
+  out.write (&outro, 1);
   
   AssertThrow (out, ExcIO());
 };
 
 
+
 template <typename Number>
-void Vector<Number>::block_read (istream &in) {
+void Vector<Number>::block_read (istream &in)
+{
   AssertThrow (in, ExcIO());
 
   unsigned int sz;
-  in >> sz;
+                                  // other version of
+                                  //  in >> sz;
+                                  // reason as above
+  in.read (reinterpret_cast<void*>(&sz),
+          reinterpret_cast<const char*>(&sz+1)
+          - reinterpret_cast<const char*>(&sz));
+  
                                   // fast initialization, since the
                                   // data elements are overwritten anyway
   reinit (sz, true);     
 
   char c;
-  in >> c;
+                                  //  in >> c;
+  in.read (&c, 1);
   AssertThrow (c=='[', ExcIO());
   
   in.read (reinterpret_cast<void*>(begin()),
           reinterpret_cast<const char*>(end())
           - reinterpret_cast<const char*>(begin()));
   
-  in >> c;
+                                  //  in >> c;
+  in.read (&c, 1);
   AssertThrow (c==']', ExcIO());
   AssertThrow (in, ExcIO());
 }

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.