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