IBM®
Skip to main content
    United States change      Terms of use
 
 
Select a scope:    
     Home      Products      Services & industry solutions      Support & downloads      My account     
alphaWorks  >  Systems management  >  

IBM XL C/C++ for Transactional Memory for AIX

A complete programming environment for developing scalable parallel applications using software transactional memory (STM).


Date Posted: May 29, 2008
Overview Requirements DownloadFAQsForum Reviews

1. What is transactional memory?
2. How does software transactional memory (STM) work?
3. How do I write a simple program using transactional memory language extensions?
4. Where can I get more information about IBM® XL C/C++ for Transactional Memory for AIX®?
5. What are the limitations?
6. How do I report bugs?
7. Can I enter or exit in the middle of a TM atomic region?
8. Why must functions called in transactions be annotated?
9. How are functions annotated for transactional memory instrumentation?
10. What is the difference between the attributes tm_func and tm_func_notrans?
11. Does function annotation apply to class member functions, virtual functions, and template functions?
12. Can malloc/free routines be used inside transactions?
13. Is it safe to call libraries in a transaction?
14. What are TM intrinsics and how are they used?
15. I downloaded the IBM XL C/C++ for Transactional Memory for AIX, but I cannot install it. What could be missing?
16. How do I compile and link an STM program?
17. How do I enable STM run-time statistics?
18. How do I know which references are transformed to STM barriers by the compiler?
19. How do I turn off transactional memory?
20. I get a warning message on an unannotated function inside a transaction. Need I do anything?
21. What should I do about a warning message on function pointers?
22. I get an error upon linking with unresolved symbols related to STM library.
23. I get the following error message: The function tm_trans_write is not a type-generic macro.


1. What is transactional memory?

Transactional memory is a set of declarative constructs that provide data-dependent synchronization for multi-threaded programs. This programming model can be an alternative to conventional synchronization methods such as locks and critical sections.
Back to top Back to top

2. How does software transactional memory (STM) work?

STM is a run-time library that manages memory accesses executed inside transactions. The run-time library ensures that the memory state of a transaction is visible to other threads only after the transaction commits. The run-time library relies on the compiler to instrument memory references in transactions into STM run-time calls to be monitored by the run-time environment.
Back to top Back to top

3. How do I write a simple program using transactional memory language extensions?

In order to write a program using transactional memory language extension, users first write a multi-threaded program using, for example, OpenMP directives or thread Libraries, then mark critical sections using #pragma tm atomic. If transactions are invoked in critical sections, they can be annotated by the attributes of transactional memory function at function declaration.

Following is the source code for the complete program foo.c:

#include <omp.h>

extern int usleep(useconds_t ) __attribute__((tm_func_notrans));

int incre(int sum) __attribute__((tm_func)) ;
int incre(int sum)
{
 usleep(1);
 return sum+1;
}

int main() {
 int sum = 0;

 printf("Num of OMP threads: %d\n", omp_get_max_threads());

#pragma omp parallel for
 for(int i=0; i <100; i++) {
 #pragma tm atomic default(trans)
 {
 sum = incre(sum);
 }
 }

 printf("sum = %d\n", sum);
}

Steps for compiling and executing the source program foo.c are as follows:

% stmxlc –qsmp=omp foo.c -lstm
% setenv OMP_NUM_THREADS 4
% ./a.out
[mycomputer] Num of OMP threads: 4
[mycomputer] sum = 100
Back to top Back to top

4. Where can I get more information about IBM® XL C/C++ for Transactional Memory for AIX®?

Please see the following white paper: Language extensions and user's guide.
Back to top Back to top

5. What are the limitations?

This release has the following limitations:
  • This release (Version 0.9) does not support non-default installation (NDI). It requires that IBM XL C (or C/C++) for Enterprise Edition for AIX be installed in its default location.
  • C++ exceptions-handling occurances in a transaction are not supported. An exception may exit the transaction without properly committing or aborting a transaction.
  • In this release, the goto statement in the tm atomic region is supported only in the C++ compiler, not the C compiler.
  • It is, in general, unsafe to call libraries inside a transaction.
  • Transactional memory might not work properly with other synchronization methods (such as locks).
  • Software transactional memory might incur a high overhead for instrumented memory references.
  • The STM run-time environment supports weak atomicity.
Back to top Back to top

6. How do I report bugs?

Please post all comments, questions, or suggestions to the alphaWorks® forum for IBM XL C/C++ for Transactional Memory for AIX.

We will make every effort to reply to the postings, but we cannot guarantee that every posting will receive a reply. No updates or fixes to the compilers will be provided during the alpha phase, but all reported bugs will be considered for resolution in future releases.

Back to top Back to top

7. Can I enter or exit in the middle of a TM atomic region?

The code block associated with #pragma tm atomic has a single entry but can have multiple exits. That is, you cannot jump into the middle of a transaction, but you can exit a transaction through a continue, break, or return statement. Please note that, as a limitation of this alpha release, the goto statement is allowed only in C++.
Back to top Back to top

8. Why must functions called in transactions be annotated?

The annotations mark functions that can be called by transactions. The compiler must properly instrument these functions so that their memory references can be monitored by the STM run-time environment.
Back to top Back to top

9. How are functions annotated for transactional memory instrumentation?

These functions must be annotated by the attributes tm_func or tm_func_notrans at the function declaration point.

 int foo() __attribute__((tm_func)) ;
int foo()
{
 ...
}

Back to top Back to top

10. What is the difference between the attributes tm_func and tm_func_notrans?

Both indicate that the function can be called in a transaction, but they differ in whether memory references in the function require compiler instrumentation.

Functions annotated by tm_func require the compiler to instrument its memory references, whereas functions annotated by tm_func_notrans do not.

The programmer guarantees that functions annotated with the attribute tm_func_notrans are safe to call from a transactional memory region without the compiler's instrumenting their memory references.

Back to top Back to top

11. Does function annotation apply to class member functions, virtual functions, and template functions?

Yes.
Back to top Back to top

12. Can malloc/free routines be used inside transactions?

Yes. The compiler will replace calls to malloc/free routines to proper STM run-time calls.
Back to top Back to top

13. Is it safe to call libraries in a transaction?

In general, it is not safe to call libraries in a transaction: The source codes of library calls are not available, so their memory references cannot be instrumented and monitored. Exceptions can be made for libraries known to access only local or non-shared data (for example, sin()).
Back to top Back to top

14. What are TM intrinsics and how are they used?

We provide users with four intrinsic functions to control whether a memory reference is transformed to a STM "read" and "write" barrier.

tm_trans_read() and tm_trans_write() are used to directly instrument references in #pragma tm atomic default(notrans) regions or tm_func_notrans functions.

tm_notrans_read() and tm_notrans_write() are used to tell the compiler not to instrument a memory reference in #pragma tm atomic default(trans) regions or tm_func functions.

Back to top Back to top

15. I downloaded the IBM XL C/C++ for Transactional Memory for AIX, but I cannot install it. What could be missing?

Please make sure you have installed the prerequisite software, which is one of these compilers: IBM XL C Enterprise Edition for AIX, Version 9.0, or IBM XL C/C++ Enterprise Edition for AIX, Version 9.0.
Back to top Back to top

16. How do I compile and link an STM program?

Programs are compiled with stmxlc or stmxlc++ and must be explicitly linked with the STM run-time library. There are two versions of STM run-time library:
  • -libstm.a is the standard STM library: % stmxlc foo.c -lstm
  • -libstmstat.a is the debug version of the STM library for collecting transaction run-time statistics: % stmxlc foo.c -lstmstat
Back to top Back to top

17. How do I enable STM run-time statistics?

Insert stm_print_stats() call in the program and link the program with the debugging version of STM run-time library -lstmstat. In the following example, run-time statistics are put out to 2 files running directly under - stm_stats_tag01_txn_foo-stats.c_22.out (stats for the transaction at line 22 in foo-stats.c) and stm_stats_tag01_all.out (stats for all transactions in the program).

Following is foo-stat.c:

#include <omp.h>

int incre(int sum) __attribute__((tm_func)) ;
int incre(int sum)
{
 sleep(1);
 return sum+1;
}

int main() {
 int sum = 0;

 printf("Num of OMP threads: %d\n", omp_get_max_threads());

#pragma omp parallel for
 for(int i=0; i <100; i++) {
 #pragma tm atomic default(trans)
 {
 sum = incre(sum);
 }
 }

 stm_print_stats();
 printf("sum = %d\n", sum);
}

% stmxlc –qsmp=omp foo-stat.c -lstmstat
% setenv OMP_NUM_THREADS 4
% ./a.out
[mycomputer] Num of OMP threads: 4
[mycomputer] sum = 100
Back to top Back to top

18. How do I know which references are transformed to STM barriers by the compiler?

Use the compiler option –qreport to get the information in the listing file. The following is an example of using –qreport when compiling an STM program; the instrumentation report is in the "STM Instrumentation Report Section" part of foo.lst.

% stmxlc -qsmp=omp -qreport foo.c -lstm
Back to top Back to top

19. How do I turn off transactional memory?

The option -qnotm turns off the processing of transactional memory. Under this option, transactional memory pragma and function attributes are ignored. Intrinsic functions tm_trans_read, tm_trans_write, tm_notrans_read, and tm_notrans_write are mapped to regular "read" and "write" operations.
Back to top Back to top

20. I get a warning message on an unannotated function inside a transaction. Need I do anything?

This message warns about un-annotated functions called in lexical transactional scopes. It is highly recommended that programmers pay attention to this warning message and annotate the reported function as either tm_func or tm_func_notrans.

The wording of the warning message might differ between the XL C and XL C/C++ compilers:

  • Compiled with XL C compiler: "The function foo is called from a transactional context but its prototype is not annotated with attribute tm_func or tm_func_notrans."
  • Compiled with XL C/C++ compiler: "The function 'void foo(int)' should be annotated with tm_func or tm_func_notrans function attribute."
Back to top Back to top

21. What should I do about a warning message on function pointers?

This message warns about calls through function pointers in lexical transactional scopes. It is highly recommended that programmers pay attention to this warning message and ensure that all targets of the reported function pointer be annotated with transactional function attributes.

The warning message is as follows:

  • Compiled with XL C compiler: "A call through a function pointer in a transactional context may invoke a function that is not annotated with attribute tm_func or tm_func_notrans."
  • Compiled with XL C/C++ compiler: "User should make sure the function that the function pointer 'fpt' points to should be annotated with transactional memory function attribute."
Back to top Back to top

22. I get an error upon linking with unresolved symbols related to STM library.

This error is possibly caused by a missing STM library during the linking. Here are some messages you might see if –lstm is not used at the link:
  • ld: 0711-317 ERROR: Undefined Symbol: .stm_desc
  • ld: 0711-317 ERROR: Undefined symbol: .stm_begin
  • ld: 0711-317 ERROR: Undefined symbol: .stm_end
Back to top Back to top

23. I get the following error message: The function tm_trans_write is not a type-generic macro.

This is a C-only message. The problem is possibly caused by mismatching or incorrect parameter types used in the intrinsics. Refer to the Language extensions and user's guide for the supported data types for these intrinsics.

When using TM intrinsics to access pointer types in C, type casting to (void**) or (void*) is typically needed. For example:

char* p[10];
char* val;
...
tm_trans_write((void**) &p[2], (void*) val);


IBM, AIX, and alphaWorks are trademarks of IBM Corporation in the United States, other countries, or both.
Other company, product, or service names may be trademarks or service marks of others.
Back to top Back to top
Download now Download now

Related technologies

For platform(s):
AIX

For topics:
AIX, Compilers, Parallel computing, Scalability


Related resources

C/C++ Café

 

    About IBM Privacy Contact