TMODEL Procedure
Example 39.1 Thread Allocation Using the Performance Statement
(View the complete code for this example.)
This example illustrates how you can use the PERFORMANCE statement to improve the performance of parameter estimation for a data set that contains multiple BY groups. For clarity, a small data set and a simple model are used. In practice, the benefits of configuring the thread allocation strategy are realized only for larger data sets and more computationally demanding models.
In the following PROC TMODEL step, a linear model is estimated for 20 BY groups, each of which contains 1,001 observations:
data d;
call streaminit(1);
do iby = 1 to 2;
do jby = 1 to 10;
do x = -500 to 500;
y = 2*x + 1 + rand('normal');
output;
end;
end;
end;
run;
proc tmodel data=d;
performance nthreads=4 bypriority=1 partpriority=1 / threadconfig timings;
y = a*x + b;
by iby jby;
fit y;
quit;
In this example, PROC TMODEL performs the estimations in two concurrent threads, where each thread performs the estimation for 10 BY groups. Also, within the estimation of each BY group, the 1,001 observations are processed concurrently in two partitions, one with 501 observations and the other with 500 observations. Output 39.1.1 shows how PROC TMODEL divides this estimation problem into threads and the time it takes to complete all 20 estimations.
Output 39.1.1: Multithreading Performance for Two BY-Group Threads
| Multithreading Configuration | ||
|---|---|---|
| Calculation Type | Concurrency Factor | Priority |
| BY Group Processing | 2 | 1.00 |
| Nonlinear Optimization | 1 | 0 |
| Data Partitioning | 2 | 1.00 |
| Performance Summary | |
|---|---|
| Threads Used | 4 |
| Task Time (sec) | 6.786222 |
| Program Run Time (sec) | 0.352537 |
| Data Time (sec) | 0.331969 |
Another way to perform these estimation tasks is to divide the 20 BY groups into four concurrent threads, where the estimation of each BY group is performed on a single partition that contains all 1,001 observations. You can do this by setting the PARTPRIORITY= option to 0 in the following PERFORMANCE statement:
proc tmodel data=d;
performance nthreads=4 bypriority=1 partpriority=0 / threadconfig timings;
y = a*x + b;
by iby jby;
fit y;
quit;
Output 39.1.2 shows that maximizing the number of BY-group threads improves the performance of this model and data set.
Output 39.1.2: Multithreading Performance for Four BY-Group Threads
| Multithreading Configuration | ||
|---|---|---|
| Calculation Type | Concurrency Factor | Priority |
| BY Group Processing | 4 | 1.00 |
| Nonlinear Optimization | 1 | 0 |
| Data Partitioning | 1 | 0 |
| Performance Summary | |
|---|---|
| Threads Used | 4 |
| Task Time (sec) | 5.798113 |
| Program Run Time (sec) | 0.372177 |
| Data Time (sec) | 0.359323 |