- Infos im HLRS Wiki sind nicht rechtsverbindlich und ohne Gewähr -

NEC Cluster NUMA Tuning

From HLRS Platforms
Revision as of 19:28, 25 November 2011 by Hwwnec5 (talk | contribs)
Jump to navigationJump to search

NUMA Tuning

The Nehalem architecture is the first intel platform following a NUMA (=non uniform memory access) design pattern. The memory controller is located within the CPU chip, and therefor, a system with two CPU sockets as the HLRS/NEC installation has two distinct memory controllers, each responsible for 1/2 of the memory.

To achieve maximum performance, this has to be taken into consideration, as data is best accessed by processes nearby the data - or in other words, for best performance, the data has to be distributed over the two memory controllers, or NUMA nodes, in a pattern that matches the accesses from the processes or thread.

The linux kernel us NUMA aware, and does it's best to place data at a good (=near) memory location. This is achieved by following a first touch policy. A memory page is allocated - if possible - nearby the process touching it first.

Important: First touch, not allocate!

MPI programs with one process per core tend to do things right, data is accessed from the process allocating and first touching the data. Only extreme inbalance, like one rank using so much memory on one NUMA node that other ranks memory does not fit into the local node. In such a case, performance could suffer as memory accesses have to be done to remote memory on the further node.

For OpenMP programs, care has to be taken that the nodes are used in a balanced way, and that processes touch the memory multithreaded, and in the same way as the data is accessed later, if possible.

Here is simple example to demonstrate the impact of wrong initialization of data.

File: numa.c
#include <stdlib.h>
#include <stdio.h>
#include <sys/time.h>

#define GB (1024*1024*1024)
#define N (GB/2)

double second()
        struct timeval tp;
        struct timezone tzp;
        int i;
        i = gettimeofday(&tp,&tzp);
        return ( (double) tp.tv_sec + (double) tp.tv_usec * 1.e-6 );

        int i;
        double t1,t2;
        float *a,*b,*c;

        /* allocate memory */
        if(!a) {
                fprintf(stderr, "allocation error\n");
        if(!b) {
                fprintf(stderr, "allocation error\n");
        if(!c) {
                fprintf(stderr, "allocation error\n");

        /* initialize the data */
#pragma omp parallel for private(i) shared(a,b,c) 
        for(i=0; i<N; i++) {

        /* do something with data */
#pragma omp parallel for private(i) shared(a,b,c)
        for(i=0; i<N; i++) {

        printf("time: %lf sec\n",t2-t1);

If this code is compiled using

icc -openmp -O3 -xSSE4.1 numa.c

and run using


one gets a runtime of about 0.443941 seconds. (we use 8 threads and use intel compilers openmp runtime option to pin threads to cores for most consistent performance and NUMA placement)

If compiled with

icc -DPARALLELINIT -openmp -O3 -xSSE4.1 numa.c

the runtime is 0.230432 seconds, which is x1.9 better than the initial result.

The initialization of the data within a parallel loop makes sure the data is for each thread on the local node, and therefor nearly doubles the performance. As the data is small enough to fit into one node, if no care is taken, all data resides behind one of the two memory controllers, and one half of the available memory bandwidth is wasted.

If a hybrid MPI-OpenMP approach is used, it can make perfect sense to run one MPI process per numa node, so on the Nehalem cluster, 2 per node, and use 4 threads per MPI process.

See the MPI section for a wrapper script allowing numa placement of the MPI processes and thread pinning of the OpenMP threads for best results.