Multithreaded = more productive


When I write SAS/IML programs, I usually do my development in the SAS/IML Studio environment. Why? There are many reasons, but the one that I will discuss today is the fact that the application is multithreaded and supports multiple programming workspaces.

The advantages of multiple programming workspaces

I am always multitasking, which means that usually I am writing and running multiple programs that are in various stages of completion. For example, today I am working on three projects: a program for my blog (ContaminatedNormal), a customer's program that I am trying to analyze for SAS Technical Support (TechSupportG01832), and a program that I am writing for an upcoming presentation (7_MVNormal). When I am working on my upcoming presentation, my SAS/IML Studio environment might look like the following:

In the image, I drew a red ellipse on the workspace bar, which shows that there are three workspaces. The following image is a close-up of the workspace bar:

The names of the programs appear on the buttons on the workspace bar, and I can switch to a different program by clicking a button.

Each workspace is a separate SAS/IML programming environment. It has its own program window and an independent WORK library for storing temporary data sets. Each program runs independently: a variable named x in one program has no relationship to a variable of the same name in a different program. Consequently, I can develop many SAS/IML programs simultaneously.

The advantages of a multithreaded application

Even more useful is that I can run multiple programs simultaneously! Because the SAS/IML application is multithreaded, I can run arbitrarily many SAS/IML programs concurrently (but there is only one SAS process). This is great if I am running a simulation that requires several minutes to complete. I can run the simulation in one programming workspace and then switch to a different workspace to work on a different program.

For example, suppose that I am hard at work when I get a phone call. The caller asks if I can come up to his office in ten minutes. No problem. I immediately open a prewritten program called Alarm and run it in SAS/IML Studio. I then switch to the Technical Support issue and start working on that program. My workspace bar looks like the following:

The blue triangle on the Alarm button lets me know that the program is running in a separate thread, even while I investigate the Technical Support issue. (If I have access to several SAS servers, I can even tell SAS/IML Studio to run programs on a remote server.) After ten minutes, the Alarm program finishes running and makes a beeping sounds that reminds me of my appointment.

Notice that a multithreaded interface does not imply that the computations are multithreaded. However, SAS also provides multithreaded computations in Base SAS procedures (Ray, 2003) and in analytical procedures (Cohen, 2002).

A SAS/IML program that sounds an alarm

A blog post that doesn't contain any code is so unsatisfying, so here is my SAS/IML program that beeps after a specified length of time. You can run this program in SAS/IML Studio, then switch to a new workspace and continue your work:

/* Demonstrate that SAS/IML Studio is multithreaded */
/* no "proc iml" statement; run in SAS/IML Studio */
delay = 10; /* specify time in minutes (use 1/12 to demo program) */
AlarmTime = time()+60*delay;
print "Alarm will ring at " AlarmTime[format=time9.];
printnow; /* force printing to happen immediately */
/* pause for this many seconds */
call sleep(60*delay, 1); 
/* Time sound the alarm */
tone = repeat(do(400,800,50), 3);
call sound(tone, 0.05);

About Author

Rick Wicklin

Distinguished Researcher in Computational Statistics

Rick Wicklin, PhD, is a distinguished researcher in computational statistics at SAS and is a principal developer of SAS/IML software. His areas of expertise include computational statistics, simulation, statistical graphics, and modern methods in statistical data analysis. Rick is author of the books Statistical Programming with SAS/IML Software and Simulating Data with SAS.

1 Comment

  1. Pingback: Ten tips for learning the SAS/IML language - The DO Loop

Leave A Reply

Back to Top