queso-0.57.0
TeuchosVector.C
Go to the documentation of this file.
1 //-----------------------------------------------------------------------bl-
2 //--------------------------------------------------------------------------
3 //
4 // QUESO - a library to support the Quantification of Uncertainty
5 // for Estimation, Simulation and Optimization
6 //
7 // Copyright (C) 2008-2017 The PECOS Development Team
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the Version 2.1 GNU Lesser General
11 // Public License as published by the Free Software Foundation.
12 //
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Lesser General Public License for more details.
17 //
18 // You should have received a copy of the GNU Lesser General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc. 51 Franklin Street, Fifth Floor,
21 // Boston, MA 02110-1301 USA
22 //
23 //-----------------------------------------------------------------------el-
24 
25 #include <queso/Defines.h>
26 
27 #ifdef QUESO_HAS_TRILINOS
28 
29 #include <queso/TeuchosVector.h>
30 #include <queso/RngBase.h>
31 
32 namespace QUESO {
33 
34 using std:: cout;
35 using std:: endl;
36 
37 // constructor with dimension -----------------------
39  :
40  Vector(env,map)
41 {
42  m_vec.size(map.NumGlobalElements());
43 
44  queso_require_equal_to_msg(m_vec.length(), map.NumMyElements(), "incompatible local vec size");
45 
46  queso_require_equal_to_msg(m_vec.length(), map.NumGlobalElements(), "incompatible global vec size");
47 
48  queso_require_equal_to_msg(m_vec.length(), m_map.NumMyElements(), "incompatible own vec size");
49 
50  //std::cout << "In TeuchosVector::constructor(env,map)"
51  // << "\n m_vec.length() = " << m_vec.length()
52  // << "\n map.NumGlobalElements() = " << map.NumGlobalElements()
53  // << "\n map.NumMyElements() = " << map.NumMyElements()
54  // << std::endl;
55 }
56 
57 // ---------------------------------------------------
58 TeuchosVector::TeuchosVector(const BaseEnvironment& env, const Map& map, double value)
59  :
60  Vector(env,map)
61 {
62  m_vec.size(map.NumGlobalElements());
63  m_vec = value;
64 
65  queso_require_equal_to_msg(m_vec.length(), map.NumMyElements(), "incompatible local vec size");
66 
67  queso_require_equal_to_msg(m_vec.length(), map.NumGlobalElements(), "incompatible global vec size");
68 
69  queso_require_equal_to_msg(m_vec.length(), m_map.NumMyElements(), "incompatible own vec size");
70 }
71 
72 // ---------------------------------------------------
73 TeuchosVector::TeuchosVector(const BaseEnvironment& env, double d1, double d2, const Map& map)
74  :
75  Vector(env,map)
76  {
77  m_vec.size(map.NumGlobalElements());
78 
79  queso_require_equal_to_msg(m_vec.length(), map.NumMyElements(), "incompatible local vec size");
80 
81  queso_require_equal_to_msg(m_vec.length(), map.NumGlobalElements(), "incompatible global vec size");
82 
83  for (int i = 0; i < m_vec.length(); ++i) {
84  double alpha = (double) i / ((double) m_vec.length() - 1.);
85  (*this)[i] = (1.-alpha)*d1 + alpha*d2;
86  }
87 
88  queso_require_equal_to_msg(m_vec.length(), m_map.NumMyElements(), "incompatible own vec size");
89 }
90 
91 // ---------------------------------------------------
92 TeuchosVector::TeuchosVector(const TeuchosVector& v, double d1, double d2)
93  :
94  Vector(v.env(),v.map())
95 {
96  m_vec.size(v.sizeLocal());
97 
98  queso_require_equal_to_msg(m_vec.length(), v.map().NumMyElements(), "incompatible local vec size");
99 
100  queso_require_equal_to_msg(m_vec.length(), v.map().NumGlobalElements(), "incompatible global vec size");
101 
102  for ( int i = 0; i < m_vec.length(); ++i) {
103  double alpha = (double) i / ((double) m_vec.length() - 1.);
104  (*this)[i] = (1.-alpha)*d1 + alpha*d2;
105  }
106 
107  queso_require_equal_to_msg(m_vec.length(), m_map.NumMyElements(), "incompatible own vec size");
108 }
109 
110 // ---------------------------------------------------
112  :
113  Vector(v.env(),v.map())
114  {
115  m_vec.size(v.sizeLocal());
116 
117  queso_require_equal_to_msg(m_vec.length(), v.map().NumMyElements(), "incompatible local vec size");
118 
119  queso_require_equal_to_msg(m_vec.length(), v.map().NumGlobalElements(), "incompatible global vec size");
120  this->copy(v);
121 
122  queso_require_equal_to_msg(m_vec.length(), m_map.NumMyElements(), "incompatible own vec size");
123 }
124 
125 
126 // destructor --------------------------------------
128 {
129 };
130 
131 // Set methods ------------------------------------
132 //-------------------------------------------------
133 // assigns values a to all entrances in the vector
135 {
136  m_vec.putScalar(a);
137  return *this;
138 }
139 
140 //-------------------------------------------------
142 {
143  unsigned int size1 = m_vec.length();
144  unsigned int size2 = rhs.sizeLocal();
145 
146  queso_require_equal_to_msg(size1, size2, "the vectors do NOT have the same size.\n");
147 
148  if (size1==size2){
149  for (unsigned int i=0;i<size1;i++){
150  m_vec[i]=rhs[i];
151  }
152  }
153 
154  return *this;
155 }
156 
157 //-------------------------------------------------
159 {
160  m_vec.scale(a); //Scale this vector by a; *this = a*this.
161  return *this;
162 }
163 
164  //-------------------------------------------------
166 {
167  (*this) *= (1.0/a);
168  return *this;
169 }
170 
171 //-------------------------------------------------
173 {
174  unsigned int size1 = this->sizeLocal();
175  unsigned int size2 = rhs.sizeLocal();
176  queso_require_equal_to_msg(size1, size2, "the vectors do NOT have the same size.\n");
177  if (size1==size2){
178  for (unsigned int i = 0; i < size1; ++i) {
179  (*this)[i] *= rhs[i];
180  }
181  }
182  return *this;
183 }
184 
185 //-------------------------------------------------
187 {
188  unsigned int size1 = this->sizeLocal();
189  unsigned int size2 = rhs.sizeLocal();
190 
191  queso_require_equal_to_msg(size1, size2, "the vectors do NOT have the same size.\n");
192  if (size1==size2){
193  for (unsigned int i = 0; i < size1; ++i) {
194  (*this)[i] /= rhs[i];
195  }
196  }
197  return *this;
198 }
199 
200 //-------------------------------------------------
202 {
203  unsigned int size1 = this->sizeLocal();
204  unsigned int size2 = rhs.sizeLocal();
205 
206  queso_require_equal_to_msg(size1, size2, "the vectors do NOT have the same size.\n");
207 
208  if (size1==size2){
209  for (unsigned int i = 0; i < size1; ++i) {
210  (*this)[i] += rhs[i];
211  }
212  }
213  return *this;
214 }
215 
216 //-------------------------------------------------
218 {
219  unsigned int size1 = this->sizeLocal();
220  unsigned int size2 = rhs.sizeLocal();
221 
222  queso_require_equal_to_msg(size1, size2, "the vectors do NOT have the same size.\n");
223 
224  if (size1==size2){
225  for (unsigned int i = 0; i < size1; ++i) {
226  (*this)[i] -= rhs[i];
227  }
228  }
229 
230  return *this;
231 }
232 
233 
234 // Accessor methods --------------------------------
235 //-------------------------------------------------
236 double& TeuchosVector::operator[](unsigned int i)
237 {
238  return m_vec[i];
239 }
240 
241 //-------------------------------------------------
242 const double& TeuchosVector::operator[](unsigned int i) const
243 {
244  return m_vec[i];
245 }
246 
247 // Attribute methods ------------------------------
248 //-------------------------------------------------
249 unsigned int TeuchosVector::sizeLocal() const
250 {
251  queso_require_equal_to_msg(m_vec.length(), (int) m_map.NumMyElements(), "incompatible vec size");
252 
253  return m_vec.length();
254 }
255 
256 //-------------------------------------------------
257 unsigned int TeuchosVector::sizeGlobal() const
258 {
259  queso_require_equal_to_msg(m_vec.length(), (int) m_map.NumGlobalElements(), "incompatible vec size");
260  return m_vec.length();
261 }
262 
263 //-------------------------------------------------
264 // TODO: needs to be checked. It may not be used at all. Kemelli 4/30/13.
265 double*
267 {
268  return m_vec.values();
269 };
270 
271 // Getting Max and Min values -------------------
272 // Max ------------------------------------------
273 double TeuchosVector::getMaxValue( ) const //dummy
274 {
275  const unsigned int size = this->sizeLocal();
276  std::vector<double> aux;
277 
278  for (unsigned int i=0; i<size; i++ ) {
279  aux.push_back((*this)[i]) ;
280  }
281 
282  return *max_element (aux.begin(),aux.end());
283 }
284 
285 // Min ------------------------------------------
286 double TeuchosVector::getMinValue( ) const //dummy
287 {
288  const unsigned int size = this->sizeLocal();
289  std::vector<double> aux;
290 
291  for (unsigned int i=0; i<size; i++ ) {
292  aux.push_back((*this)[i]) ;
293  }
294 
295  return *min_element (aux.begin(),aux.end());
296 
297 }
298 
299 // Max index -----------------------------------
301 {
302  const unsigned int size = this->sizeLocal();
303  std::vector<double> vect;
304 
305  for (unsigned int i=0; i<size; i++ ) {
306  vect.push_back((*this)[i]) ;
307  }
308  std::vector<double>::iterator iter_max = max_element(vect.begin(), vect.end());
309  return distance(vect.begin(), iter_max);
310 }
311 
312 // Min index -----------------------------------
314 {
315  const unsigned int size = this->sizeLocal();
316  std::vector<double> vect;
317 
318  for (unsigned int i=0; i<size; i++ ) {
319  vect.push_back((*this)[i]) ;
320  }
321  std::vector<double>::iterator iter_min = min_element(vect.begin(), vect.end());
322  return distance(vect.begin(), iter_min);
323 }
324 
325 // Max and index -------------------------------
326 void TeuchosVector::getMaxValueAndIndex( double& max_value, int& max_value_index ) //dummy
327 {
328  const unsigned int size = this->sizeLocal();
329  std::vector<double> vect;
330 
331  for (unsigned int i=0; i<size; i++ ) {
332  vect.push_back((*this)[i]) ;
333  }
334  std::vector<double>::iterator iter_max = max_element(vect.begin(), vect.end());
335 
336  max_value = *iter_max;
337  max_value_index = distance(vect.begin(), iter_max);
338 
339  return;
340 }
341 
342 // Min and index -------------------------------
343 void TeuchosVector::getMinValueAndIndex( double& min_value, int& min_value_index ) //dummy
344 {
345  const unsigned int size = this->sizeLocal();
346  std::vector<double> vect;
347 
348  for (unsigned int i=0; i<size; i++ ) {
349  vect.push_back((*this)[i]) ;
350  }
351  std::vector<double>::iterator iter_min = min_element(vect.begin(), vect.end());
352 
353  min_value = *iter_min;
354  min_value_index = distance(vect.begin(), iter_min);
355 
356  return;
357 }
358 
359 // Norm methods ------------------------------------
360 // -------------------------------------------------
362 {
363  return (m_vec).dot(m_vec );
364 }
365 
366 //-------------------------------------------------
367 double TeuchosVector::norm2() const
368 {
369  return std::sqrt(this->norm2Sq());
370 }
371 
372 //-------------------------------------------------
373 double TeuchosVector::norm1() const
374 {
375  double result = 0.;
376 
377  unsigned int size = this->sizeLocal();
378  for (unsigned int i = 0; i < size; ++i) {
379  result += fabs((*this)[i]);
380  }
381 
382  return result;
383 }
384 
385 //-------------------------------------------------
387 {
388  double result = 0.;
389 
390  unsigned int size = this->sizeLocal();
391  double aux = 0.;
392  for (unsigned int i = 0; i < size; ++i) {
393  aux = fabs((*this)[i]);
394  if (aux > result) result = aux;
395  }
396 
397  return result;
398 }
399 
400 // Comparison methods -----------------------------
401 //-------------------------------------------------
402 bool
404 {
405  queso_require_equal_to_msg(this->sizeLocal(), rhs.sizeLocal(), "vectors have different sizes");
406 
407  bool result = false;
408  unsigned int i = 0;
409  unsigned int size = this->sizeLocal();
410  while ((i < size) && (result == false)) {
411  result = ( (*this)[i] < rhs[i] );
412  i++;
413  };
414 
415  return result;
416 }
417 
418 //-------------------------------------------------
419 bool
421 {
422  queso_require_equal_to_msg(this->sizeLocal(), rhs.sizeLocal(), "vectors have different sizes");
423 
424  bool result = false;
425  unsigned int i = 0;
426  unsigned int size = this->sizeLocal();
427  while ((i < size) && (result == false)) {
428  result = ( (*this)[i] > rhs[i] );
429  i++;
430  };
431 
432  return result;
433 }
434 
435 //-------------------------------------------------
436 bool
438 {
439  queso_require_equal_to_msg(this->sizeLocal(), rhs.sizeLocal(), "vectors have different sizes");
440 
441  bool result = false;
442  unsigned int i = 0;
443  unsigned int size = this->sizeLocal();
444  while ((i < size) && (result == false)) {
445  result = ( (*this)[i] <= rhs[i] ); // prudencio 2012-02-06
446  i++;
447  };
448 
449  return result;
450 }
451 
452 //-------------------------------------------------
453 bool
455 {
456  queso_require_equal_to_msg(this->sizeLocal(), rhs.sizeLocal(), "vectors have different sizes");
457 
458  bool result = false;
459  unsigned int i = 0;
460  unsigned int size = this->sizeLocal();
461  while ((i < size) && (result == false)) {
462  result = ( (*this)[i] >= rhs[i] ); // prudencio 2012-02-06
463  i++;
464  };
465 
466  return result;
467 }
468 
469 
470 // Get/Set methods -----------------------------------
471 //----------------------------------------------------
472 void TeuchosVector::cwSet(double value)
473 {
474  (*this)=value;
475 
476  return;
477 }
478 
479 //----------------------------------------------------
480 void TeuchosVector::cwSet(unsigned int initialPos, const TeuchosVector& vec)
481 {
482  queso_require_less_msg(initialPos, this->sizeLocal(), "invalid initialPos");
483 
484  queso_require_less_equal_msg((initialPos +vec.sizeLocal()), this->sizeLocal(), "invalid vec.sizeLocal()");
485 
486  for (unsigned int i = 0; i < vec.sizeLocal(); ++i) {
487  (*this)[initialPos+i] = vec[i];
488  }
489 
490  return;
491 }
492 
493 
494 //----------------------------------------------------
495 /* extracts elements from vector (*this) starting at position initialPos and save in vec */
496 void TeuchosVector::cwExtract(unsigned int initialPos, TeuchosVector& vec) const
497 {
498  queso_require_less_msg(initialPos, this->sizeLocal(), "invalid initialPos");
499 
500  queso_require_less_equal_msg((initialPos +vec.sizeLocal()), this->sizeLocal(), "invalid vec.sizeLocal()");
501 
502  for (unsigned int i = 0; i < vec.sizeLocal(); ++i) {
503  vec[i] = (*this)[initialPos+i];
504  }
505 
506  return;
507 }
508 
509 //----------------------------------------------------
511 {
512  unsigned int size = this->sizeLocal();
513  for (unsigned int i = 0; i < size; ++i) {
514  (*this)[i] = 1./(*this)[i];
515  }
516 
517  return;
518 }
519 
520 //----------------------------------------------------
522 {
523  unsigned int size = this->sizeLocal();
524  for (unsigned int i = 0; i < size; ++i) {
525  (*this)[i] = sqrt((*this)[i]);
526  }
527 
528  return;
529 }
530 
531 //----------------------------------------------------
532 void
534 {
535  queso_require_equal_to_msg(this->sizeLocal(), v1.sizeLocal() + v2.sizeLocal(), "incompatible vector sizes");
536 
537 // if ( this->sizeLocal() != v1.sizeLocal() + v2.sizeLocal() ) {
538 // std::cout << "ERROR in TeuchosVector:: cwSetConcatenated ---> the vectors' sizes are not compatible.\n";
539 // cout << " in TeuchosVector:: cwSetConcatenated ---> resizing resulting vector... new size = "
540 // << v1.sizeLocal()+v1.sizeLocal() <<endl;
541 //
542 // m_vec.resize(v1.sizeLocal()+v1.sizeLocal());
543 // }
544 
545  for (unsigned int i = 0; i < v1.sizeLocal(); ++i) {
546  (*this)[i] = v1[i];
547  }
548 
549  for (unsigned int i = 0; i < v2.sizeLocal(); ++i) {
550  (*this)[v1.sizeLocal()+i] = v2[i];
551  }
552 
553  return;
554 }
555 
556 // -------------------------------------------------
557 //updated on 3/18, to use the RngBase+Boost
558 void TeuchosVector::cwSetGaussian(double mean, double stdDev)
559 {
560  for (unsigned int i = 0; i < this->sizeLocal(); ++i) {
561  (*this)[i] = mean + m_env.rngObject()->gaussianSample(stdDev);
562  }
563  return;
564 };
565 
566 // -------------------------------------------------
567 //updated on 3/18, to use the RngBase+Boost
568 void TeuchosVector::cwSetGaussian(const TeuchosVector& meanVec, const TeuchosVector& stdDevVec)
569 {
570  for (unsigned int i = 0; i < this->sizeLocal(); ++i) {
571  (*this)[i] = meanVec[i] + m_env.rngObject()->gaussianSample(stdDevVec[i]);
572  }
573  return;
574 };
575 
576 
577 //----------------------------------------------------
578 //implemented/checked 2/26/13
579 //updated on 3/18, to use the RngBase+Boost
581 {
582  for (unsigned int i = 0; i < this->sizeLocal(); ++i) {
583  (*this)[i] = aVec[i] + (bVec[i]-aVec[i])*m_env.rngObject()->uniformSample();
584  }
585  return;
586 }
587 
588 
589 // -------------------------------------------------
590 //updated on 3/18, to use the RngBase+Boost
591 void TeuchosVector::cwSetBeta(const TeuchosVector& alpha, const TeuchosVector& beta)
592 {
593  queso_require_equal_to_msg(this->sizeLocal(), alpha.sizeLocal(), "incompatible alpha size");
594 
595  queso_require_equal_to_msg(this->sizeLocal(), beta.sizeLocal(), "incompatible beta size");
596 
597  for (unsigned int i = 0; i < this->sizeLocal(); ++i)
598  {
599  (*this)[i] = m_env.rngObject()->betaSample(alpha[i],beta[i]);
600 
601  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 99))
602  {
603  *m_env.subDisplayFile() << "In TeuchosVector::cwSetBeta()"
604  << ": fullRank " << m_env.fullRank()
605  << ", i = " << i
606  << ", alpha[i] = " << alpha[i]
607  << ", beta[i] = " << beta[i]
608  << ", sample = " << (*this)[i]
609  << std::endl;
610  }
611  }
612  return;
613 };
614 
615 // -------------------------------------------------
616 //updated on 3/18, to use the RngBase+Boost
618 {
619  queso_require_equal_to_msg(this->sizeLocal(), aVec.sizeLocal(), "incompatible a size");
620 
621  queso_require_equal_to_msg(this->sizeLocal(), bVec.sizeLocal(), "incompatible b size");
622 
623  for (unsigned int i = 0; i < this->sizeLocal(); ++i) {
624  (*this)[i] = m_env.rngObject()->gammaSample(aVec[i],bVec[i]);
625  }
626  return;
627 }
628 
629 // -------------------------------------------------
630 //updated on 3/18, to use the RngBase+Boost
631 // Using Gamma Distribution to calculate InverseGamma.
632 // Note the divisions: 1.0/b and the 1.0/generator; they are crucial
634 {
635  queso_require_equal_to_msg(this->sizeLocal(), alpha.sizeLocal(), "incompatible alpha size");
636 
637  queso_require_equal_to_msg(this->sizeLocal(), beta.sizeLocal(), "incompatible beta size");
638 
639  for (unsigned int i = 0; i < this->sizeLocal(); ++i) {
640  (*this)[i] = 1./m_env.rngObject()->gammaSample(alpha[i],1./beta[i]);
641  }
642  return;
643 }
644 
645 
646 // Miscellaneous methods -------------------------
647 // absolute values -------------------------------
648 // tested 1/8/13
651 {
652  TeuchosVector abs_of_this_vec( *this );
653 
654  unsigned int size = abs_of_this_vec.sizeLocal();
655 
656  for( unsigned int i = 0; i < size; ++i )
657  {
658  abs_of_this_vec[i] = std::fabs( (*this)[i] );
659  }
660 
661  return abs_of_this_vec;
662 
663 }
664 
665 // -------------------------------------------------
666 void
667 TeuchosVector::copy_to_std_vector(std::vector<double>& vec)
668 {
669  unsigned int size = this->sizeLocal();
670  vec.resize(size);
671 
672  for (unsigned int i = 0; i < size; ++i)
673  vec[i] = m_vec[i];
674 
675  return;
676 }
677 
678 // -------------------------------------------------
679 void
680 TeuchosVector::copy_from_std_vector(const std::vector<double> vec)
681 {
682  unsigned int size1 = vec.size(), size2= this->sizeLocal();
683 
684  queso_require_equal_to_msg(size1, size2, "vectors have different sizes");
685 
686  for (unsigned int i = 0; i < size1; ++i)
687  m_vec[i] = vec[i];
688 
689  return;
690 }
691 
692 // -------------------------------------------------
694 {
695  std::vector<double> vec;
696 
697  (*this).copy_to_std_vector(vec);
698 
699  // using default comparison (operator <):
700  std::sort (vec.begin(), vec.end());
701 
702  (*this).copy_from_std_vector(vec);
703 };
704 
705 // -------------------------------------------------
707 {
708  double result = 0.;
709  unsigned int size = this->sizeLocal();
710  for (unsigned int i = 0; i < size; ++i) {
711  result += (*this)[i];
712  }
713 
714  return result;
715 }
716 
717 // -------------------------------------------------
718 // added 2/28/13
719 void
720 TeuchosVector::mpiBcast(int srcRank, const MpiComm& bcastComm)
721 {
722  // Filter out those nodes that should not participate
723  if (bcastComm.MyPID() < 0) return;
724 
725  // Check 'srcRank'
726  queso_require_msg(!((srcRank < 0) || (srcRank >= bcastComm.NumProc())), "invalud srcRank");
727 
728  // Check number of participant nodes
729  double localNumNodes = 1.;
730  double totalNumNodes = 0.;
731  bcastComm.Allreduce<double>(&localNumNodes, &totalNumNodes, (int) 1, RawValue_MPI_SUM,
732  "TeuchosVector::mpiBcast()",
733  "failed MPI.Allreduce() for numNodes");
734  queso_require_equal_to_msg(((int) totalNumNodes), bcastComm.NumProc(), "inconsistent numNodes");
735 
736  // Check that all participant nodes have the same vector size
737  double localVectorSize = this->sizeLocal();
738  double sumOfVectorSizes = 0.;
739  bcastComm.Allreduce<double>(&localVectorSize, &sumOfVectorSizes, (int) 1, RawValue_MPI_SUM,
740  "TeuchosVector::mpiBcast()",
741  "failed MPI.Allreduce() for vectorSize");
742 
743  if ( ((unsigned int) sumOfVectorSizes) != ((unsigned int)(totalNumNodes*localVectorSize)) ) {
744  std::cerr << "rank " << bcastComm.MyPID()
745  << ": sumOfVectorSizes = " << sumOfVectorSizes
746  << ", totalNumNodes = " << totalNumNodes
747  << ", localVectorSize = " << localVectorSize
748  << std::endl;
749  }
750  bcastComm.Barrier();
751  queso_require_equal_to_msg(((unsigned int) sumOfVectorSizes), ((unsigned int)(totalNumNodes*localVectorSize)), "inconsistent vectorSize");
752 
753  // Ok, bcast data
754  std::vector<double> dataBuffer((unsigned int) localVectorSize, 0.);
755  if (bcastComm.MyPID() == srcRank) {
756  for (unsigned int i = 0; i < dataBuffer.size(); ++i) {
757  dataBuffer[i] = (*this)[i];
758  }
759  }
760 
761  bcastComm.Bcast((void *) &dataBuffer[0], (int) localVectorSize, RawValue_MPI_DOUBLE, srcRank,
762  "TeuchosVector::mpiBcast()",
763  "failed MPI.Bcast()");
764 
765  if (bcastComm.MyPID() != srcRank) {
766  for (unsigned int i = 0; i < dataBuffer.size(); ++i) {
767  (*this)[i] = dataBuffer[i];
768  }
769  }
770 
771  return;
772 }
773 
774 // -------------------------------------------------
775 // added 2/28/13
776 void
777 TeuchosVector::mpiAllReduce(RawType_MPI_Op mpiOperation, const MpiComm& opComm, TeuchosVector& resultVec) const
778 {
779  // Filter out those nodes that should not participate
780  if (opComm.MyPID() < 0) return;
781 
782  unsigned int size = this->sizeLocal();
783  queso_require_equal_to_msg(size, resultVec.sizeLocal(), "different vector sizes");
784 
785  for (unsigned int i = 0; i < size; ++i) {
786  double srcValue = (*this)[i];
787  double resultValue = 0.;
788  opComm.Allreduce<double>(&srcValue, &resultValue, (int) 1, mpiOperation,
789  "TeuchosVector::mpiAllReduce()",
790  "failed MPI.Allreduce()");
791  resultVec[i] = resultValue;
792  }
793 
794  return;
795 }
796 
797 // -------------------------------------------------
798 // added 2/28/13
799 void
800 TeuchosVector::mpiAllQuantile(double probability, const MpiComm& opComm, TeuchosVector& resultVec) const
801 {
802  // Filter out those nodes that should not participate
803  if (opComm.MyPID() < 0) return;
804 
805  queso_require_msg(!((probability < 0.) || (1. < probability)), "invalid input");
806 
807  unsigned int size = this->sizeLocal();
808  queso_require_equal_to_msg(size, resultVec.sizeLocal(), "different vector sizes");
809 
810  for (unsigned int i = 0; i < size; ++i) {
811  double auxDouble = (int) (*this)[i];
812  std::vector<double> vecOfDoubles(opComm.NumProc(),0.);
813  opComm.Gather<double>(&auxDouble, 1, &vecOfDoubles[0], (int) 1, 0,
814  "TeuchosVector::mpiAllQuantile()",
815  "failed MPI.Gather()");
816 
817  std::sort(vecOfDoubles.begin(), vecOfDoubles.end());
818 
819  double result = vecOfDoubles[(unsigned int)( probability*((double)(vecOfDoubles.size()-1)) )];
820 
821  opComm.Bcast((void *) &result, (int) 1, RawValue_MPI_DOUBLE, 0,
822  "TeuchosVector::mpiAllQuantile()",
823  "failed MPI.Bcast()");
824 
825  resultVec[i] = result;
826  }
827 
828  return;
829 }
830 
831 // -------------------------------------------------
832 // added/tested 2/28/13
833 void
835  const TeuchosVector& x1Vec,
836  const TeuchosVector& y1Vec,
837  const TeuchosVector& x2Vec)
838 {
839  queso_require_greater_msg(x1Vec.sizeLocal(), 1, "invalid 'x1' size");
840 
841  queso_require_equal_to_msg(x1Vec.sizeLocal(), y1Vec.sizeLocal(), "invalid 'x1' and 'y1' sizes");
842 
843  queso_require_equal_to_msg(x2Vec.sizeLocal(), this->sizeLocal(), "invalid 'x2' and 'this' sizes");
844 
845  for (unsigned int i = 1; i < x1Vec.sizeLocal(); ++i) { // Yes, '1'
846  queso_require_greater_msg(x1Vec[i], x1Vec[i-1], "invalid 'x1' values");
847  }
848 
849  for (unsigned int id2 = 0; id2 < x2Vec.sizeLocal(); ++id2) {
850  double x2 = x2Vec[id2];
851  unsigned int id1 = 0;
852  bool found1 = false;
853  for (id1 = 0; id1 < x1Vec.sizeLocal(); ++id1) {
854  if (x2 <= x1Vec[id1]) {
855  found1 = true;
856  break;
857  }
858  }
859  bool makeLinearModel = false;
860  double xa = 0.;
861  double xb = 0.;
862  double ya = 0.;
863  double yb = 0.;
864  if (x2 == x1Vec[id1]) {
865  (*this)[id2] = y1Vec[id1];
866  }
867  else if (x2 < x1Vec[0]) {
868  // Extrapolation case
869  makeLinearModel = true;
870  xa = x1Vec[0];
871  xb = x1Vec[1];
872  ya = y1Vec[0];
873  yb = y1Vec[1];
874  }
875  else if (found1 == true) {
876  // Interpolation case
877  makeLinearModel = true;
878  xa = x1Vec[id1-1];
879  xb = x1Vec[id1];
880  ya = y1Vec[id1-1];
881  yb = y1Vec[id1];
882  }
883  else {
884  // Extrapolation case
885  makeLinearModel = true;
886  xa = x1Vec[x1Vec.sizeLocal()-2];
887  xb = x1Vec[x1Vec.sizeLocal()-1];
888  ya = y1Vec[x1Vec.sizeLocal()-2];
889  yb = y1Vec[x1Vec.sizeLocal()-1];
890  }
891 
892  if (makeLinearModel) {
893  double rate = (yb-ya)/(xb-xa);
894  (*this)[id2] = ya + (x2-xa)*rate;
895  }
896  }
897  return;
898 }
899 
900 // -------------------------------------------------
901 // added 2/28/13
902 void
904  unsigned int firstPositionToStoreDiff,
905  double valueForRemainderPosition,
906  TeuchosVector& outputVec) const
907 {
908  unsigned int size = this->sizeLocal();
909 
910  queso_require_less_equal_msg(firstPositionToStoreDiff, 1, "invalid firstPositionToStoreDiff");
911 
912  queso_require_equal_to_msg(size, outputVec.sizeLocal(), "invalid size of outputVecs");
913 
914  for (unsigned int i = 0; i < (size-1); ++i) {
915  outputVec[firstPositionToStoreDiff+i] = (*this)[i+1]-(*this)[i];
916  }
917  if (firstPositionToStoreDiff == 0) {
918  outputVec[size-1] = valueForRemainderPosition;
919  }
920  else {
921  outputVec[0] = valueForRemainderPosition;
922  }
923 
924  return;
925 }
926 
927 // I/O methods -------------------------------------
928 // -------------------------------------------------
929 void
930 TeuchosVector::print(std::ostream& os) const
931 {
932  unsigned int size = this->sizeLocal();
933 
934  std::ostream::fmtflags curr_fmt = os.flags();
935 
936  if (m_printScientific) {
937  unsigned int savedPrecision = os.precision();
938  os.precision(16);
939 
940  if (m_printHorizontally) {
941  for (unsigned int i = 0; i < size; ++i) {
942  os << std::scientific << (*this)[i]
943  << " ";
944  }
945  }
946  else {
947  for (unsigned int i = 0; i < size; ++i) {
948  os << std::scientific << (*this)[i]
949  << std::endl;
950  }
951  }
952 
953  os.precision(savedPrecision);
954  }
955  else {
956  if (m_printHorizontally) {
957  for (unsigned int i = 0; i < size; ++i) {
958  os << std::dec << (*this)[i]
959  << " ";
960  }
961  }
962  else {
963  for (unsigned int i = 0; i < size; ++i) {
964  os << std::dec << (*this)[i]
965  << std::endl;
966  }
967  }
968  }
969 
970  os.flags(curr_fmt);
971  return;
972 }
973 
974 // -------------------------------------------------
975 void
977  const std::string& fileName,
978  const std::string& fileType,
979  const std::set<unsigned int>& allowedSubEnvIds)
980 {
981  queso_require_greater_equal_msg(m_env.subRank(), 0, "unexpected subRank");
982 
983  queso_require_less_equal_msg(this->numOfProcsForStorage(), 1, "implemented just for sequential vectors for now");
984 
985  FilePtrSetStruct filePtrSet;
986  if (m_env.openInputFile(fileName,
987  fileType, // "m or hdf"
988  allowedSubEnvIds,
989  filePtrSet)) {
990  double subReadSize = this->sizeLocal();
991 
992  // In the logic below, the id of a line' begins with value 0 (zero)
993  unsigned int idOfMyFirstLine = 1;
994  unsigned int idOfMyLastLine = this->sizeLocal();
995  unsigned int numParams = 1; // Yes, just '1'
996 
997  // Read number of chain positions in the file by taking care of the first line,
998  // which resembles something like 'variable_name = zeros(n_positions,m_params);'
999  std::string tmpString;
1000 
1001  // Read 'variable name' string
1002  *filePtrSet.ifsVar >> tmpString;
1003  //std::cout << "Just read '" << tmpString << "'" << std::endl;
1004 
1005  // Read '=' sign
1006  *filePtrSet.ifsVar >> tmpString;
1007  //std::cout << "Just read '" << tmpString << "'" << std::endl;
1008  queso_require_equal_to_msg(tmpString, "=", "string should be the '=' sign");
1009 
1010  // Read 'zeros(n_positions,n_params)' string
1011  *filePtrSet.ifsVar >> tmpString;
1012  //std::cout << "Just read '" << tmpString << "'" << std::endl;
1013  unsigned int posInTmpString = 6;
1014 
1015  // Isolate 'n_positions' in a string
1016  char nPositionsString[tmpString.size()-posInTmpString+1];
1017  unsigned int posInPositionsString = 0;
1018  do {
1019  queso_require_less_msg(posInTmpString, tmpString.size(), "symbol ',' not found in first line of file");
1020  nPositionsString[posInPositionsString++] = tmpString[posInTmpString++];
1021  } while (tmpString[posInTmpString] != ',');
1022  nPositionsString[posInPositionsString] = '\0';
1023 
1024  // Isolate 'n_params' in a string
1025  posInTmpString++; // Avoid reading ',' char
1026  char nParamsString[tmpString.size()-posInTmpString+1];
1027  unsigned int posInParamsString = 0;
1028  do {
1029  queso_require_less_msg(posInTmpString, tmpString.size(), "symbol ')' not found in first line of file");
1030  nParamsString[posInParamsString++] = tmpString[posInTmpString++];
1031  } while (tmpString[posInTmpString] != ')');
1032  nParamsString[posInParamsString] = '\0';
1033 
1034  // Convert 'n_positions' and 'n_params' strings to numbers
1035  unsigned int sizeOfVecInFile = (unsigned int) strtod(nPositionsString,NULL);
1036  unsigned int numParamsInFile = (unsigned int) strtod(nParamsString, NULL);
1037  if (m_env.subDisplayFile()) {
1038  *m_env.subDisplayFile() << "In TeuchosVector::subReadContents()"
1039  << ": fullRank " << m_env.fullRank()
1040  << ", sizeOfVecInFile = " << sizeOfVecInFile
1041  << ", numParamsInFile = " << numParamsInFile
1042  << ", this->sizeLocal() = " << this->sizeLocal()
1043  << std::endl;
1044  }
1045 
1046  // Check if [size of vec in file] >= [requested sub vec size]
1047  queso_require_greater_equal_msg(sizeOfVecInFile, subReadSize, "size of vec in file is not big enough");
1048 
1049  // Check if [num params in file] == [num params in current vec]
1050  queso_require_equal_to_msg(numParamsInFile, numParams, "number of parameters of vec in file is different than number of parameters in this vec object");
1051 
1052  // Code common to any core in a communicator
1053  unsigned int maxCharsPerLine = 64*numParams; // Up to about 60 characters to represent each parameter value
1054 
1055  unsigned int lineId = 0;
1056  while (lineId < idOfMyFirstLine) {
1057  filePtrSet.ifsVar->ignore(maxCharsPerLine,'\n');
1058  lineId++;
1059  };
1060 
1061  if (m_env.subDisplayFile()) {
1062  *m_env.subDisplayFile() << "In TeuchosVector::subReadContents()"
1063  << ": beginning to read input actual data"
1064  << std::endl;
1065  }
1066 
1067  // Take care of initial part of the first data line,
1068  // which resembles something like 'variable_name = [value1 value2 ...'
1069  // Read 'variable name' string
1070  *filePtrSet.ifsVar >> tmpString;
1071  //std::cout << "Core 0 just read '" << tmpString << "'" << std::endl;
1072 
1073  // Read '=' sign
1074  *filePtrSet.ifsVar >> tmpString;
1075  //std::cout << "Core 0 just read '" << tmpString << "'" << std::endl;
1076  queso_require_equal_to_msg(tmpString, "=", "in core 0, string should be the '=' sign");
1077 
1078  // Take into account the ' [' portion
1079  std::streampos tmpPos = filePtrSet.ifsVar->tellg();
1080  filePtrSet.ifsVar->seekg(tmpPos+(std::streampos)2);
1081 
1082  if (m_env.subDisplayFile()) {
1083  *m_env.subDisplayFile() << "In TeuchosVector::subReadContents()"
1084  << ": beginning to read lines with numbers only"
1085  << ", lineId = " << lineId
1086  << ", idOfMyFirstLine = " << idOfMyFirstLine
1087  << ", idOfMyLastLine = " << idOfMyLastLine
1088  << std::endl;
1089  }
1090 
1091  while (lineId <= idOfMyLastLine) {
1092  *filePtrSet.ifsVar >> (*this)[lineId - idOfMyFirstLine];
1093  lineId++;
1094  };
1095 
1096  m_env.closeFile(filePtrSet,fileType);
1097  }
1098 
1099  return;
1100 }
1101 
1102 // -------------------------------------------------
1103 void
1105  const std::string& varNamePrefix,
1106  const std::string& fileName,
1107  const std::string& fileType,
1108  const std::set<unsigned int>& allowedSubEnvIds) const
1109 {
1110  queso_require_greater_equal_msg(m_env.subRank(), 0, "unexpected subRank");
1111 
1112  queso_require_less_equal_msg(this->numOfProcsForStorage(), 1, "implemented just for sequential vectors for now");
1113 
1114  FilePtrSetStruct filePtrSet;
1115  if (m_env.openOutputFile(fileName,
1116  fileType, // "m or hdf"
1117  allowedSubEnvIds,
1118  false,
1119  filePtrSet)) {
1120  *filePtrSet.ofsVar << varNamePrefix << "_sub" << m_env.subIdString() << " = zeros(" << this->sizeLocal()
1121  << "," << 1
1122  << ");"
1123  << std::endl;
1124  *filePtrSet.ofsVar << varNamePrefix << "_sub" << m_env.subIdString() << " = [";
1125 
1126  bool savedVectorPrintScientific = this->getPrintScientific();
1127  bool savedVectorPrintHorizontally = this->getPrintHorizontally();
1128  this->setPrintScientific (true);
1129  this->setPrintHorizontally(false);
1130  *filePtrSet.ofsVar << *this;
1131  //<< std::endl; // No need for 'endl' because horizontally = 'false'
1132  this->setPrintHorizontally(savedVectorPrintHorizontally);
1133  this->setPrintScientific (savedVectorPrintScientific);
1134 
1135  *filePtrSet.ofsVar << "];\n";
1136 
1137  m_env.closeFile(filePtrSet,fileType);
1138  }
1139 
1140  return;
1141 }
1142 
1143 
1144 // -------------------------------------------------
1145 // Private metfods ---------------------------------
1146 // -------------------------------------------------
1147 
1148 void
1150 {
1151  this->Vector::base_copy(rhs);
1152 
1153  unsigned int size1 = m_vec.length();
1154  unsigned int size2 = rhs.sizeLocal();
1155 
1156  if (size1==size2){
1157  for (unsigned int i=0;i<size1;i++){
1158  m_vec[i]=rhs[i];
1159  }
1160  }
1161  return;
1162 }
1163 
1164 
1165 // -------------------------------------------------
1166 // Operators outside class definition --------------
1167 // -------------------------------------------------
1168 
1169 // -------------------------------------------------
1171 {
1172  TeuchosVector answer(x); //copy x to answer
1173  answer.cwInvert();
1174  answer *= a;
1175  return answer;
1176 }
1177 
1178 // -------------------------------------------------
1180 {
1181  TeuchosVector answer(x);
1182  answer /= y;
1183  return answer;
1184 }
1185 
1186 // -------------------------------------------------
1188 {
1189  TeuchosVector answer(x);
1190  answer *= a;
1191  return answer;
1192 }
1193 
1194 // -------------------------------------------------
1196 {
1197  TeuchosVector answer(x);
1198  answer *= y;
1199  return answer;
1200 }
1201 
1202 // -------------------------------------------------
1203 double scalarProduct(const TeuchosVector& x, const TeuchosVector& y)
1204 {
1205  unsigned int size1 = x.sizeLocal();
1206  unsigned int size2 = y.sizeLocal();
1207 
1208  queso_require_equal_to_msg(size1, size2, "different sizes of x and y");
1209  double result = 0.;
1210  for (unsigned int i = 0; i < size1; ++i) {
1211  result += x[i]*y[i];
1212  }
1213 
1214  return result;
1215 }
1216 
1217 // -------------------------------------------------
1219 {
1220  TeuchosVector answer(x);
1221  answer += y;
1222  return answer;
1223 }
1224 
1225 // -------------------------------------------------
1227 {
1228  TeuchosVector answer(x);
1229  answer -= y;
1230  return answer;
1231 }
1232 
1233 // -------------------------------------------------
1234 bool
1235 operator== (const TeuchosVector& lhs, const TeuchosVector& rhs)
1236 {
1237  bool answer = true;
1238  unsigned int size1 = lhs.sizeLocal();
1239  unsigned int size2 = rhs.sizeLocal();
1240 
1241  queso_require_equal_to_msg(size1, size2, "different sizes of lhs and rhs");
1242 
1243  for (unsigned int i = 0; i < size1; ++i) {
1244  if (lhs[i] != rhs[i]) {
1245  answer = false;
1246  break;
1247  }
1248  }
1249 
1250  return answer;
1251 }
1252 
1253 // -------------------------------------------------
1254 std::ostream&
1255 operator<<(std::ostream& os, const TeuchosVector& obj)
1256 {
1257  obj.print(os);
1258 
1259  return os;
1260 }
1261 
1262 // -------------------------------------------------
1263 
1264 } // End namespace QUESO
1265 
1266 #endif // ifdef QUESO_HAS_TRILINOS
void cwSetConcatenated(const TeuchosVector &v1, const TeuchosVector &v2)
This function concatenates vectors v1 and v2 into this vector.
GslMatrix operator+(const GslMatrix &m1, const GslMatrix &m2)
Definition: GslMatrix.C:2022
virtual double gammaSample(double a, double b) const =0
Samples a value from a Gamma distribution.
void cwExtract(unsigned int initialPos, TeuchosVector &vec) const
Component-wise extracts all values of this with vector vec, starting at position initialPos.
double getMinValue() const
Returns the minimum value in the this vector.
void cwSqrt()
Component-wise sets the square-root of this.
TeuchosVector()
Default Constructor.
int NumGlobalElements() const
Returns the total number of elements across all processors.
Definition: Map.C:85
std::ostream & operator<<(std::ostream &os, const SequenceStatisticalOptions &obj)
std::ifstream * ifsVar
Provides a stream interface to read data from files.
Definition: Environment.h:89
const BaseEnvironment & m_env
Environment variable.
Definition: Vector.h:117
virtual void base_copy(const Vector &src)
Copies base data from vector src to this vector.
Definition: Vector.C:101
void cwSetInverseGamma(const TeuchosVector &a, const TeuchosVector &b)
This function sets component-wise random variates from the Inverse Gamma distribution, with parameters given by vectors a and b.
virtual double gaussianSample(double stdDev) const =0
Samples a value from a Gaussian distribution with standard deviation given by stdDev.
void mpiBcast(int srcRank, const MpiComm &bcastComm)
Broadcasts a message from the process with srcRank root to all other processes of the group...
bool m_printHorizontally
Flag for either or not print this matrix horizontally.
Definition: Vector.h:130
void copy_to_std_vector(std::vector< double > &vec)
Copies the values of this vector (a TeuchosVector) to a std::vector structure.
A class for partitioning vectors and matrices.
Definition: Map.h:49
unsigned int sizeGlobal() const
Returns the global length of this vector.
bool atLeastOneComponentBiggerThan(const TeuchosVector &rhs) const
This function returns true if at least one component of this is bigger than the respective component ...
double normInf() const
Returns the infinity-norm (maximum norm) of the vector.
void cwInvert()
This function inverts component-wise the element values of this.
The QUESO MPI Communicator Class.
Definition: MpiComm.h:203
void print(std::ostream &os) const
Print method. Defines the behavior of the std::ostream &lt;&lt; operator inherited from the Object class...
void Gather(void *sendbuf, int sendcnt, RawType_MPI_Datatype sendtype, void *recvbuf, int recvcount, RawType_MPI_Datatype recvtype, int root, const char *whereMsg, const char *whatMsg) const
Gather values from each process to collect on all processes.
Definition: MpiComm.C:202
const std::string & subIdString() const
Access to the attribute m_subIdString; which stores the string for the sub-environment, and it will be used, for instance, to create the output files for each sub-environment.
Definition: Environment.C:348
void setPrintScientific(bool value) const
Determines whether vector should be printed in Scientific Notation.
Definition: Vector.C:88
TeuchosVector & operator-=(const TeuchosVector &rhs)
Stores in this vector the coordinate-wise subtraction of this and rhs.
TeuchosVector & operator/=(double a)
Stores in this vector the coordinate-wise division of this by a.
~TeuchosVector()
Destructor.
void matlabDiff(unsigned int firstPositionToStoreDiff, double valueForRemainderPosition, TeuchosVector &outputVec) const
bool m_printScientific
Flag for either or not print this matrix in scientific notation.
Definition: Vector.h:133
int getMaxValueIndex() const
This function returns the index of the maximum value in the vector this.
int fullRank() const
Returns the rank of the MPI process in QUESO&#39;s full communicator.
Definition: Environment.C:268
void subWriteContents(const std::string &varNamePrefix, const std::string &fileName, const std::string &fileType, const std::set< unsigned int > &allowedSubEnvIds) const
bool getPrintScientific() const
Checks if the vector should be printed in Scientific Notation.
Definition: Vector.C:95
double norm2Sq() const
Returns the norm of the vector, as the square root of 2-norm of this vector.
double scalarProduct(const GslVector &x, const GslVector &y)
Definition: GslVector.C:1137
void setPrintHorizontally(bool value) const
Determines whether vector should be printed horizontally.
Definition: Vector.C:75
std::ofstream * ofsVar
Provides a stream interface to write data to files.
Definition: Environment.h:86
virtual double betaSample(double alpha, double beta) const =0
Samples a value from a Beta distribution.
bool atLeastOneComponentBiggerOrEqualThan(const TeuchosVector &rhs) const
This function returns true if at least one component of this is bigger than or equal to the respectiv...
unsigned int sizeLocal() const
Returns the length of this vector.
const RngBase * rngObject() const
Access to the RNG object.
Definition: Environment.C:471
void cwSet(double value)
Component-wise sets all values to this with value.
bool openOutputFile(const std::string &fileName, const std::string &fileType, const std::set< unsigned int > &allowedSubEnvIds, bool writeOver, FilePtrSetStruct &filePtrSet) const
Opens an output file for each sub-environment that was chosen to send data to the file...
Definition: Environment.C:521
void matlabLinearInterpExtrap(const TeuchosVector &xVec, const TeuchosVector &yVec, const TeuchosVector &xiVec)
Reproduces MATLAB linear inter/extra-polation.
void cwSetBeta(const TeuchosVector &alpha, const TeuchosVector &beta)
This function sets component-wise random variates from the Beta distribution, with vector parameters ...
GslMatrix operator-(const GslMatrix &m1, const GslMatrix &m2)
Definition: GslMatrix.C:2029
void getMinValueAndIndex(double &value, int &index)
This function returns minimum value in the vector this and its the index.
void cwSetUniform(const TeuchosVector &lowerBoundVec, const TeuchosVector &upperBoundVec)
This function sets component-wise a number uniformly distributed in the range of elements of [lowerBo...
bool operator==(const GslVector &lhs, const GslVector &rhs)
Definition: GslVector.C:1168
double norm2() const
Returns the 2-norm (Euclidean norm) of the vector.
int getMinValueIndex() const
This function returns the index of the minimum value in the vector this.
const Map & map() const
Definition: Vector.C:61
double getMaxValue() const
Returns the maximum value in the this vector.
Class for vector operations (virtual).
Definition: Vector.h:47
void Allreduce(void *sendbuf, void *recvbuf, int count, RawType_MPI_Datatype datatype, RawType_MPI_Op op, const char *whereMsg, const char *whatMsg) const
Combines values from all processes and distributes the result back to all processes.
Definition: MpiComm.C:143
void Barrier() const
Pause every process in *this communicator until all the processes reach this point.
Definition: MpiComm.C:174
double & operator[](unsigned int i)
Element access method (non-const).
void getMaxValueAndIndex(double &value, int &index)
This function returns maximum value in the vector this and its the index.
MPI_Op RawType_MPI_Op
Definition: MpiComm.h:45
double norm1() const
Returns the 1-norm of the vector.
GslMatrix operator*(double a, const GslMatrix &mat)
Definition: GslMatrix.C:1982
TeuchosVector abs() const
This function returns absolute value of all elements in this.
unsigned int numOfProcsForStorage() const
Definition: Vector.C:68
TeuchosVector & operator*=(double a)
Stores in this vector the coordinate-wise multiplication of this and a.
Struct for handling data input and output from files.
Definition: Environment.h:77
void cwSetGaussian(double mean, double stdDev)
This function sets component-wise Gaussian random variates, with mean mean and standard deviation std...
int subRank() const
Returns the rank of the MPI process in the sub-communicator subComm()
Definition: Environment.C:287
void sort()
This function sorts the elements of the vector this in ascending numerical order. ...
void copy_from_std_vector(const std::vector< double > vec)
Copies the values of std::vector structure to this vector (a TeuchosVector).
void mpiAllQuantile(double probability, const MpiComm &opComm, TeuchosVector &resultVec) const
Gathers values from a group of processes and returns all quantiles.
void closeFile(FilePtrSetStruct &filePtrSet, const std::string &fileType) const
Closes the file.
Definition: Environment.C:1084
GslVector operator/(double a, const GslVector &x)
Definition: GslVector.C:1104
int MyPID() const
Return my process ID.
Definition: MpiComm.C:124
Teuchos::SerialDenseVector< int, double > m_vec
Teuchos vector.
void cwSetGamma(const TeuchosVector &a, const TeuchosVector &b)
This function sets component-wise random variates from the Inverse Gamma distribution, with parameters given by vectors a and b.
double sumOfComponents() const
Returns the sum of the components of the vector.
virtual double uniformSample() const =0
Samples a value from a uniform distribution.
void subReadContents(const std::string &fileName, const std::string &fileType, const std::set< unsigned int > &allowedSubEnvIds)
int NumMyElements() const
Returns the number of elements owned by the calling processor.
Definition: Map.C:107
void mpiAllReduce(RawType_MPI_Op mpiOperation, const MpiComm &opComm, TeuchosVector &resultVec) const
Combines values from all processes and distributes the result back to all processes.
void copy(const TeuchosVector &src)
This function copies the elements of the vector src into this.
int NumProc() const
Returns total number of processes.
Definition: MpiComm.C:133
MonteCarloSGOptions::MonteCarloSGOptions(const BaseEnvironment &env, const char *prefix, const McOptionsValues &alternativeOptionsValues queso_require_equal_to_msg)(m_env.optionsInputFileName(), std::string(""), std::string("this constructor is incompatible with the existence of an options input file"))
Class for vector operations using Teuchos (Trilinos).
Definition: TeuchosVector.h:55
TeuchosVector & operator+=(const TeuchosVector &rhs)
Stores in this vector the coordinate-wise addition of this and rhs.
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:320
bool openInputFile(const std::string &fileName, const std::string &fileType, const std::set< unsigned int > &allowedSubEnvIds, FilePtrSetStruct &filePtrSet) const
Opens an input file.
Definition: Environment.C:896
const Map m_map
Mapping variable.
Definition: Vector.h:122
bool getPrintHorizontally() const
Checks if vector is printed horizontally.
Definition: Vector.C:82
TeuchosVector & operator=(double a)
Set all values in the vector to a constant value.
unsigned int displayVerbosity() const
Definition: Environment.C:450
void Bcast(void *buffer, int count, RawType_MPI_Datatype datatype, int root, const char *whereMsg, const char *whatMsg) const
Broadcast values from the root process to the slave processes.
Definition: MpiComm.C:191
bool atLeastOneComponentSmallerOrEqualThan(const TeuchosVector &rhs) const
This function returns true if at least one component of this is smaller than or equal to the respecti...
bool atLeastOneComponentSmallerThan(const TeuchosVector &rhs) const
This function returns true if at least one component of this is smaller than the respective component...
This (virtual) class sets up the environment underlying the use of the QUESO library by an executable...
Definition: Environment.h:198

Generated on Sat Apr 22 2017 14:04:36 for queso-0.57.0 by  doxygen 1.8.5