XL C/C++: Optimization and Programming Guide

XL C/C++: Optimization and Programming Guide

IBM XL C/C++ for AIX, V10.1 Optimization and Programming Guide Ve r s i o n 10.1 SC23-8887-00 IBM XL C/C++ for AIX, V10.1 Optimization and Programming Guide Ve r s i o n 10.1 SC23-8887-00 Note Before using this information and the product it supports, read the information in “Notices” on page 143. First edition This edition applies to IBM XL C/C++ for AIX, V10.1 (Program number 5724-U81) and to all subsequent releases and modifications until otherwise indicated in new editions. Make sure you are using the correct edition for the level of the product. © Copyright International Business Machines Corporation 1996, 2008. All rights reserved. US Government Users Restricted Rights – Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. Contents About this information . .v Managing memory with multiple heaps . .25 Who should read this information . .v Functions for managing user-created heaps . .26 How to use this information . .v Creating a heap . .27 How this information is organized . .v Expanding a heap . .28 Conventions . .vi Using a heap . .29 Related information . .ix Getting information about a heap . .30 IBM XL C/C++ information . .ix Closing and destroying a heap . .30 Standards and specifications . .x Changing the default heap used in a program . .31 Other IBM information . .xi Compiling and linking a program with Other information . .xi user-created heaps . .31 Technical support . .xi Examples of creating and using user heaps . .31 How to send your comments . xii Debugging memory heaps . .36 Functions for checking memory heaps . .37 Functions for debugging memory heaps . .37 Chapter 1. Using 32-bit and 64-bit Using memory allocation fill patterns . .39 modes . .1 Skipping heap checking . .39 Assigning long values . .2 Using stack traces . .40 Assigning constant values to long variables . .2 Bit-shifting long values . .3 Chapter 6. Using C++ templates . .41 Assigning pointers . .3 Using the -qtempinc compiler option . .42 Aligning aggregate data . .4 Example of -qtempinc . .42 Calling Fortran code . .4 Regenerating the template instantiation file . .44 Using -qtempinc with shared libraries . .44 Chapter 2. Using XL C/C++ with Fortran 5 Using the -qtemplateregistry compiler option . .44 Identifiers . .5 Recompiling related compilation units . .45 Corresponding data types . .5 Switching from -qtempinc to -qtemplateregistry 45 Character and aggregate data . .6 Function calls and parameter passing . .7 Chapter 7. Constructing a library . .47 Pointers to functions . .7 Compiling and linking a library . .47 Sample program: C/C++ calling Fortran . .7 Compiling a static library . .47 Compiling a shared library . .47 Chapter 3. Aligning data . .9 Linking a library to an application . .49 Using alignment modes . .9 Linking a shared library to another shared library 50 Alignment of aggregates . .11 Initializing static objects in libraries (C++) . .50 Alignment of bit fields . .13 Assigning priorities to objects . .50 Using alignment modifiers . .15 Order of object initialization across libraries . .52 Guidelines for determining alignment of scalar Dynamically loading a shared library . .55 variables . .17 Loading and initializing a module with the Guidelines for determining alignment of loadAndInit function . .55 aggregate variables . .17 Terminating and unloading a module with the terminateAndUnload function . .57 Chapter 4. Handling floating point operations . .19 Chapter 8. Replacing operator new and Floating-point formats . .19 operator delete in applications that use Handling multiply-add operations . .19 shared libraries (C++) . .59 Compiling for strict IEEE conformance . .20 Handling floating-point constant folding and Chapter 9. Using the C++ utilities . .61 rounding . .20 Matching compile-time and runtime rounding Demangling compiled C++ names . .61 modes . .21 Demangling compiled C++ names with c++filt 61 Rounding modes and standard library functions 22 Demangling compiled C++ names with the Handling floating-point exceptions . .23 demangle class library . .62 Compiling a decimal floating-point program . .23 Creating a shared library with the makeC++SharedLib utility . .64 Linking with the linkxlC utility . .66 Chapter 5. Using memory heaps . .25 © Copyright IBM Corp. 1996, 2008 iii Chapter 10. Optimizing your BLAS function syntax. .110 Linking the libxlopt library . .113 applications . .67 Distinguishing between optimization and tuning . .67 Steps in the optimization process . .68 Chapter 14. Parallelizing your Basic optimization . .68 programs . .115 Optimizing at level 0 . .68 Countable loops . .116 Optimizing at level 2 . .69 Enabling automatic parallelization . .117 Advanced optimization . .70 Using IBM SMP directives (C only) . .117 Optimizing at level 3 . .71 Using OpenMP directives . .118 An intermediate step: adding -qhot suboptions at Shared and private variables in a parallel level 3 . .71 environment . .119 Optimizing at level 4 . .72 Reduction operations in parallelized loops . 121 Optimizing at level 5 . .73 Tuning for your system architecture . .73 Chapter 15. Selecting the standard Getting the most out of target machine options 74 allocation method to suit performance Using high-order loop analysis and transformations 76 (C++) . 123 Getting the most out of -qhot . .77 Using shared-memory parallelism (SMP) . .77 Getting the most out of -qsmp . .78 Chapter 16. Ensuring thread safety Using interprocedural analysis . .79 (C++) . 125 Getting the most from -qipa . .80 Ensuring thread safety of template objects . 125 Using profile-directed feedback . .81 Ensuring thread safety of stream objects . 125 Viewing profiling information with showpdf . .83 Object level profile-directed feedback . .84 Chapter 17. Memory debug library Other optimization options . .86 functions . 127 Memory allocation debug functions . 127 Chapter 11. Debugging optimized code 89 _debug_calloc — Allocate and initialize memory 127 Understanding different results in optimized _debug_free — Free allocated memory . 128 programs . .90 _debug_heapmin — Free unused memory in the Debugging before optimization . .90 default heap . 129 Using -qoptdebug to help debug optimized _debug_malloc — Allocate memory . 130 programs . .91 _debug_ucalloc — Reserve and initialize memory from a user-created heap . 131 Chapter 12. Coding your application to _debug_uheapmin — Free unused memory in a improve performance . .95 user-created heap . 132 Find faster input/output techniques . .95 _debug_umalloc — Reserve memory blocks Reduce function-call overhead . .95 from a user-created heap . 133 Manage memory efficiently . .97 _debug_realloc — Reallocate memory block . 134 Optimize variables . .97 String handling debug functions . 135 Manipulate strings efficiently . .98 _debug_memcpy — Copy bytes . 135 Optimize expressions and program logic . .99 _debug_memset — Set bytes to value . 136 Optimize operations in 64-bit mode . .99 _debug_strcat — Concatenate strings . 137 _debug_strcpy — Copy strings . 138 _debug_strncat — Concatenate strings . 139 Chapter 13. Using the high _debug_strncpy — Copy strings . 140 performance libraries . 101 _debug_strnset — Set characters in a string . 141 Using the Mathematical Acceleration Subsystem _debug_strset — Set characters in a string . 141 libraries (MASS) . 101 Using the scalar library . 101 Notices . 143 Using the vector libraries . 104 Trademarks and service marks . 145 Compiling and linking a program with MASS 109 Using the Basic Linear Algebra Subprograms – BLAS . .110 Index . 147 iv XL C/C++: Optimization and Programming Guide About this information ® This guide discusses advanced topics related to the use of the IBM XL C/C++ for ® AIX , V10.1 compiler, with a particular focus on program portability and optimization. The guide provides both reference information and practical tips for getting the most out of the compiler’s capabilities, through recommended programming practices and compilation procedures. Who should read this information This document is addressed to programmers building complex applications, who already have experience compiling with XL C/C++, and would like to take further advantage of the compiler’s capabilities for program optimization and tuning, support for advanced programming language features, and add-on tools and utilities. How to use this information ″ ″ This document uses a task-oriented approach to presenting the topics, by concentrating on a specific programming or compilation problem in each section. Each topic contains extensive cross-references to the relevant sections of the reference guides in the IBM XL C/C++ for AIX, V10.1 documentation set, which provide detailed descriptions of compiler options and pragmas, and specific language extensions. How this information is organized This guide includes these topics: v Chapter 1, “Using 32-bit and 64-bit modes,” on page 1 discusses common problems that arise when porting existing 32-bit applications to 64-bit mode, and provides recommendations for avoiding these problems. v Chapter 2, “Using XL C/C++ with Fortran,” on page 5 discusses considerations for calling Fortran code from XL C/C++ programs. v Chapter 3, “Aligning data,” on page 9 discusses the different compiler options available for controlling the alignment of data in aggregates, such as structures and classes, on all platforms. v Chapter 4, “Handling floating point operations,” on page 19 discusses options available for controlling the way floating-point operations are handled by the compiler. v Chapter 5, “Using memory heaps,” on page 25 discusses

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    164 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us