Home > Articles > Programming > General Programming/Other Languages

Multicore Application Programming: An Interview with Darryl Gove

Jim Mauro interviews Darryl Gove, the author of Multicore Application Programming, about the joys of programming with threads and concurrency, the current state of multi-threaded application software, and the effectiveness of automatic parallelization technology.
Like this article? We recommend

Jim Mauro: Your expertise, your work and your published work explore application software performance and concurrency/threaded programming in great detail. Before we get into the joys of programming with threads and concurrency, how long have you been looking at application performance and optimizations, and is there anything in particular that moved you in that direction?

Darryl Gove: I joined Sun in 1999. My Ph.D. is in mathematical and simulation modeling of infectious diseases. When I joined Sun, the plan included me both spending time on modeling the performance of computers and improving the performance of applications on them. That never really worked out; I ended up having plenty to do on performance analysis.

Performance analysis and optimization happened to be something that I had always been interested in. Although I’ve done a fair amount of coding in various languages, I tend to be most comfortable looking at assembly language and understanding things at that level of abstraction. So the work I currently do on optimization, parallelization, and performance seems a very good fit for the kind of thing that I’m interested in.

Jim: We both know it’s really hard to write really good code, and very challenging to write scalable, threaded code. What is your view of the current state of multi-threaded application software, both in terms of what you see out there, and the APIs available for programmers to use?

Darryl: There’s an amazing transition going on. Looking back a few years, it was hard to get access to multiprocessor systems, so you had approaches like MPI, which distributed an application over multiple machines. You had POSIX threads, which gave you low level control over the parallelization that your application employed. You had OpenMP, which gave you a high level way of describing parallelism. Together with Windows threading, these still represent the prevalent approaches.

Today, if you look around you can see a wide range of alternatives. I find the CUDA/OpenCL approach of leveraging GPUs to be very interesting. Partly because I suspect it to be indicative of the future direction of the industry—many parallel cores—and partly because, for some situations, it can provide substantial gains over today’s technologies.

However, there’s not a single approach that has cracked the “make it easy to write parallel programs” problem. The two approaches that are the closest to this are automatic parallelization and OpenMP. Most of the other approaches have significant barrier to entry in terms of what can be achieved, or of what source code changes are necessary.

Jim: In my experience (and this likely seems pretty obvious) the biggest impediment to creating scalable, threaded applications is efficient use of synchronization primitives for locking—mutex locks, reader/write locks. What is your view on the state of tools available to help developers identify lock contention issues that impede scalability, and the state of published, available material for developers to reference to improve the lock granularity in their code? Are threaded applications overly cautious with the use of locks today, in your experience?

Darryl: Locks are one of the critical limiters to scaling. As you know, this is recognized in Solaris, and it has the Dtrace-based tools lockstat and plockstat that highlight lock hold times and contention. However, you can relatively easily pick up locking issues just by profiling the code. Of course the profile can be slightly hard to interpret, but the information is normally lurking there somewhere. That said, it is always possible to improve tools to make the problems more apparent.

Adding locks into code is something of a dark art. Scaling is typically improved by increasing the number of locks (i.e., reducing the granularity of each lock). But the cost of acquiring a particular lock typically increases as the number of locks increase. The alternative of using lock-free algorithms also has overheads, sometimes of performance, sometimes of implementation complexity. So there is not necessarily a “magic ratio” for locks to threads.

What you can expect to find is that an application will scale up to the number of cores that are present on the machine used to develop it. So long as using more cores leads to better performance, a developer will probably accept whatever scaling they get. However, as multicore processors with higher thread counts become available, we should expect (a) applications to show scaling issues and (b) developers to fix these scaling issues. So we’ll hit plenty of lock-induced scaling issues, but these will be fixed as machines with high thread count get more readily available.

Looking at the issue more broadly, poor scaling from lock contention is often relatively easy to diagnose. It is not necessarily that easy to fix, but knowing that the problem is there is the first step to solving it. There are other limitations to scaling that are less easy to diagnose and less easy to solve. Good examples of this are memory locality issues due to NUMA architectures or resource contention in shared processor pipelines. It can be hard to identify these problems, and it can be nearly impossible to provide a general solution for them.

Jim: That all aligns with my experience as well. To what extent did the availability of the atomic operations in Solaris (atomic_ops(3C)) help developers in terms of providing an alternative to the use of mutex locks for relatively simple variable operations? I have never actually measured the difference, but it seems using (for example) atomic_inc_[data_type]() would be far less expensive and more efficient than wrapping a mutex_lock()/mutex_unlock() call around a variable that multiple threads need to increment.

Darryl: The atomic operations were a fantastic addition to Solaris 10. As you point out, they can be much more efficient than a mutex lock. Obviously, atomic ops are only useful for manipulation of a single variable, incrementing it, decrementing it, or some other basic operation. They don’t work for more complex situations, for example where there are multiple variables being modified. What is nice, though, is that there are a number of situations where it is only the modification of a single variable that is needed. The obvious example is keeping an event counter.

If you squint at the code for a mutex lock and the code for an atomic operation, they are very similar—essentially try to do “this” until it works. For a mutex lock, the “this” is to acquire the lock; for an atomic operation it is to modify the variable. The performance gain from using atomic operations is because there is only a single memory address being accessed (no separate mutex variable). There’s also a gain because the atomic operations spin until it works, whereas mutexes have lots of features to handle contention—exponential backoff, sending waiting threads to sleep.

The other pleasing thing with the introduction of atomic operations into Solaris was that it brought the OS up to parity with other platforms. It seems a reasonable expectation that developers will have access to this kind of support. This makes sense. We should now expect most applications to be parallel, so we need low-cost intrinsics that can safely perform these kinds of data manipulation in multithreaded codes.

Jim: In your book, Multicore Application Programming, you dedicate a chapter to using automatic parallelization and OpenMP. In your experience, how effective is the automatic parallelization technology? Are compilers able to generate scalable, threaded programs?

Darryl: Well.... yes for some subset of applications, compilers can generate scalable, multithreaded versions. So when it works, it works well. However, it is really tricky for a compiler to do this in general. There are a number of problems. The most common is pointer aliasing, but other characteristics of the code, such as function calls, can also stop the compiler from automatically parallelizing loops.

The upshot is that automatic parallelization is often quite limited in scope. However, the compiler can usually give feedback as to what is stopping automatic parallelization, and this can enable the developer to change the code to make the compiler more effective.

This can build into a useful approach to parallelizing applications. The first pass is to get the compiler to do what it can, then tweak the source to help the compiler do a better job, before finally going in and manually adding OpenMP directives.

Jim: All modern microprocessors these days are multicore/multithread. That is, multiple threads-per-core. For most architectures, we see relatively small thread-per-core counts (2), and some variation in the underlying implementations (e.g., Intel hyperthreads versus UltraSPARC T-series), the latter of course having significantly more threads-per-core. Is writing multithreaded software for a modern multicore/multithread processor very different than it was several years ago, when systems had multiple CPUs, but a given “CPU” was a single-core, single-thread on a chip? Put another way, does the underlying target platform influence the design and implementation of multithreaded code?

Darryl: I think the question highlights the crux of the book. At first glance writing software for a multicore processor is no different from writing software for a multiprocessor system. The fundamental requirement is to identify chunks of work that can safely and efficiently be performed in parallel.

However, there are actually critical differences. The most obvious difference is that multiple threads on the same core end up sharing resources—instruction issue width and cache space being two obvious ones. This resource sharing may cause the throughput of a core running two threads to be only slightly more than the same core running one thread. This can be summarized whether it is better, for performance, to spread multiple threads across multiple cores to avoid sharing of core resources.

However, not all resource sharing is a problem. In the case of communication between threads, it is useful for the threads to share a common cache. This reduces communication costs and helps an application scale to higher numbers of threads. In this case it is better for an application to place its threads on one core, or multiple cores in close proximity.

The other benefit that comes with low communication costs is that some of the traditional scaling inhibitors—contended mutex locks, false sharing—are substantially diminished.

Consider false sharing. This is the situation where two threads need to write to different items of data that happen to reside on the same cache line. On a multiprocessor system this causes the cache line to migrate between processors. On a multicore processor this causes the cache line to remain resident in the shared cache. Cache latency can be, perhaps, ten times lower than memory latency, so the cost of sharing drops by a factor of ten. The consequence of this is that an application which has significant costs due to false sharing will get a significant performance gain on a multicore system.

An observation that goes with this is that the difficulty of writing scalable code also drops. A developer might end up with a data layout that has false sharing, or they might have fixed correctness issues by adding a number of mutexes. On a multicore processor there is little performance impact from these, so the application scales despite the issue.

Multicore processors are a great opportunity for developers. They have placed parallel application development at a much more accessible price point than multiprocessor systems. The are also a more forgiving platform than multiprocessor systems. The exciting thing is that we are very much in the infancy of this opportunity. There’s still a shift going on where people are figuring out how to best take advantage of multiple threads. So I think we’re going to be in for very interesting times.

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020