1 | #include <stdio.h>
|
---|
2 | #include <stdlib.h>
|
---|
3 | #include <math.h>
|
---|
4 | #include <iostream>
|
---|
5 |
|
---|
6 | #include "sopnamsp.h"
|
---|
7 | #include "histinit.h"
|
---|
8 | #include "ctimer.h"
|
---|
9 | #include "datatable.h"
|
---|
10 | #include "swppfdtable.h"
|
---|
11 |
|
---|
12 | /* Programme test performances des DataTables / cf G. Barrand */
|
---|
13 | /* R. Ansari (LAL) - Avril 2005 */
|
---|
14 |
|
---|
15 | void cre_rempli_table(BaseDataTable& dt, sa_size_t nl)
|
---|
16 | {
|
---|
17 | Timer tm("cre_rempli_table");
|
---|
18 | cout << " tstdtable/Info: cre_rempli_table() avec nl = " << nl << endl;
|
---|
19 | // Ajout de colonnes int + 6 x double
|
---|
20 | dt.AddIntegerColumn("i");
|
---|
21 | dt.AddDoubleColumn("p1");
|
---|
22 | dt.AddDoubleColumn("p2");
|
---|
23 | dt.AddDoubleColumn("p3");
|
---|
24 | dt.AddDoubleColumn("p4");
|
---|
25 | dt.AddDoubleColumn("p5");
|
---|
26 | dt.AddDoubleColumn("p6");
|
---|
27 | // remplissage :
|
---|
28 | MuTyV rec[10];
|
---|
29 | // r_8 rec[10]; Si on veut tout remplir avec des double
|
---|
30 | sa_size_t nl10 = nl/10;
|
---|
31 | for(sa_size_t k=0; k<nl; k++) {
|
---|
32 | rec[0] = (int_4)(k+1);
|
---|
33 | rec[1] = (r_8)(k*M_PI);
|
---|
34 | rec[2] = (r_8)(2*k*M_PI);
|
---|
35 | rec[3] = (r_8)(3*k*M_PI);
|
---|
36 | rec[4] = (r_8)(4*k*M_PI);
|
---|
37 | rec[5] = (r_8)(5*k*M_PI);
|
---|
38 | rec[6] = (r_8)(6*k*M_PI);
|
---|
39 | dt.AddLine(rec);
|
---|
40 | if ((k%nl10)==0)
|
---|
41 | cout << "cre_rempli_table/Info fin remplissage ligne " << k << endl;
|
---|
42 | }
|
---|
43 | tm.Split("cre_rempli_table/fin remplissage");
|
---|
44 | // Impression resume de la table :
|
---|
45 | cout << dt ;
|
---|
46 | return;
|
---|
47 | }
|
---|
48 |
|
---|
49 | void lit_ck_table(BaseDataTable& dt)
|
---|
50 | {
|
---|
51 | cout << " tstdtable/Info: lit_ck_table() - Table: " << endl;
|
---|
52 | cout << dt;
|
---|
53 | if (dt.NEntry() < 1) {
|
---|
54 | cout << " tstdtable/Error: Table vide ! " << endl;
|
---|
55 | return;
|
---|
56 | }
|
---|
57 | r_8 mean[10] = {0., 0., 0., 0., 0., 0., 0., 0., 0., 0. };
|
---|
58 | r_8* rec;
|
---|
59 | sa_size_t nl10 = dt.NEntry()/10;
|
---|
60 | for(sa_size_t k=0; k<dt.NEntry(); k++) {
|
---|
61 | rec = dt.GetLineD(k);
|
---|
62 | for(int i=0; i<7; i++) mean[i] += rec[i];
|
---|
63 | if ((k%nl10)==0)
|
---|
64 | cout << "li_ck_table/Info fin check ligne " << k << endl;
|
---|
65 | }
|
---|
66 | double wtot = dt.NEntry();
|
---|
67 | for(int i=0; i<7; i++) {
|
---|
68 | mean[i] /= wtot;
|
---|
69 | cout << " tstdtable/Info: Moyenne[" << i << "]= " << mean[i] << endl;
|
---|
70 | }
|
---|
71 | return;
|
---|
72 | }
|
---|
73 |
|
---|
74 | int main(int narg, char *arg[])
|
---|
75 | {
|
---|
76 | if (narg < 3) {
|
---|
77 | cout << " tstdtable/Erreur: arguments manquants \n"
|
---|
78 | << " Usage: tstdtable r/w filename [mem/swap] [Nlines] [segsize]\n"
|
---|
79 | << " r : lecture depuis filename - calcule moyenne \n"
|
---|
80 | << " w : creation / ecriture ds filename \n"
|
---|
81 | << " NLines: Nombre de lignes de la table si w (defaut=10^6) \n"
|
---|
82 | << " mem: Utilisation de DataTable (memoire) \n"
|
---|
83 | << " swap: Utilisation de SwPPFDataTable (swap sur PPF) \n"
|
---|
84 | << " segsize: Taille de segment (defaut=1024) \n"
|
---|
85 | << endl;
|
---|
86 | return 1;
|
---|
87 | }
|
---|
88 |
|
---|
89 | try {
|
---|
90 | SophyaInit();
|
---|
91 | char oper = *arg[1];
|
---|
92 | string fname = arg[2];
|
---|
93 | sa_size_t nlines = 1000000;
|
---|
94 | sa_size_t segsize = 1024;
|
---|
95 | string msw = "mem";
|
---|
96 | if (narg > 3) msw = arg[3];
|
---|
97 | if (narg > 4) nlines = atol(arg[4]);
|
---|
98 | if (narg > 5) segsize = atol(arg[5]);
|
---|
99 | cout << "======== tstdtable: DataTable/G.Barrand test de performance I/O ========" << endl;
|
---|
100 | cout << " Operation= " << oper << " FileName= " << fname
|
---|
101 | << " (NLines= " << nlines << " Mem/Swap= " << msw << " )" << endl;
|
---|
102 | //---------- Creation , ecriture table
|
---|
103 | if (oper == 'w') {
|
---|
104 | if (msw == "mem") {
|
---|
105 | Timer tm("DTable:Mem/W");
|
---|
106 | cout << "1/ tstdtable/Info: Creation/Ecriture DataTable (memoire) " << endl;
|
---|
107 | DataTable dt(segsize);
|
---|
108 | cre_rempli_table(dt, nlines);
|
---|
109 | tm.Split("Mem/W:Fin-Remplissage");
|
---|
110 | cout << "2/ tstdtable/Info: Ecriture DataTable ds " << fname << endl;
|
---|
111 | POutPersist so(fname);
|
---|
112 | so << dt;
|
---|
113 | tm.Split("Mem/W:Fin-PPFWrite");
|
---|
114 | }
|
---|
115 | else {
|
---|
116 | Timer tm("DTable:Swap/W");
|
---|
117 | cout << "1/ tstdtable/Info: Creation/Ecriture DataTable (PPFSwap) " << endl;
|
---|
118 | POutPersist so(fname);
|
---|
119 | SwPPFDataTable dt(so, segsize);
|
---|
120 | cre_rempli_table(dt, nlines);
|
---|
121 | tm.Split("Swap/W:Fin-Remplissage");
|
---|
122 | cout << "2/ tstdtable/Info: Ecriture DataTable ds " << fname << endl;
|
---|
123 | so << dt;
|
---|
124 | tm.Split("Mem/W:Fin-Ecriture");
|
---|
125 | }
|
---|
126 | }
|
---|
127 | //---------- Lecture/verification table
|
---|
128 | else {
|
---|
129 | if (msw == "mem") {
|
---|
130 | Timer tm("DTable:Mem/R");
|
---|
131 | cout << "1/ tstdtable/Info: Lecture DataTable (memoire) de " << fname << endl;
|
---|
132 | DataTable dt;
|
---|
133 | PInPersist si(fname);
|
---|
134 | si >> dt;
|
---|
135 | tm.Split("Mem/R:Fin-PPFRead");
|
---|
136 | cout << "2/ tstdtable/Info: Lecture/verification table " << endl;
|
---|
137 | lit_ck_table(dt);
|
---|
138 | tm.Split("Mem/R:Fin-CheckLecture");
|
---|
139 | }
|
---|
140 | else {
|
---|
141 | Timer tm("DTable:Swap/R");
|
---|
142 | cout << "1/ tstdtable/Info: Lecture DataTable (swap) de " << fname << endl;
|
---|
143 | SwPPFDataTable dt;
|
---|
144 | PInPersist si(fname);
|
---|
145 | si >> dt;
|
---|
146 | tm.Split("Swap/R:Fin-PPFRead");
|
---|
147 | cout << "2/ tstdtable/Info: Lecture/verification table " << endl;
|
---|
148 | lit_ck_table(dt);
|
---|
149 | tm.Split("Swap/R:Fin-CheckLecture");
|
---|
150 | }
|
---|
151 | }
|
---|
152 |
|
---|
153 | }
|
---|
154 | catch(PThrowable& exc ) {
|
---|
155 | cerr << "tstdtable-main() , Catched exception: \n" << exc.Msg() << endl;
|
---|
156 | }
|
---|
157 | catch(std::exception& ex) {
|
---|
158 | cerr << "tstdtable-main() , Catched exception ! " << (string)(ex.what()) << endl;
|
---|
159 | }
|
---|
160 | catch(...) {
|
---|
161 | cerr << "tstdtable-main() , Catched ... ! " << endl;
|
---|
162 | }
|
---|
163 | cout << "============== tstdtable: DataTable =================" << endl;
|
---|
164 | return 0;
|
---|
165 | }
|
---|