EpetraExt Package Browser (Single Doxygen Collection) Development
test/inout/cxx_main.cpp
Go to the documentation of this file.
00001 /*
00002 //@HEADER
00003 // ***********************************************************************
00004 //
00005 //     EpetraExt: Epetra Extended - Linear Algebra Services Package
00006 //                 Copyright (2011) Sandia Corporation
00007 //
00008 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
00009 // the U.S. Government retains certain rights in this software.
00010 //
00011 // Redistribution and use in source and binary forms, with or without
00012 // modification, are permitted provided that the following conditions are
00013 // met:
00014 //
00015 // 1. Redistributions of source code must retain the above copyright
00016 // notice, this list of conditions and the following disclaimer.
00017 //
00018 // 2. Redistributions in binary form must reproduce the above copyright
00019 // notice, this list of conditions and the following disclaimer in the
00020 // documentation and/or other materials provided with the distribution.
00021 //
00022 // 3. Neither the name of the Corporation nor the names of the
00023 // contributors may be used to endorse or promote products derived from
00024 // this software without specific prior written permission.
00025 //
00026 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00027 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00028 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00029 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00030 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00031 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00032 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00033 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00034 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00035 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00036 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00037 //
00038 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
00039 //
00040 // ***********************************************************************
00041 //@HEADER
00042 */
00043 
00044 #include "Epetra_ConfigDefs.h"
00045 #include "EpetraExt_Version.h"
00046 #ifdef EPETRA_MPI
00047 #include "mpi.h"
00048 #include "Epetra_MpiComm.h"
00049 #else
00050 #include "Epetra_SerialComm.h"
00051 #endif
00052 #include "Trilinos_Util.h"
00053 #include "Epetra_Comm.h"
00054 #include "Epetra_Map.h"
00055 #include "Epetra_Time.h"
00056 #include "Epetra_BlockMap.h"
00057 #include "Epetra_MultiVector.h"
00058 #include "Epetra_Vector.h"
00059 #include "Epetra_Export.h"
00060 
00061 #include "Epetra_VbrMatrix.h"
00062 #include "Epetra_CrsMatrix.h"
00063 #include "EpetraExt_RowMatrixOut.h"
00064 #include "EpetraExt_OperatorOut.h"
00065 #include "EpetraExt_MultiVectorOut.h"
00066 #include "EpetraExt_VectorOut.h"
00067 #include "EpetraExt_BlockMapOut.h"
00068 #include "EpetraExt_BlockMapIn.h"
00069 #include "EpetraExt_CrsMatrixIn.h"
00070 #include "EpetraExt_MultiVectorIn.h"
00071 #include "EpetraExt_VectorIn.h"
00072 // include the header files again to check if guards are in place
00073 #include "EpetraExt_RowMatrixOut.h"
00074 #include "EpetraExt_VectorOut.h"
00075 #include "EpetraExt_BlockMapOut.h"
00076 #include "EpetraExt_BlockMapIn.h"
00077 #include "EpetraExt_CrsMatrixIn.h"
00078 #include "EpetraExt_MultiVectorIn.h"
00079 #include "EpetraExt_VectorIn.h"
00080 #include <string>
00081 #include <vector>
00082 #include "Poisson2dOperator.h"
00083 // prototypes
00084 
00085 int checkValues( double x, double y, std::string message = "", bool verbose = false) { 
00086   if (fabs((x-y)/x) > 0.01 && x > 1.0e-12) {
00087     if (verbose) std::cout << "********** " << message << " check failed.********** " << std::endl;
00088     return(1); 
00089   }
00090   else {
00091     if (verbose) std::cout << message << " check OK." << std::endl;    
00092     return(0);
00093   }
00094 }
00095 int runTests(Epetra_Map & map, Epetra_CrsMatrix & A, Epetra_Vector & x, Epetra_Vector & b, Epetra_Vector & xexact, bool verbose);
00096 int runOperatorTests(Epetra_Operator & A, bool verbose);
00097 int generateHyprePrintOut(const char* filename, const Epetra_Comm &comm);
00098 int runHypreTest(Epetra_CrsMatrix &A);
00099 
00100 int main(int argc, char *argv[]) {
00101 
00102 #ifdef EPETRA_MPI
00103   MPI_Init(&argc,&argv);
00104   Epetra_MpiComm comm (MPI_COMM_WORLD);
00105 #else
00106   Epetra_SerialComm comm;
00107 #endif
00108 
00109   int MyPID = comm.MyPID();
00110 
00111   bool verbose = false;
00112   bool verbose1 = false; 
00113   // Check if we should print results to standard out
00114   if (argc > 1) {
00115     if ((argv[1][0] == '-') && (argv[1][1] == 'v')) {
00116       verbose1 = true;
00117       if (MyPID==0) verbose = true;
00118     }
00119   }
00120   if (verbose)
00121     std::cout << EpetraExt::EpetraExt_Version() << std::endl << std::endl;
00122 
00123   if (verbose1) std::cout << comm << std::endl;
00124 
00125 
00126   // Uncomment the next three lines to debug in mpi mode
00127   //int tmp;
00128   //if (MyPID==0) cin >> tmp;
00129   //comm.Barrier();
00130 
00131   Epetra_Map * map;
00132   Epetra_CrsMatrix * A; 
00133   Epetra_Vector * x; 
00134   Epetra_Vector * b;
00135   Epetra_Vector * xexact;
00136 
00137   int nx = 20*comm.NumProc();
00138   int ny = 30;
00139   int npoints = 7;
00140   int xoff[] = {-1,  0,  1, -1,  0,  1,  0};
00141   int yoff[] = {-1, -1, -1,  0,  0,  0,  1};
00142 
00143    
00144   int ierr = 0;
00145   // Call routine to read in HB problem 0-base
00146   Trilinos_Util_GenerateCrsProblem(nx, ny, npoints, xoff, yoff, comm, map, A, x, b, xexact);
00147 
00148   ierr += runTests(*map, *A, *x, *b, *xexact, verbose);
00149 
00150   delete A;
00151   delete x;
00152   delete b;
00153   delete xexact;
00154   delete map;
00155 
00156   // Call routine to read in HB problem 1-base
00157   Trilinos_Util_GenerateCrsProblem(nx, ny, npoints, xoff, yoff, comm, map, A, x, b, xexact, 1);
00158 
00159   ierr += runTests(*map, *A, *x, *b, *xexact, verbose);
00160 
00161   delete A;
00162   delete x;
00163   delete b;
00164   delete xexact;
00165   delete map;
00166 
00167   // Call routine to read in HB problem -1-base
00168   Trilinos_Util_GenerateCrsProblem(nx, ny, npoints, xoff, yoff, comm, map, A, x, b, xexact, -1);
00169 
00170   ierr += runTests(*map, *A, *x, *b, *xexact, verbose);
00171 
00172   delete A;
00173   delete x;
00174   delete b;
00175   delete xexact;
00176   delete map;
00177 
00178   int nx1 = 5;
00179   int ny1 = 4;
00180   Poisson2dOperator Op(nx1, ny1, comm);
00181   ierr += runOperatorTests(Op, verbose);
00182 
00183   generateHyprePrintOut("MyMatrixFile", comm);
00184 
00185   EPETRA_CHK_ERR(EpetraExt::HypreFileToCrsMatrix("MyMatrixFile", comm, A));
00186   
00187   runHypreTest(*A);
00188   delete A;
00189 
00190   #ifdef EPETRA_MPI
00191   MPI_Finalize() ;
00192 #endif
00193 
00194   return(ierr);
00195 }
00196 
00197 int runHypreTest(Epetra_CrsMatrix &A){
00198   
00199   Epetra_Vector X(A.RowMap());
00200   EPETRA_CHK_ERR(X.Random());
00201   Epetra_Vector Y(A.RowMap());
00202   EPETRA_CHK_ERR(A.Multiply(false, X, Y));
00203   
00204   return 0;
00205 }
00206 
00207 int runTests(Epetra_Map & map, Epetra_CrsMatrix & A, Epetra_Vector & x, Epetra_Vector & b, Epetra_Vector & xexact, bool verbose) {
00208 
00209   int ierr = 0;
00210 
00211   // Create MultiVectors and put x, b, xexact in both columns of X, B, and Xexact, respectively.
00212   Epetra_MultiVector X( map, 2, false );
00213   Epetra_MultiVector B( map, 2, false );
00214   Epetra_MultiVector Xexact( map, 2, false );
00215 
00216   for (int i=0; i<X.NumVectors(); ++i) {
00217     *X(i) = x;
00218     *B(i) = b;
00219     *Xexact(i) = xexact;
00220   }
00221   double residual;
00222   std::vector<double> residualmv(2);
00223   residual = A.NormInf(); double rAInf = residual;
00224   if (verbose) std::cout << "Inf Norm of A                                                     = " << residual << std::endl;
00225   residual = A.NormOne(); double rAOne = residual;
00226   if (verbose) std::cout << "One Norm of A                                                     = " << residual << std::endl;
00227   xexact.Norm2(&residual); double rxx = residual; 
00228   Xexact.Norm2(&residualmv[0]); std::vector<double> rXX( residualmv );  
00229   if (verbose) std::cout << "Norm of xexact                                                    = " << residual << std::endl;
00230   if (verbose) std::cout << "Norm of Xexact                                                    = (" << residualmv[0] << ", " <<residualmv[1] <<")"<< std::endl;
00231   Epetra_Vector tmp1(map);
00232   Epetra_MultiVector tmp1mv(map,2,false);
00233   A.Multiply(false, xexact, tmp1);
00234   A.Multiply(false, Xexact, tmp1mv);
00235   tmp1.Norm2(&residual); double rAx = residual;
00236   tmp1mv.Norm2(&residualmv[0]); std::vector<double> rAX( residualmv );
00237   if (verbose) std::cout << "Norm of Ax                                                        = " << residual << std::endl;
00238   if (verbose) std::cout << "Norm of AX                                                        = (" << residualmv[0] << ", " << residualmv[1] <<")"<< std::endl;
00239   b.Norm2(&residual); double rb = residual;
00240   B.Norm2(&residualmv[0]); std::vector<double> rB( residualmv );
00241   if (verbose) std::cout << "Norm of b (should equal norm of Ax)                               = " << residual << std::endl;
00242   if (verbose) std::cout << "Norm of B (should equal norm of AX)                               = (" << residualmv[0] << ", " << residualmv[1] <<")"<< std::endl;
00243   tmp1.Update(1.0, b, -1.0);
00244   tmp1mv.Update(1.0, B, -1.0);
00245   tmp1.Norm2(&residual);
00246   tmp1mv.Norm2(&residualmv[0]);
00247   if (verbose) std::cout << "Norm of difference between compute Ax and Ax from file            = " << residual << std::endl;
00248   if (verbose) std::cout << "Norm of difference between compute AX and AX from file            = (" << residualmv[0] << ", " << residualmv[1] <<")"<< std::endl;
00249   map.Comm().Barrier();
00250 
00251   EPETRA_CHK_ERR(EpetraExt::BlockMapToMatrixMarketFile("Test_map.mm", map, "Official EpetraExt test map", 
00252                    "This is the official EpetraExt test map generated by the EpetraExt regression tests"));
00253 
00254   EPETRA_CHK_ERR(EpetraExt::RowMatrixToMatrixMarketFile("Test_A.mm", A, "Official EpetraExt test matrix", 
00255               "This is the official EpetraExt test matrix generated by the EpetraExt regression tests"));
00256 
00257   EPETRA_CHK_ERR(EpetraExt::VectorToMatrixMarketFile("Test_x.mm", x, "Official EpetraExt test initial guess", 
00258                  "This is the official EpetraExt test initial guess generated by the EpetraExt regression tests"));
00259 
00260   EPETRA_CHK_ERR(EpetraExt::MultiVectorToMatrixMarketFile("Test_mvX.mm", X, "Official EpetraExt test initial guess", 
00261                             "This is the official EpetraExt test initial guess generated by the EpetraExt regression tests"));
00262                
00263   EPETRA_CHK_ERR(EpetraExt::VectorToMatrixMarketFile("Test_xexact.mm", xexact, "Official EpetraExt test exact solution", 
00264                  "This is the official EpetraExt test exact solution generated by the EpetraExt regression tests"));
00265 
00266   EPETRA_CHK_ERR(EpetraExt::MultiVectorToMatrixMarketFile("Test_mvXexact.mm", Xexact, "Official EpetraExt test exact solution", 
00267                       "This is the official EpetraExt test exact solution generated by the EpetraExt regression tests"));
00268                
00269   EPETRA_CHK_ERR(EpetraExt::VectorToMatrixMarketFile("Test_b.mm", b, "Official EpetraExt test right hand side", 
00270                  "This is the official EpetraExt test right hand side generated by the EpetraExt regression tests"));
00271 
00272   EPETRA_CHK_ERR(EpetraExt::MultiVectorToMatrixMarketFile("Test_mvB.mm", B, "Official EpetraExt test right hand side", 
00273                       "This is the official EpetraExt test right hand side generated by the EpetraExt regression tests"));
00274                
00275   EPETRA_CHK_ERR(EpetraExt::MultiVectorToMatlabFile("Test_mvB.mat", B));
00276  
00277   EPETRA_CHK_ERR(EpetraExt::RowMatrixToMatlabFile("Test_A.dat", A));
00278 
00279   Epetra_Map * map1;
00280   Epetra_CrsMatrix * A1; 
00281   Epetra_CrsMatrix * A2; 
00282   Epetra_CrsMatrix * A3; 
00283   Epetra_Vector * x1; 
00284   Epetra_Vector * b1;
00285   Epetra_Vector * xexact1;
00286   Epetra_MultiVector * X1; 
00287   Epetra_MultiVector * B1;
00288   Epetra_MultiVector * Xexact1;
00289 
00290   EpetraExt::MatrixMarketFileToMap("Test_map.mm", map.Comm(), map1);
00291 
00292   if (map.SameAs(*map1)) {
00293     if (verbose) std::cout << "Maps are equal.  In/Out works." << std::endl;
00294   }
00295   else {
00296     if (verbose) std::cout << "Maps are not equal.  In/Out fails." << std::endl;
00297     ierr += 1;
00298   }
00299   EPETRA_CHK_ERR(EpetraExt::MatrixMarketFileToCrsMatrix("Test_A.mm", *map1, A1));
00300   // If map is zero-based, then we can compare to the convenient reading versions
00301   if (map1->IndexBase()==0) EPETRA_CHK_ERR(EpetraExt::MatrixMarketFileToCrsMatrix("Test_A.mm", map1->Comm(), A2));
00302   if (map1->IndexBase()==0) EPETRA_CHK_ERR(EpetraExt::MatlabFileToCrsMatrix("Test_A.dat", map1->Comm(), A3));
00303   EPETRA_CHK_ERR(EpetraExt::MatrixMarketFileToVector("Test_x.mm", *map1, x1));
00304   EPETRA_CHK_ERR(EpetraExt::MatrixMarketFileToVector("Test_xexact.mm", *map1, xexact1));
00305   EPETRA_CHK_ERR(EpetraExt::MatrixMarketFileToVector("Test_b.mm", *map1, b1));
00306   EPETRA_CHK_ERR(EpetraExt::MatrixMarketFileToMultiVector("Test_mvX.mm", *map1, X1));
00307   EPETRA_CHK_ERR(EpetraExt::MatrixMarketFileToMultiVector("Test_mvXexact.mm", *map1, Xexact1));
00308   EPETRA_CHK_ERR(EpetraExt::MatrixMarketFileToMultiVector("Test_mvB.mm", *map1, B1));
00309 
00310   residual = A1->NormInf(); double rA1Inf = residual;
00311   if (verbose) std::cout << "Inf Norm of A1                                                    = " << residual << std::endl;
00312   ierr += checkValues(rA1Inf,rAInf,"Inf Norm of A", verbose);
00313 
00314   residual = A1->NormOne(); double rA1One = residual;
00315   if (verbose) std::cout << "One Norm of A1                                                    = " << residual << std::endl;
00316   ierr += checkValues(rA1One,rAOne,"One Norm of A", verbose);
00317 
00318   xexact1->Norm2(&residual); double rxx1 = residual;
00319   if (verbose) std::cout << "Norm of xexact1                                                   = " << residual << std::endl;
00320   ierr += checkValues(rxx1,rxx,"Norm of xexact", verbose);
00321 
00322   Xexact1->Norm2(&residualmv[0]); std::vector<double> rXX1(residualmv);
00323   if (verbose) std::cout << "Norm of Xexact1                                                   = (" << residualmv[0] <<", " <<residualmv[1]<<")"<< std::endl;
00324   ierr += checkValues(rXX1[0],rXX[0],"Norm of Xexact", verbose);
00325   ierr += checkValues(rXX1[1],rXX[1],"Norm of Xexact", verbose);
00326 
00327   Epetra_Vector tmp11(*map1);
00328   A1->Multiply(false, *xexact1, tmp11);
00329 
00330   Epetra_MultiVector tmp11mv(*map1,2,false);
00331   A1->Multiply(false, *Xexact1, tmp11mv);
00332 
00333   tmp11.Norm2(&residual); double rAx1 = residual;
00334   if (verbose) std::cout << "Norm of A1*x1                                                     = " << residual << std::endl;
00335   ierr += checkValues(rAx1,rAx,"Norm of A1*x", verbose);
00336 
00337   tmp11mv.Norm2(&residualmv[0]); std::vector<double> rAX1(residualmv);
00338   if (verbose) std::cout << "Norm of A1*X1                                                     = (" << residualmv[0] <<", "<<residualmv[1]<<")"<< std::endl;
00339   ierr += checkValues(rAX1[0],rAX[0],"Norm of A1*X", verbose);
00340   ierr += checkValues(rAX1[1],rAX[1],"Norm of A1*X", verbose);
00341 
00342   if (map1->IndexBase()==0) {
00343     Epetra_Vector tmp12(*map1);
00344     A2->Multiply(false, *xexact1, tmp12);
00345     
00346     tmp12.Norm2(&residual); double rAx2 = residual;
00347     if (verbose) std::cout << "Norm of A2*x1                                                     = " << residual << std::endl;
00348     ierr += checkValues(rAx2,rAx,"Norm of A2*x", verbose);
00349 
00350     Epetra_Vector tmp13(*map1);
00351     A3->Multiply(false, *xexact1, tmp13);
00352     
00353     tmp13.Norm2(&residual); double rAx3 = residual;
00354     if (verbose) std::cout << "Norm of A3*x1                                                     = " << residual << std::endl;
00355     ierr += checkValues(rAx3,rAx,"Norm of A3*x", verbose);
00356   }
00357   b1->Norm2(&residual); double rb1 = residual;
00358   if (verbose) std::cout << "Norm of b1 (should equal norm of Ax)                              = " << residual << std::endl;
00359   ierr += checkValues(rb1,rb,"Norm of b", verbose);
00360 
00361   B1->Norm2(&residualmv[0]); std::vector<double> rB1(residualmv);
00362   if (verbose) std::cout << "Norm of B1 (should equal norm of AX)                              = (" << residualmv[0] <<", "<<residualmv[1]<<")"<< std::endl;
00363   ierr += checkValues(rB1[0],rB[0],"Norm of B", verbose);
00364   ierr += checkValues(rB1[1],rB[1],"Norm of B", verbose);
00365 
00366   tmp11.Update(1.0, *b1, -1.0);
00367   tmp11.Norm2(&residual);
00368   if (verbose) std::cout << "Norm of difference between computed A1x1 and A1x1 from file        = " << residual << std::endl;
00369   ierr += checkValues(residual,0.0,"Norm of difference between computed A1x1 and A1x1 from file", verbose);
00370 
00371   tmp11mv.Update(1.0, *B1, -1.0);
00372   tmp11mv.Norm2(&residualmv[0]);
00373   if (verbose) std::cout << "Norm of difference between computed A1X1 and A1X1 from file        = (" << residualmv[0] << ", "<<residualmv[1]<<")"<< std::endl;
00374   ierr += checkValues(residualmv[0],0.0,"Norm of difference between computed A1X1 and A1X1 from file", verbose);
00375   ierr += checkValues(residualmv[1],0.0,"Norm of difference between computed A1X1 and A1X1 from file", verbose);
00376 
00377   if (map1->IndexBase()==0) {delete A2; delete A3;}
00378   delete A1;
00379   delete x1;
00380   delete b1;
00381   delete xexact1;
00382   delete X1;
00383   delete B1;
00384   delete Xexact1;
00385   delete map1;
00386 
00387   return(ierr);
00388 }
00389 
00390 int runOperatorTests(Epetra_Operator & A, bool verbose) {
00391 
00392   int ierr = 0;
00393 
00394 
00395   double residual;
00396   EPETRA_CHK_ERR(EpetraExt::OperatorToMatrixMarketFile("Test_A1.mm", A, "Official EpetraExt test operator", 
00397               "This is the official EpetraExt test operator generated by the EpetraExt regression tests"));
00398   EPETRA_CHK_ERR(EpetraExt::OperatorToMatlabFile("Test_A1.dat", A));
00399 
00400   A.OperatorRangeMap().Comm().Barrier();
00401   A.OperatorRangeMap().Comm().Barrier();
00402   Epetra_CrsMatrix * A1; 
00403   Epetra_CrsMatrix * A2; 
00404   EPETRA_CHK_ERR(EpetraExt::MatrixMarketFileToCrsMatrix("Test_A1.mm", A.OperatorRangeMap(), A1));
00405   EPETRA_CHK_ERR(EpetraExt::MatlabFileToCrsMatrix("Test_A1.dat", A.OperatorRangeMap().Comm(), A2));
00406 
00407 
00408   residual = A.NormInf(); double rAInf = residual;
00409   if (verbose) std::cout << "Inf Norm of Operator A                                            = " << residual << std::endl;
00410   residual = A1->NormInf(); double rA1Inf = residual;
00411   if (verbose) std::cout << "Inf Norm of Matrix A1                                             = " << residual << std::endl;
00412   ierr += checkValues(rA1Inf,rAInf,"Inf Norm of A", verbose);
00413 
00414 
00415   Epetra_Vector x(A.OperatorDomainMap()); x.Random();
00416   Epetra_Vector y1(A.OperatorRangeMap());
00417   Epetra_Vector y2(A.OperatorRangeMap());
00418   Epetra_Vector y3(A.OperatorRangeMap());
00419   A.Apply(x,y1);
00420   A1->Multiply(false, x, y2);
00421   A2->Multiply(false, x, y3);
00422 
00423   y1.Norm2(&residual); double rAx1 = residual;
00424   if (verbose) std::cout << "Norm of A*x                                                       = " << residual << std::endl;
00425 
00426   y2.Norm2(&residual); double rAx2 = residual;
00427   if (verbose) std::cout << "Norm of A1*x                                                      = " << residual << std::endl;
00428   ierr += checkValues(rAx1,rAx2,"Norm of A1*x", verbose);
00429 
00430   y3.Norm2(&residual); double rAx3 = residual;
00431   if (verbose) std::cout << "Norm of A2*x                                                      = " << residual << std::endl;
00432   ierr += checkValues(rAx1,rAx3,"Norm of A2*x", verbose);
00433 
00434   delete A1;
00435   delete A2;
00436 
00437   return(ierr);
00438 }
00439 
00440 int generateHyprePrintOut(const char *filename, const Epetra_Comm &comm){
00441   int MyPID = comm.MyPID();
00442   int NumProc = comm.NumProc();
00443 
00444   int N = 100;
00445   int ilower = MyPID * N;
00446   int iupper = (MyPID+1)*N-1;
00447 
00448   double filePID = (double)MyPID/(double)100000;
00449   std::ostringstream stream;
00450   // Using setprecision() puts it in the std::string
00451   stream << std::setiosflags(std::ios::fixed) << std::setprecision(5) << filePID;
00452   // Then just ignore the first character
00453   std::string fileName(filename);
00454   fileName += stream.str().substr(1,7);
00455 
00456   std::ofstream myfile(fileName.c_str());
00457 
00458   if(myfile.is_open()){
00459     myfile << ilower << " " << iupper << " " << ilower << " " << iupper << std::endl;
00460     for(int i = ilower; i <= iupper; i++){
00461       for(int j=i-5; j <= i+5; j++){
00462         if(j >= 0 && j < N*NumProc)
00463           myfile << i << " " << j << " " << (double)rand()/(double)RAND_MAX << std::endl;
00464       }
00465     }
00466     myfile.close();
00467     return 0;
00468   } else {
00469     std::cout << "\nERROR:\nCouldn't open file.\n";
00470     return -1;
00471   }
00472 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines