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

Generated on Thu Jun 11 2015 13:52:31 for queso-0.53.0 by  doxygen 1.8.5