The HPDS2 Procedure

Example 7.2 Aggregate Result Data Set

This example illustrates how the intermediate result data that are generated from the DS2 code running in parallel on separate grid nodes can be aggregated into a final result data set. In this case, the aggregation is done by a second-stage PROC DS2 program that executes on the SAS client.

This example uses a DATA step program that runs on the SAS client to generate a sample data set that consists of dimensional information for each of 200 objects (closed cylinders). These data are used by the HPDS2 procedure to calculate the volume and surface area of each object. The second-stage DS2 procedure aggregates these results, summing the total volume and surface area for all objects and computing the average volume and surface area. In this example, the DS2 code running in parallel on the grid is used to perform the row-independent and computationally intensive portion of the processing, whereas the work done by the second-stage DS2 procedure is limited to the final result aggregation and summary.

libname applianc &ENGINE
        server = "&GRIDDATASERVER"
        user   = &USER 
        password = &PASSWORD 
        database = &DATABASE;

data obj_dims;
   do id=1 to 200;
      radius = ranuni(1) * 10;
      height = ranuni(1) * 20;
      output;
   end;
run;

%let pi=3.14159;
proc hpds2 data=obj_dims
           out=applianc.obj_comps;
   performance host="&GRIDHOST" install="&GRIDINSTALLLOC";
   data DS2GTF.out;
      method run();
         set DS2GTF.in;
         volume = &pi * radius**2 * height;
         area = (2 * &pi * radius**2) + (2 * &pi * radius * height);
      end;
   enddata;
run;
proc print data=applianc.obj_comps (obs=20);
   title1 'Volumes and Areas';
run;
data obj_comps;
   set applianc.obj_comps;
run;
proc ds2;
   data obj_totals (keep = (ncount vsum asum vmean amean));
      dcl double ncount vsum asum vmean amean;
      method init();
         ncount = 0;
         vsum = 0;
         asum = 0;
      end;
      method run();
         set {select volume, area from obj_comps};
         ncount + 1;
         vsum + volume;
         asum + area;
      end;
      method term();
         if ncount ne 0 then do;
            vmean = vsum/ncount;
            amean = asum/ncount;
         end;
         output;
      end;
   enddata;
run;
quit;
proc print data=obj_totals;
   title1 'Total Volume and Area';
run;

Output 7.2.1 shows a subset of the volumes and areas that are computed by the HPDS2 procedure.

Output 7.2.1: Computed Volumes and Areas

Volumes and Areas

Obs id radius height volume area
1 1 1.8496256982 19.401774313 208.53 246.97
2 2 3.9982430609 5.1879729075 260.55 230.77
3 3 9.2160257787 19.385546995 5172.67 1656.20
4 4 5.4297917315 10.633834456 984.93 548.03
5 5 0.4979402621 1.331331032 1.04 5.72
6 6 8.1931857058 10.477410429 2209.58 961.15
7 7 8.5339431085 1.3436915359 307.43 529.64
8 8 9.5702385761 5.943879283 1710.27 932.89
9 9 2.7261178907 13.798592619 322.16 283.05
10 10 9.7676486241 4.5301503709 1357.82 877.48
11 11 6.8823655028 8.2552773264 1228.45 654.60
12 12 5.5855411271 5.7445122142 563.03 397.63
13 13 4.7578930504 16.89973954 1201.87 647.45
14 14 6.3452411845 11.807293385 1493.47 723.71
15 15 5.8258152641 7.5402673835 803.99 489.26
16 16 7.2836155991 10.132070589 1688.66 797.02
17 17 9.3121359401 18.582400996 5062.32 1632.10
18 18 5.8966033794 5.9444569265 649.33 438.70
19 19 3.910424334 9.4485835123 453.90 328.23
20 20 6.7952574821 3.3617670198 487.67 433.66



Output 7.2.2 shows the aggregated results that are produced by the second-stage DS2 program.

Output 7.2.2: Computed Total Volume and Area

Total Volume and Area

Obs ncount vsum asum vmean amean
1 200 209883.99 104680.26 1049.42 523.401