Code Optimisation for Data-Based Global Carbon Cycle Analysis
Total Page:16
File Type:pdf, Size:1020Kb
Code optimisation for data-based global carbon cycle analysis André Schembri August 19, 2016 i. TABLE OF CONTENTS i. Table of Contents ............................................................................................................................ 1 ii. Table of Figures ............................................................................................................................... 3 iii. Table of acronyms ........................................................................................................................... 5 iv. Abstract ........................................................................................................................................... 6 v. Acknowledgments ........................................................................................................................... 7 1 Introduction .................................................................................................................................... 8 2 Literature Review .......................................................................................................................... 10 2.1 CARDAMOM .......................................................................................................................... 10 2.2 Target System ........................................................................................................................ 12 2.2.1 The Eddie3 Computer Cluster ......................................................................................... 12 2.2.2 The Xeon® E5-2630 v3 processor..................................................................................... 12 2.3 Code Optimisation ................................................................................................................. 16 2.3.1 Increasing instruction level parallelism ........................................................................... 16 2.3.2 Using less expensive instructions .................................................................................... 16 2.3.3 Using optimal memory access patterns .......................................................................... 17 3 Research Methods ......................................................................................................................... 18 3.1 Identifying the best compilation strategy ............................................................................... 18 3.2 Code Optimisation ................................................................................................................. 19 3.3 Keeping track of changes ........................................................................................................ 19 3.4 Scripts used to run tests ......................................................................................................... 19 3.5 Verification of results ............................................................................................................. 22 3.6 Determining performance gain and loss ................................................................................. 22 4 Compilation Strategies ................................................................................................................... 23 4.1 List and description of compiler flags determined to be important ......................................... 23 4.2 Results of different optimisation levels................................................................................... 24 4.3 Results of different combination of compilation strategies ..................................................... 26 5 Code Optimisation ......................................................................................................................... 28 5.1 Hotspot Analysis .................................................................................................................... 28 5.2 Carbon Model Code Optimisation .......................................................................................... 30 5.2.1 Calculate time and temperature dependencies............................................................... 30 5.2.2 Calculate Fluxes code block and the ACM function ......................................................... 36 1 5.2.3 Extracting function from the main Carbon_Model loop .................................................. 45 5.2.4 Calculate growing session index code block .................................................................... 46 5.3 The EDC2_GSI subroutine optimisation .................................................................................. 48 5.4 Merging the optimisations together ....................................................................................... 50 6 Conclusions ................................................................................................................................... 53 7 Future Work .................................................................................................................................. 53 Appendix A – Code of the carbon model sub procedure ........................................................................ 54 Appendix B – Scripts used to run benchmarks ....................................................................................... 73 Shell script used to run benchmarks .................................................................................................. 73 Script used to collect results .............................................................................................................. 74 Appendix C – Simple unit test ................................................................................................................ 76 Appendix D – Other Results ................................................................................................................... 79 Results which were not collected with Eddie ..................................................................................... 79 Results collected with Eddie .............................................................................................................. 82 Bibliography .......................................................................................................................................... 83 2 ii. TABLE OF FIGURES FIGURE 1-1 THE CARBON EXCHANGES WITHIN A TERRESTRIAL ECOSYSTEM (TAKEN FROM [2]) ......................................................... 8 FIGURE 2-1 THREE STEPS USUALLY UNDERTAKEN TO GENERATE DATA WITH CARDAMOM ......................................................... 10 FIGURE 2-2 A UML ACTIVITY DIAGRAM SHOWING A HIGH LEVEL OVERVIEW OF HOW CARDAMOM WORKS, TOGETHER WITH THE CPU TIME SPENT IN EACH PART OF CARDAMOM........................................................................................................... 11 TABLE 2-1 DIFFERENT NODE TYPES THAT COMPOSE THE EDDIE3 COMPUTE CLUSTER (TAKEN FROM HTTPS://WWW.WIKI.ED.AC.UK/DISPLAY/RESEARCHSERVICES/MEMORY+SPECIFICATION) .................................................. 12 TABLE 2-2 SHOWING THE MAXIMUM TURBO BOOST THAT CAN BE ACHIEVED BY THE DIFFERENT CORES WITHIN INTEL® XEON® PROCESSOR E5-2630 V3, BOTH WHEN USING AVX INSTRUCTIONS AND OTHER X86 INSTRUCTIONS. (TAKEN FROM INTEL® XEON® PROCESSOR E5 V3PRODUCT FAMILY - PROCESSOR SPECIFICATION UPDATE [11])............................................................................. 14 FIGURE 2-3 THE DIFFERENT EXECUTION PORTS AND EXECUTION UNITS IN HASWELL MICROARCHITECTURE TAKEN FROM [7]. ................ 15 FIGURE 3-1 DIRECTORY STRUCTURE TO RUN CARDAMOM TESTS IN BULK, WITH SCRIPTS TO BUILD EXECUTABLE (MAKEFILE), RUNNING ALL THE TESTS AND BUILD FILES (RUNALL.SH) AND COLLECTING RESULTS (GETRESULTS.PY) .................................................. 21 TABLE 4-1 LIST OF DIFFERENT COMPILATION FLAGS AVAILABLE FOR THE INTEL COMPILER AND THEIR INTENDED EFFECT ........................ 24 FIGURE 4-1 TIME TAKEN TO RUN CARDAMOM COMPILED WITH INTEL COMPILER USING DIFFERENT OPTIMISATION LEVELS, USING THE UK FORESTRY PARAMETER FILE AS AN INPUT, THE RESULTS SHOW THAT THE BEST OPTIMISATION LEVEL IS THE O2 LEVEL. .................. 25 FIGURE 4-2 TIME TAKEN TO RUN CARDAMOM WITH THE UK FORESTRY SAMPLE USING DIFFERENT COMPILATION STRATEGIES (FOR SINGLE FILE SEE FOOTNOTE), THE RESULTS SHOW THAT THE BEST PERFORMING COMPILATION STRATEGY IS O2 -XHOST -IPO -NO-FTZ. SINGLE FILE MEANS THAT THE COMPILATION WAS NOT LINKED INTO TWO DIFFERENT COMPILATION BUT COMPILED IN A SINGLE COMPILATION .................................................................................................................................................. 27 FIGURE 5-1 A TREE DIAGRAM SHOWING HOW THE CPU TIME WAS SPENT IN EACH PART OF THE APPLICATION (SOME VALUES BELOW 1% ARE OMITTED).................................................................................................................................................. 29 FIGURE 5-2 CODE BLOCK: "CALCULATE TIME AND TEMPERATURE DEPENDENCIES" FROM CARDAMOM’S CARBON MODEL METHOD ... 30 FIGURE 5-3 COMPUTING A NUMBER THAT WHEN MULTIPLIED GENERATES (ALMOST) THE SAME RESULTS AS DIVIDING THE NUMBER AND ASSIGNING IT TO DETATDIVISOR ............................................................................................................................ 31 FIGURE 5-4 REPLACING THE DIVISOR (/DELTAT(N)) WITH A MULTIPLIER (*DELTATDIVISOR) ........................................................ 32 FIGURE 5--5-5 TIME TAKEN TO RUN CARDAMOM WITH (A)