00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include <cmath>
00014 #include <iostream>
00015 #include <fstream>
00016 #include <cstdlib>
00017 #include <unistd.h>
00018 #include <limits>
00019 #include <tut.h>
00020 #include "Epetra_Comm.h"
00021 #include "Epetra_CrsMatrix.h"
00022 #include "Epetra_Map.h"
00023 #include "Epetra_Vector.h"
00024 #include "Trilinos_Util_CrsMatrixGallery.h"
00025 #include "myrlog.h"
00026 #include "balancedmtxreader.h"
00027 #include "mtxreader.h"
00028
00029 #undef RLOG_TIME_TSC
00030 #include "rlog/RLogTime.h"
00031
00032 namespace tut {
00033 Epetra_Comm& get_comm_world();
00034 }
00035
00036 namespace {
00037
00038 struct testdata {
00039 testdata()
00040 : comm(tut::get_comm_world()) {}
00041 Epetra_Comm& comm;
00042 };
00043
00044 typedef tut::test_group<testdata> testgroup;
00045 typedef testgroup::object testobject;
00046 testgroup group("matrix_memory");
00047
00048
00049 template<>
00050 template<>
00051 void testobject::test<5>() {
00052 rInfo("Reading test matrices...");
00053 string filename;
00054 BaseMtxReader *reader = 0;
00055
00056
00057 filename = "test/ml_laplace/H.mtx";
00058 if (access(filename.c_str(), R_OK)) {
00059 rError("Unable to access H matrix file.");
00060 exit(1);
00061 }
00062 reader = new BalancedMtxReader(filename, comm);
00063
00064 size_t before, after;
00065 before = get_mem_footprint();
00066
00067 Epetra_CrsMatrix* A = reader->read();
00068
00069 after = get_mem_footprint();
00070 size_t measured = after - before;
00071
00072
00073 size_t estimated = get_matrix_mem_footprint(*A);
00074
00075 rInfo("estimated = %s, measured = %s",
00076 rlog::bytes2str(estimated).c_str(),
00077 rlog::bytes2str(measured).c_str());
00078
00079
00080 ensure(0.7 * estimated < measured && measured < 1.3 * estimated);
00081
00082 delete reader;
00083 delete A;
00084 }
00085
00086 template<>
00087 template<>
00088 void testobject::test<10>() {
00089 const int N = 1000000;
00090
00091 Trilinos_Util::CrsMatrixGallery gallery("laplace_2d", comm);
00092 gallery.Set("problem_size", N);
00093 gallery.Set("map_type", "linear");
00094 gallery.Set("exact_solution", "random");
00095
00096 size_t before, after;
00097 before = get_mem_footprint();
00098
00099 Epetra_CrsMatrix* A = gallery.GetMatrix();
00100 after = get_mem_footprint();
00101 size_t measured = after - before;
00102
00103
00104 size_t estimated = get_matrix_mem_footprint(*A);
00105 rInfo("estimated = %s, measured = %s",
00106 rlog::bytes2str(estimated).c_str(),
00107 rlog::bytes2str(measured).c_str());
00108
00109
00110 ensure(0.7 * estimated < measured && measured < 1.3 * estimated);
00111
00112 }
00113
00117 template<>
00118 template<>
00119 void testobject::test<1>() {
00120 int nx = 1000;
00121 int ny = 1000;
00122 int numPoint = nx*ny;
00123
00124 size_t before, after;
00125 before = get_mem_footprint();
00126
00127 Epetra_Map unifMap(numPoint, 0, comm);
00128 Epetra_CrsMatrix A(Copy, unifMap, 5, false);
00129
00130 for (int iy = 0; iy < ny; ++iy) {
00131 for (int ix = 0; ix < nx; ++ix) {
00132 int point = iy*nx + ix;
00133 if (unifMap.MyGID(point) == false)
00134 continue;
00135 int col = point;
00136 double val = 4.0;
00137 assert(A.InsertGlobalValues(point, 1, &val, &col) >= 0);
00138 if (ix > 0) {
00139 col = point-1;
00140 val = -1.0;
00141 assert(A.InsertGlobalValues(point, 1, &val, &col) >= 0);
00142 }
00143 if (ix < nx-1) {
00144 col = point+1;
00145 val = -1.0;
00146 assert(A.InsertGlobalValues(point, 1, &val, &col) >= 0);
00147 }
00148 if (iy > 0) {
00149 col = point-nx;
00150 val = -1.0;
00151 assert(A.InsertGlobalValues(point, 1, &val, &col) >= 0);
00152 }
00153 if (iy < ny-1) {
00154 col = point+nx;
00155 val = -1.0;
00156 assert(A.InsertGlobalValues(point, 1, &val, &col) >= 0);
00157 }
00158 }
00159 }
00160 assert(A.FillComplete() >= 0);
00161 assert(A.OptimizeStorage() >= 0);
00162
00163 after = get_mem_footprint();
00164 size_t measured = after - before;
00165
00166
00167 size_t estimated = get_matrix_mem_footprint(A);
00168 rInfo("estimated = %s, measured = %s",
00169 rlog::bytes2str(estimated).c_str(),
00170 rlog::bytes2str(measured).c_str());
00171
00172
00173 ensure(0.7 * estimated < measured && measured < 1.3 * estimated);
00174 }
00175
00176 };