Posts Tagged ‘instrumentation’

UPC performance analysis

October 8, 2012

GASP is an interface for instrumenting UPC applications. It allows performance analysis tools to gather information on application execution. If you want to gather such data you need to implement a number of call-back functions, which will receive all information when application is run. Then you compile your implementation along with the user code. In a nutshell GASP is simply a collection of functions which are inserted at the beginning as well as at the end of UPC library functions. Each time function is called you receive data through call-backs. Then it’s up to you what you do with that data: count how many times function has been called, calculate how much data has been transfered between threads, find out how much time has been spent in barriers and so on. GASP is described in detail in specification, there are also several articles on that topic. You can find that information at GASP official site. GASP is implemented in Berkeley UPC, there is also a limited support in GCC UPC.


There are several tools that can utilize GASP to analyze UPC applications. The most dumb tool is upc_dump, which is included into Berkeley UPC compiler. It doesn’t actually analyze application, it simply dumps all tracing information. Here is how you compile UPC application with upc_dump:

> /opt/bupc-runtime-2.8.0/opt_inst/bin/upcc -network=udp --inst-toolname=dump /opt/bupc-runtime-2.8.0/opt_inst/bin/gasp-dump/gaspu.upc -L/opt/bupc-runtime-2.8.0/opt_inst/bin/gasp-dump -lgasp-dump -T=4 --inst bin_file

First of all you need to compile your code with instrumented version of UPC from opt_inst subdirectory. I described how to compile opt_inst earlier in this post. With --inst-toolname you provide the name of instrumentation tool (it seems that it doesn’t matter what you specify here). Then you compile your application along with gaspu.upc. Usually developers of performance analysis tools put GASP related call-back implementations into a library and all upcalls to UPC code into a separate source file (such as gaspu.upc for upc_dump), since library is compiled with C compiler and cannot include UPC code. Then you provide path to the library with -L flag and name of the library with -l flag. The last --inst flag instructs the compiler to instrument all UPC library functions. --inst-functions also instruments all user-defined functions. Additionally, --inst-local allows to instrument all local accesses to shared memory within the thread.


upc_trace is another tool distributed with Berkeley UPC, but it has some performance analysis functionality. Unlike upc_dump you don’t need to manually specify all flags to the compiler. What you need to do is to compile an opt_trace subbuild. And upcrun application with the -trace flag. When execution is completed you will have several trace files which you pass on to upc_trace tool. Performance analysis data is represented as output text file. You can control which types of events are gathered using GASNET_TRACEMASK environment variable.

Parallel Performance Wizard

PPW is probably the one performance analysis tool for UPC with rich functionality. PPW installation is simple:

# ./configure --prefix=/home/fred/ppw-2.6 --with-upc=/home/fred/bupc-runtime-2.10.0
# make
# make install

Then to perform simple tests use PPW wrappers for upcc and upcrun:

> ppwupcc -network=udp --inst-functions -T=32 upc_code.c
> UPC_NODES=”n1 n2 n3 n4″ ppwrun --output=upc_code.par upcrun -n 32 -nodes=4 bin_file

PPW has GUI where you pass the .par file and see what happened in the application.


Advanced notes on Unified Parallel C installation

October 8, 2012

I already described basic Berkeley UPC compiler installation here. So now lets go deeper in details.

Backend Compilers

Basically UPC compiler is a translator from UPC language to C. After translation is done, backend C compiler is invoked to actually compile the code. On Linux clusters GCC is used by default, if you have Intel, Sun or any other high performance compiler installed, then use CC and CXX flags in UPC runtime configure step:

./configure CC=icc CXX=icpc --prefix=/opt/bupc-runtime-2.12.1-icc
./configure CC=suncc CXX=sunCC --prefix=/opt/bupc-runtime-2.10.0-suncc

Optional UPC builds

By default Berkeley UPC is installed in two configurations: debug (with GASnet assertions enabled and debugging info compiled in) and opt (optimized version for everyday use). You will see debug and opt subdirectories in your working UPC runtime build. But you can install additional versions of runtime for other uses.

Berkeley UPC has integrated tracing facility. If you upcrun application with the -trace flag, tracing data is collected and you can analyze it with upc_trace utility. Tracing build can be compiled by using opt_trace multiconf option:

./configure --prefix=/opt/bupc-runtime-2.12.1 --with-multiconf=+opt_trace

Berkeley UPC has integrated callbacks (called GASP) for third-party instrumenting utilities. Instrumentation allows developers of performance analysis tools to gather all sorts of information about UPC program execution. Like functions called, their arguments, etc. If you want to develop your own UPC performance analysis tool you can use this feature during development and instruct users to build opt_trace version of UPC to be able to use your tool later.

./configure --prefix=/opt/bupc-runtime-2.12.1 --with-multiconf=+opt_inst

You can debug UPC applications with dbg build, if you are a developer and use instrumented build of UPC and need to debug it, then build a dbg_inst version. There was a dbg_inst.patch (find link below) to add dbg_inst functionality to UPC, but it’s already integrated into compiler as far as I remember.

./configure --prefix=/opt/bupc-runtime-2.12.1 --with-multiconf=+dbg_inst

There was also another bug which broke dbg_inst in 2.12.1 (which was originally implemented in 2.10.0) with the following errors:

/root/install/berkeley_upc-2.12.1/gasnet/gasnet_trace.c: In function ‘gasneti_trace_finish’:

/root/install/berkeley_upc-2.12.1/gasnet/gasnet_trace.c:988: error: ‘gasneti_mallocreport_filename’ undeclared (first use in this function)

/root/install/berkeley_upc-2.12.1/gasnet/gasnet_trace.c:988: error: (Each undeclared identifier is reported only once

/root/install/berkeley_upc-2.12.1/gasnet/gasnet_trace.c:988: error: for each function it appears in.)

To resolve this issue apply mallocreport.patch00 (find link below). But if you use recent Berkeley UPC build you won’t see this bug.

Block size

If you work with huge matrixes and want to distribute them in large chunks of consecutive rows, then you will run into UPC limitation of block size. UPC pack pointer representation into one 64 bit integer. By default 34 bits are allocated for memory address, 10 bits for threads and 20 bits for phase (or block size). 2^20 is basically a 1048576 elements which is a very small number. You can redistribute bits with --with-sptr-packed-bits=value value=’phase,thread,addr’ configure option, but then you will either have small address space or small number of threads.

Another option is to use --enable-sptr-struct configure flag which changes shared pointer representation from int to struct. It will increase block size to 2^(32-1) which is 2147483647. But it could also be too small if you conduct performance measurement and need to run your code for 1 thread. Then the whole matrix is a one huge block. 50000×50000 matrix is already hit the limit.

If 2^(32-1) is not enough, then the last option for you is to use row distributed algorithm instead of row-block distributed.

POSIX shared memory problems with InfiniBand

UPC support two one-node inter-thread shared memory communication types: POSIX shared memory and SYSV shared memory. POSIX is configured by default. If you want to register large amounts of shared memory with many PSHM processes using --shared-heap key you can see errors like these:

*** FATAL ERROR: Unexpected error Bad address (rc=1 errno=14) when registering the segment

NOTICE: Before reporting bugs, run with GASNET_BACKTRACE=1 in the environment to generate a backtrace.

*** Caught a fatal signal: SIGABRT(6) on node 29/32

To solve this problem reinstall runtime using the following options:

./configure --prefix=/opt/bupc-runtime-2.12.1 --enable-pshm --disable-pshm-posix --enable-pshm-sysv

Bug when building translator

For some vendor-build GCC releases, like Red Hat, older versions of translator fail to compile with error like:

/usr/bin/ld: ipl_summarize_util.o: relocation R_X86_64_PC32 against `Phi_To_Idx_Map’ can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Bad value
collect2: ld returned 1 exit status

It’s a bug number 2202 in UPC Bugzilla and is described here. Solution and patch are described in post 17. Find copy of patch below.

UPC I/O support for large files

UPC have parallel I/O extension. In version 2.14.0 and earlier by default UPC I/O supported files 2GB in length. It led to upc_all_fread_shared() returning -1 “Invalid argument” for data above the 2GB limit. To change defaults from 2^(32-1) bits size to 2^(64-1) use BUPC_IO_64 variable during runtime configure step:

./configure CC=”gcc -DBUPC_IO_64″ CXX=”g++ -DBUPC_IO_64″ --prefix=/opt/bupc-runtime-2.12.1

Replace GCC with your own compiler.

SUN compiler issues

If you run into an error (I had it in version 2.10.0):

“/home/fred/install/berkeley_upc-2.10.0/upcr_profile.c”, line 36: left operand must be modifiable lvalue: op “=”
cc: acomp failed for /home/fred/install/berkeley_upc-2.10.0/upcr_globfiles.c

Apply patch sun_const_field.patch00 (find link below).  Additional info can be found in Berkeley UPC Bugzilla, bug number 2696.

Another bug (not an error, but an annoying warning) looks like numerous warnings throughout compilation:

“/home/fred/install/berkeley_upc-2.10.0/upcr_atomic.h”, line 876: warning: result of paste undefined and not portable: 64_ (E_PASTE_RESULT_NOT_TOKEN)
“/home/fred/install/berkeley_upc-2.10.0/upcr_atomic.h”, line 876: warning: result of paste undefined and not portable: 64_cswap (E_PASTE_RESULT_NOT_TOKEN)

To get rid of it apply patch not_token.patch00 (find link below). It’s described in the same 2696.

Links to patches

Unfortunately WordPress doesn’t allow to upload .txt files due to security reasons. Other formats, such as .doc or .pdf will break the lines. So I decided to give direct links when possible and provide contents of patch in text converted to .jpg format in case direct link will break in future. The drawback is that you will have to type it yourself or OCR it.