From: wolf Date: Thu, 14 Sep 2000 08:35:33 +0000 (+0000) Subject: Use [io]stream.write instead of operator<< or operator>> in X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c84ed7f158091a5388a02204daa1b20d747017b5;p=dealii-svn.git Use [io]stream.write instead of operator<< or operator>> in 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 --- diff --git a/deal.II/lac/include/lac/vector.templates.h b/deal.II/lac/include/lac/vector.templates.h index c303a580ba..9c7d890173 100644 --- a/deal.II/lac/include/lac/vector.templates.h +++ b/deal.II/lac/include/lac/vector.templates.h @@ -478,6 +478,7 @@ void Vector::equ (const Number a, const Vector& u, } + template void Vector::equ (const Number a, const Vector& u) { @@ -491,8 +492,10 @@ void Vector::equ (const Number a, const Vector& u) } + template -void Vector::ratio (const Vector &a, const Vector &b) { +void Vector::ratio (const Vector &a, const Vector &b) +{ Assert (dim!=0, ExcEmptyVector()); Assert (a.dim == b.dim, ExcDimensionsDontMatch (a.dim, b.dim)); @@ -508,6 +511,7 @@ void Vector::ratio (const Vector &a, const Vector &b) { }; + template Vector& Vector::operator = (const Number s) { @@ -517,6 +521,7 @@ Vector& Vector::operator = (const Number s) } + template Vector& Vector::operator = (const Vector& v) @@ -530,6 +535,7 @@ Vector::operator = (const Vector& v) } + template template Vector& @@ -544,6 +550,7 @@ Vector::operator = (const Vector& v) } + template void Vector::print (FILE* f, const char* format) const { @@ -555,6 +562,7 @@ void Vector::print (FILE* f, const char* format) const } + template void Vector::print (const char* format) const { @@ -566,6 +574,7 @@ void Vector::print (const char* format) const } + template void Vector::print (ostream &out, unsigned int precision, @@ -594,39 +603,65 @@ void Vector::print (ostream &out, }; + template -void Vector::block_write (ostream &out) const { +void Vector::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(&sz), + reinterpret_cast(&sz+1) + - reinterpret_cast(&sz)); + const char intro = '['; + out.write (&intro, 1); out.write (reinterpret_cast(begin()), reinterpret_cast(end()) - reinterpret_cast(begin())); - out << ']'; + + // out << ']'; + const char outro = ']'; + out.write (&outro, 1); AssertThrow (out, ExcIO()); }; + template -void Vector::block_read (istream &in) { +void Vector::block_read (istream &in) +{ AssertThrow (in, ExcIO()); unsigned int sz; - in >> sz; + // other version of + // in >> sz; + // reason as above + in.read (reinterpret_cast(&sz), + reinterpret_cast(&sz+1) + - reinterpret_cast(&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(begin()), reinterpret_cast(end()) - reinterpret_cast(begin())); - in >> c; + // in >> c; + in.read (&c, 1); AssertThrow (c==']', ExcIO()); AssertThrow (in, ExcIO()); }