1 #include <stdio.h>
2 #include "../../IV.h"
3 #include "../../Utilities.h"
4 #include "../../timings.h"
5 
6 /*--------------------------------------------------------------------*/
7 /*
8    ---------------------------------------------------------------
9    this program tries to get some idea of the malloc()/free()
10    characteristics of a machine and operating system. it was
11    written to try and understand the initialization times for
12    the FrontMtx object for the i4a matrix with 99192 rows and
13    columns.
14 
15    the program reads in a vector that contains the byte counts
16    for the factor submatrices. depending on the input parameters,
17    the program allocates the storage and then free'ing the storage.
18 
19    zeroflag --
20           0     --> do not zero the storage
21       otherwise --> zero the storage
22    sortflag --
23           0     --> do not sort the byte counts in ascending order
24       otherwise --> sort the byte counts in ascending order
25 
26    created -- 98sep05, cca
27    ---------------------------------------------------------------
28 */
29 int
main(int argc,char * argv[])30 main ( int argc, char *argv[] ) {
31 double   t1, t2 ;
32 double   *dvec ;
33 double   **pdvecs ;
34 int      item, nitem, sortflag, sum, zeroflag ;
35 int      *nbytes ;
36 IV       *nbytesIV ;
37 
38 if ( argc != 3 ) {
39    fprintf(stdout, "\n usage : a.out zeroflag sortflag ") ;
40    return(1) ;
41 }
42 zeroflag = atoi(argv[1]) ;
43 sortflag = atoi(argv[2]) ;
44 if ( zeroflag == 0 ) {
45    fprintf(stdout, "\n storage not zero'd") ;
46 } else {
47    fprintf(stdout, "\n storage zero'd") ;
48 }
49 if ( sortflag == 0 ) {
50    fprintf(stdout, "\n byte counts not sorted") ;
51 } else {
52    fprintf(stdout, "\n byte counts sorted") ;
53 }
54 /*
55    -------------------------------------------------
56    read in the vector that contains the bytes counts
57    for the SubMtx objects from the i4a matrix
58    -------------------------------------------------
59 */
60 nbytesIV = IV_new() ;
61 IV_readFromFile(nbytesIV, "nbytes.ivf") ;
62 IV_sizeAndEntries(nbytesIV, &nitem, &nbytes) ;
63 sum = IV_sum(nbytesIV) ;
64 fprintf(stdout, "\n %d items read in, sum = %d",
65         nitem, sum) ;
66 fflush(stdout) ;
67 if ( sortflag != 0 ) {
68    IVqsortUp(nitem, nbytes) ;
69 }
70 /*
71    ------------------------------------
72    now time the malloc()'s and free()'s
73    ------------------------------------
74 */
75 pdvecs = PDVinit(nitem) ;
76 if ( zeroflag == 0 ) {
77    MARKTIME(t1) ;
78    for ( item = 0 ; item < nitem ; item++ ) {
79       pdvecs[item] = DVinit2(nbytes[item]/sizeof(double)) ;
80    }
81    MARKTIME(t2) ;
82    fprintf(stdout, "\n  CPU %10.5f for DVinit2", t2 - t1) ;
83 
84    MARKTIME(t1) ;
85    for ( item = 0 ; item < nitem ; item++ ) {
86       DVfree(pdvecs[item]) ;
87    }
88    MARKTIME(t2) ;
89    fprintf(stdout, "\n  CPU %10.5f for DVfree", t2 - t1) ;
90 } else {
91    MARKTIME(t1) ;
92    for ( item = 0 ; item < nitem ; item++ ) {
93       pdvecs[item] = DVinit(nbytes[item]/sizeof(double), 0.0) ;
94    }
95    MARKTIME(t2) ;
96    fprintf(stdout, "\n  CPU %10.5f for DVinit", t2 - t1) ;
97 
98    MARKTIME(t1) ;
99    for ( item = 0 ; item < nitem ; item++ ) {
100       DVfree(pdvecs[item]) ;
101    }
102    MARKTIME(t2) ;
103    fprintf(stdout, "\n  CPU %10.5f for DVfree", t2 - t1) ;
104 }
105 fprintf(stdout, "\n") ;
106 fflush(stdout) ;
107 return(1) ; }
108 
109 /*--------------------------------------------------------------------*/
110