| 1 | /*
|
|---|
| 2 | !-------------------------------------------------------------------------!
|
|---|
| 3 | ! !
|
|---|
| 4 | ! N A S P A R A L L E L B E N C H M A R K S 3.3 !
|
|---|
| 5 | ! !
|
|---|
| 6 | ! O p e n M P V E R S I O N !
|
|---|
| 7 | ! !
|
|---|
| 8 | ! D C !
|
|---|
| 9 | ! !
|
|---|
| 10 | !-------------------------------------------------------------------------!
|
|---|
| 11 | ! !
|
|---|
| 12 | ! DC creates all specifided data-cube views in parallel. !
|
|---|
| 13 | ! Refer to NAS Technical Report 03-005 for details. !
|
|---|
| 14 | ! It calculates all groupbys in a top down manner using well known !
|
|---|
| 15 | ! heuristics and optimizations. !
|
|---|
| 16 | ! !
|
|---|
| 17 | ! Permission to use, copy, distribute and modify this software !
|
|---|
| 18 | ! for any purpose with or without fee is hereby granted. We !
|
|---|
| 19 | ! request, however, that all derived work reference the NAS !
|
|---|
| 20 | ! Parallel Benchmarks 3.3. This software is provided "as is" !
|
|---|
| 21 | ! without express or implied warranty. !
|
|---|
| 22 | ! !
|
|---|
| 23 | ! Information on NPB 3.3, including the technical report, the !
|
|---|
| 24 | ! original specifications, source code, results and information !
|
|---|
| 25 | ! on how to submit new results, is available at: !
|
|---|
| 26 | ! !
|
|---|
| 27 | ! http://www.nas.nasa.gov/Software/NPB/ !
|
|---|
| 28 | ! !
|
|---|
| 29 | ! Send comments or suggestions to npb@nas.nasa.gov !
|
|---|
| 30 | ! !
|
|---|
| 31 | ! NAS Parallel Benchmarks Group !
|
|---|
| 32 | ! NASA Ames Research Center !
|
|---|
| 33 | ! Mail Stop: T27A-1 !
|
|---|
| 34 | ! Moffett Field, CA 94035-1000 !
|
|---|
| 35 | ! !
|
|---|
| 36 | ! E-mail: npb@nas.nasa.gov !
|
|---|
| 37 | ! Fax: (650) 604-3957 !
|
|---|
| 38 | ! !
|
|---|
| 39 | !-------------------------------------------------------------------------!
|
|---|
| 40 | ! Author: Michael Frumkin !
|
|---|
| 41 | ! Leonid Shabanov !
|
|---|
| 42 | !-------------------------------------------------------------------------!
|
|---|
| 43 | */
|
|---|
| 44 |
|
|---|
| 45 | #include <stdio.h>
|
|---|
| 46 | #include <stdlib.h>
|
|---|
| 47 | #include <string.h>
|
|---|
| 48 | #include <errno.h>
|
|---|
| 49 | #include <ctype.h>
|
|---|
| 50 | #include <math.h>
|
|---|
| 51 |
|
|---|
| 52 | #ifdef _OPENMP
|
|---|
| 53 | #include <omp.h>
|
|---|
| 54 | #endif
|
|---|
| 55 |
|
|---|
| 56 |
|
|---|
| 57 | #include "adc.h"
|
|---|
| 58 | #include "macrodef.h"
|
|---|
| 59 | #include "npbparams.h"
|
|---|
| 60 |
|
|---|
| 61 | #ifdef UNIX
|
|---|
| 62 | /*
|
|---|
| 63 | #include <sys/types.h>
|
|---|
| 64 | */
|
|---|
| 65 | #include <unistd.h>
|
|---|
| 66 |
|
|---|
| 67 | #define MAX_TIMERS 64 /* NPB maximum timers */
|
|---|
| 68 | void timer_clear(int);
|
|---|
| 69 | void timer_start(int);
|
|---|
| 70 | void timer_stop(int);
|
|---|
| 71 | double timer_read(int);
|
|---|
| 72 | #endif
|
|---|
| 73 |
|
|---|
| 74 | /*
|
|---|
| 75 | void c_print_results( char *name,
|
|---|
| 76 | char clss,
|
|---|
| 77 | int n1,
|
|---|
| 78 | int n2,
|
|---|
| 79 | int n3,
|
|---|
| 80 | int niter,
|
|---|
| 81 | double t,
|
|---|
| 82 | double mops,
|
|---|
| 83 | char *optype,
|
|---|
| 84 | int passed_verification,
|
|---|
| 85 | char *npbversion,
|
|---|
| 86 | char *compiletime,
|
|---|
| 87 | char *cc,
|
|---|
| 88 | char *clink,
|
|---|
| 89 | char *c_lib,
|
|---|
| 90 | char *c_inc,
|
|---|
| 91 | char *cflags,
|
|---|
| 92 | char *clinkflags );
|
|---|
| 93 | */
|
|---|
| 94 |
|
|---|
| 95 | void initADCpar(ADC_PAR *par);
|
|---|
| 96 | int ParseParFile(char* parfname, ADC_PAR *par);
|
|---|
| 97 | int GenerateADC(ADC_PAR *par);
|
|---|
| 98 | void ShowADCPar(ADC_PAR *par);
|
|---|
| 99 | int32 DC(ADC_VIEW_PARS *adcpp);
|
|---|
| 100 | int Verify(long long int checksum,ADC_VIEW_PARS *adcpp);
|
|---|
| 101 |
|
|---|
| 102 | #define BlockSize 1024
|
|---|
| 103 |
|
|---|
| 104 | int main ( int argc, char * argv[] )
|
|---|
| 105 | {
|
|---|
| 106 | ADC_PAR *parp;
|
|---|
| 107 | ADC_VIEW_PARS *adcpp;
|
|---|
| 108 | int32 retCode;
|
|---|
| 109 |
|
|---|
| 110 | fprintf(stdout,"\n\n NAS Parallel Benchmarks (NPB3.3-OMP) - DC Benchmark\n\n" );
|
|---|
| 111 | if(argc!=3){
|
|---|
| 112 | fprintf(stdout," No Paramter file. Using compiled defaults\n");
|
|---|
| 113 | }
|
|---|
| 114 | if(argc>3 || (argc>1 && !isdigit(argv[1][0]))){
|
|---|
| 115 | fprintf(stderr,"Usage: <program name> <amount of memory>\n");
|
|---|
| 116 | fprintf(stderr," <file of parameters>\n");
|
|---|
| 117 | fprintf(stderr,"Example: bin/dc.S 1000000 DC/ADC.par\n");
|
|---|
| 118 | fprintf(stderr,"The last argument, (a parameter file) can be skipped\n");
|
|---|
| 119 | exit(1);
|
|---|
| 120 | }
|
|---|
| 121 |
|
|---|
| 122 | if( !(parp = (ADC_PAR*) malloc(sizeof(ADC_PAR)))
|
|---|
| 123 | ||!(adcpp = (ADC_VIEW_PARS*) malloc(sizeof(ADC_VIEW_PARS)))){
|
|---|
| 124 | PutErrMsg("main: malloc failed")
|
|---|
| 125 | exit(1);
|
|---|
| 126 | }
|
|---|
| 127 | initADCpar(parp);
|
|---|
| 128 | parp->clss=CLASS;
|
|---|
| 129 | if(argc!=3){
|
|---|
| 130 | parp->dim=attrnum;
|
|---|
| 131 | parp->tuplenum=input_tuples;
|
|---|
| 132 | }else if( (argc==3)&&(!ParseParFile(argv[2], parp))) {
|
|---|
| 133 | PutErrMsg("main.ParseParFile failed")
|
|---|
| 134 | exit(1);
|
|---|
| 135 | }
|
|---|
| 136 | ShowADCPar(parp);
|
|---|
| 137 | if(!GenerateADC(parp)) {
|
|---|
| 138 | PutErrMsg("main.GenerateAdc failed")
|
|---|
| 139 | exit(1);
|
|---|
| 140 | }
|
|---|
| 141 |
|
|---|
| 142 | adcpp->ndid = parp->ndid;
|
|---|
| 143 | adcpp->clss = parp->clss;
|
|---|
| 144 | adcpp->nd = parp->dim;
|
|---|
| 145 | adcpp->nm = parp->mnum;
|
|---|
| 146 | adcpp->nTasks = 1;
|
|---|
| 147 |
|
|---|
| 148 | if(argc>=2)
|
|---|
| 149 | adcpp->memoryLimit = atoi(argv[1]);
|
|---|
| 150 | else
|
|---|
| 151 | adcpp->memoryLimit = 0;
|
|---|
| 152 | if(adcpp->memoryLimit <= 0){
|
|---|
| 153 | /* size of rb-tree with tuplenum nodes */
|
|---|
| 154 | adcpp->memoryLimit = parp->tuplenum*(50+5*parp->dim);
|
|---|
| 155 | fprintf(stdout,"Estimated rb-tree size = %d \n", adcpp->memoryLimit);
|
|---|
| 156 | }
|
|---|
| 157 | adcpp->nInputRecs = parp->tuplenum;
|
|---|
| 158 | strcpy(adcpp->adcName, parp->filename);
|
|---|
| 159 | strcpy(adcpp->adcInpFileName, parp->filename);
|
|---|
| 160 |
|
|---|
| 161 | if((retCode=DC(adcpp))) {
|
|---|
| 162 | PutErrMsg("main.DC failed")
|
|---|
| 163 | fprintf(stderr, "main.ParRun failed: retcode = %d\n", retCode);
|
|---|
| 164 | exit(1);
|
|---|
| 165 | }
|
|---|
| 166 |
|
|---|
| 167 | if(parp) { free(parp); parp = 0; }
|
|---|
| 168 | if(adcpp) { free(adcpp); adcpp = 0; }
|
|---|
| 169 | return 0;
|
|---|
| 170 | }
|
|---|
| 171 |
|
|---|
| 172 | int32 CloseAdcView(ADC_VIEW_CNTL *adccntl);
|
|---|
| 173 | int32 PartitionCube(ADC_VIEW_CNTL *avp);
|
|---|
| 174 | ADC_VIEW_CNTL *NewAdcViewCntl(ADC_VIEW_PARS *adcpp, uint32 pnum);
|
|---|
| 175 | int32 ComputeGivenGroupbys(ADC_VIEW_CNTL *adccntl);
|
|---|
| 176 |
|
|---|
| 177 | int32 DC(ADC_VIEW_PARS *adcpp) {
|
|---|
| 178 | int32 itsk=0;
|
|---|
| 179 | double t_total=0.0;
|
|---|
| 180 | int verified;
|
|---|
| 181 |
|
|---|
| 182 | typedef struct {
|
|---|
| 183 | int verificationFailed;
|
|---|
| 184 | uint32 totalViewTuples;
|
|---|
| 185 | uint64 totalViewSizesInBytes;
|
|---|
| 186 | uint32 totalNumberOfMadeViews;
|
|---|
| 187 | uint64 checksum;
|
|---|
| 188 | double tm_max;
|
|---|
| 189 | } PAR_VIEW_ST;
|
|---|
| 190 |
|
|---|
| 191 | PAR_VIEW_ST *pvstp;
|
|---|
| 192 |
|
|---|
| 193 | pvstp = (PAR_VIEW_ST*) malloc(sizeof(PAR_VIEW_ST));
|
|---|
| 194 | pvstp->verificationFailed = 0;
|
|---|
| 195 | pvstp->totalViewTuples = 0;
|
|---|
| 196 | pvstp->totalViewSizesInBytes = 0;
|
|---|
| 197 | pvstp->totalNumberOfMadeViews = 0;
|
|---|
| 198 | pvstp->checksum = 0;
|
|---|
| 199 |
|
|---|
| 200 | #ifdef _OPENMP
|
|---|
| 201 | adcpp->nTasks=omp_get_max_threads();
|
|---|
| 202 | fprintf(stdout,"\nNumber of available threads: %d\n", adcpp->nTasks);
|
|---|
| 203 | if (adcpp->nTasks > MAX_NUMBER_OF_TASKS) {
|
|---|
| 204 | adcpp->nTasks = MAX_NUMBER_OF_TASKS;
|
|---|
| 205 | fprintf(stdout,"Warning: Maximum number of tasks reached: %d\n",
|
|---|
| 206 | adcpp->nTasks);
|
|---|
| 207 | }
|
|---|
| 208 | #pragma omp parallel shared(pvstp) private(itsk)
|
|---|
| 209 | #endif
|
|---|
| 210 | {
|
|---|
| 211 | double tm0=0;
|
|---|
| 212 | int itimer=0;
|
|---|
| 213 | ADC_VIEW_CNTL *adccntlp;
|
|---|
| 214 | #ifdef _OPENMP
|
|---|
| 215 | itsk=omp_get_thread_num();
|
|---|
| 216 | #endif
|
|---|
| 217 | adccntlp = NewAdcViewCntl(adcpp, itsk);
|
|---|
| 218 |
|
|---|
| 219 | if (!adccntlp) {
|
|---|
| 220 | PutErrMsg("ParRun.NewAdcViewCntl: returned NULL")
|
|---|
| 221 | adccntlp->verificationFailed=1;
|
|---|
| 222 | }else{
|
|---|
| 223 | adccntlp->verificationFailed = 0;
|
|---|
| 224 | if (adccntlp->retCode!=0) {
|
|---|
| 225 | fprintf(stderr,
|
|---|
| 226 | "DC.NewAdcViewCntl: return code = %d\n",
|
|---|
| 227 | adccntlp->retCode);
|
|---|
| 228 | }
|
|---|
| 229 | }
|
|---|
| 230 |
|
|---|
| 231 | if (!adccntlp->verificationFailed) {
|
|---|
| 232 | if( PartitionCube(adccntlp) ) {
|
|---|
| 233 | PutErrMsg("DC.PartitionCube failed");
|
|---|
| 234 | }
|
|---|
| 235 | timer_clear(itimer);
|
|---|
| 236 | timer_start(itimer);
|
|---|
| 237 | if( ComputeGivenGroupbys(adccntlp) ) {
|
|---|
| 238 | PutErrMsg("DC.ComputeGivenGroupbys failed");
|
|---|
| 239 | }
|
|---|
| 240 | timer_stop(itimer);
|
|---|
| 241 | tm0 = timer_read(itimer);
|
|---|
| 242 | }
|
|---|
| 243 | #ifdef _OPENMP
|
|---|
| 244 | #pragma omp critical
|
|---|
| 245 | #endif
|
|---|
| 246 | {
|
|---|
| 247 | if(pvstp->tm_max<tm0) pvstp->tm_max=tm0;
|
|---|
| 248 | pvstp->verificationFailed += adccntlp->verificationFailed;
|
|---|
| 249 | if (!adccntlp->verificationFailed) {
|
|---|
| 250 | pvstp->totalNumberOfMadeViews += adccntlp->numberOfMadeViews;
|
|---|
| 251 | pvstp->totalViewSizesInBytes += adccntlp->totalViewFileSize;
|
|---|
| 252 | pvstp->totalViewTuples += adccntlp->totalOfViewRows;
|
|---|
| 253 | pvstp->checksum += adccntlp->totchs[0];
|
|---|
| 254 | }
|
|---|
| 255 | }
|
|---|
| 256 | if(CloseAdcView(adccntlp)) {
|
|---|
| 257 | PutErrMsg("ParRun.CloseAdcView: is failed");
|
|---|
| 258 | adccntlp->verificationFailed = 1;
|
|---|
| 259 | }
|
|---|
| 260 | } /* omp parallel */
|
|---|
| 261 |
|
|---|
| 262 | t_total=pvstp->tm_max;
|
|---|
| 263 |
|
|---|
| 264 | pvstp->verificationFailed=Verify(pvstp->checksum,adcpp);
|
|---|
| 265 | verified = (pvstp->verificationFailed == -1)? -1 :
|
|---|
| 266 | (pvstp->verificationFailed == 0)? 1 : 0;
|
|---|
| 267 |
|
|---|
| 268 | fprintf(stdout,"\n*** DC Benchmark Results:\n");
|
|---|
| 269 | fprintf(stdout," Benchmark Time = %20.3f\n", t_total);
|
|---|
| 270 | fprintf(stdout," Input Tuples = %12d\n", (int) adcpp->nInputRecs);
|
|---|
| 271 | fprintf(stdout," Number of Views = %12d\n",
|
|---|
| 272 | (int) pvstp->totalNumberOfMadeViews);
|
|---|
| 273 | fprintf(stdout," Number of Tasks = %12d\n", (int) adcpp->nTasks);
|
|---|
| 274 | fprintf(stdout," Tuples Generated = %20.0f\n",
|
|---|
| 275 | (double) pvstp->totalViewTuples);
|
|---|
| 276 | fprintf(stdout," Tuples/s = %20.2f\n",
|
|---|
| 277 | (double) pvstp->totalViewTuples / t_total);
|
|---|
| 278 | fprintf(stdout," Checksum = %20.12e\n", (double) pvstp->checksum);
|
|---|
| 279 | if (pvstp->verificationFailed)
|
|---|
| 280 | fprintf(stdout, " Verification failed\n");
|
|---|
| 281 |
|
|---|
| 282 | /*
|
|---|
| 283 | c_print_results("DC",
|
|---|
| 284 | adcpp->clss,
|
|---|
| 285 | (int)adcpp->nInputRecs,
|
|---|
| 286 | 0,
|
|---|
| 287 | 0,
|
|---|
| 288 | 1,
|
|---|
| 289 | t_total,
|
|---|
| 290 | (double) pvstp->totalViewTuples * 1.e-6 / t_total,
|
|---|
| 291 | "Tuples generated",
|
|---|
| 292 | verified,
|
|---|
| 293 | NPBVERSION,
|
|---|
| 294 | COMPILETIME,
|
|---|
| 295 | CC,
|
|---|
| 296 | CLINK,
|
|---|
| 297 | C_LIB,
|
|---|
| 298 | C_INC,
|
|---|
| 299 | CFLAGS,
|
|---|
| 300 | CLINKFLAGS);
|
|---|
| 301 | */
|
|---|
| 302 | return ADC_OK;
|
|---|
| 303 | }
|
|---|
| 304 |
|
|---|
| 305 | long long checksumS=464620213;
|
|---|
| 306 | long long checksumWlo=434318;
|
|---|
| 307 | long long checksumWhi=1401796;
|
|---|
| 308 | long long checksumAlo=178042;
|
|---|
| 309 | long long checksumAhi=7141688;
|
|---|
| 310 | long long checksumBlo=700453;
|
|---|
| 311 | long long checksumBhi=9348365;
|
|---|
| 312 |
|
|---|
| 313 | int Verify(long long int checksum,ADC_VIEW_PARS *adcpp){
|
|---|
| 314 | switch(adcpp->clss){
|
|---|
| 315 | case 'S':
|
|---|
| 316 | if(checksum==checksumS) return 0;
|
|---|
| 317 | break;
|
|---|
| 318 | case 'W':
|
|---|
| 319 | if(checksum==checksumWlo+1000000*checksumWhi) return 0;
|
|---|
| 320 | break;
|
|---|
| 321 | case 'A':
|
|---|
| 322 | if(checksum==checksumAlo+1000000*checksumAhi) return 0;
|
|---|
| 323 | break;
|
|---|
| 324 | case 'B':
|
|---|
| 325 | if(checksum==checksumBlo+1000000*checksumBhi) return 0;
|
|---|
| 326 | break;
|
|---|
| 327 | default:
|
|---|
| 328 | return -1; /* CLASS U */
|
|---|
| 329 | }
|
|---|
| 330 | return 1;
|
|---|
| 331 | }
|
|---|
| 332 |
|
|---|