High Performance Computing for Applications in Engineering ME759 Fall 2023 Lecture 02 09 08 2023 Dan Negrut 2023 ME759 UW Madison University of Wisconsin Madison 1 Cartoon of the day Tom Toro University of Wisconsin Madison 2 Is Zoom recording on University of Wisconsin Madison 3 Before we get started Quick overview things discussed last time 30 000 feet perspective of ME759 Read the lecture material start assignment early stay honest ME759 is not hard But it s busy Purpose of today s lecture Do not run code on the log in node of Euler CAE will suspend your account Use Slurm to launch you exe Discuss about the concept of instruction Your program is a bunch of them instructions Discuss how transistors are organized to work together so that they end up executing them instructions Miscellaneous Homework went out last night Due on Thursday at 9 pm University of Wisconsin Madison 4 Euler an important slide For those who didn t take ME459 please read this deck of slides It is very important It tells you how to log into Euler It tells you how to work on Euler which requires you to use Slurm utilities Bottom line you should not run a program on Euler s log in node You can compile a piece of code but run using Slurm If you run code on log in node CAE will suspend your Euler account It helps you to take care of Assignment 1 Talks about the concept of module slurm scripts etc University of Wisconsin Madison 5 Assignment the typical work cycle 1 Write your solution using your favorite editor IDE on your computer or CAE workstation 2 Build test the code on your CAE computer until you are convinced that it works as intended 3 Get your files over to Euler using scp or via git 4 Build your executable on Euler on the log in node 5 Write Recycle slurm scripts to define how your executable will be managed by Slurm 6 Run slurm script to place your executable in the Slurm queue 7 Once it finished examine the output of your job 8 By default output of your program is written to a file starting with slurm If there are any small problems use a terminal text editor on Euler like vim to make minor changes to your code and then rerun your slurm script to test your program again on Euler NOTE If the results look bad you might need to go back to 1 9 Once you are convinced that program works as expected on Euler push solution into your git repo Note Your code will be graded based on how it runs on Euler not how it works on your computer University of Wisconsin Madison 6 The Hardware Software Interplay Big Segment University of Wisconsin Madison 7 The ISA The FDX cycle Microarchitecture ure aspects University of Wisconsin Madison 8 This segment s purpose Understand the basics of how the hardware works for the purpose of writing better software Immediate focus discuss how a sequence of instructions processes a bunch of data University of Wisconsin Madison 9 From C C Code to Machine Instructions 1 4 Your program is the result of a compile step in which a source file is turned into an executable Your lines of code converted into machine instructions What s an executable Sequence of machine instructions that can be processed one by one by the processor Execution concludes i e your program is done when last instruction was taken care of include iostream Simplest C Program int main int argc char argv std cout Hello World n return 0 euler ME759 gcc o helloWorld helloWorld cpp euler ME759 ls helloWorld helloWorld cpp euler ME759 helloWorld Hello World euler ME759 University of Wisconsin Madison 10 From C Code to Machine Instructions 2 4 Fact There is a difference between a line a code and a machine instruction Example Line of C code a 4 delta a 3 line of C code MIPS assembly code generated by the compiler three instructions lw t0 12 s2 reg t0 gets value stored 12 bytes from address in s2 add t0 s4 t0 reg t0 gets the sum of values stored in reg s4 and reg t0 sw t0 16 s2 store what s in t0 at mem location 16 bytes from address in s2 Set of three corresponding MIPS instructions produced by the compiler 10001110010010000000000000001100 00000010100010000100000000100000 10101110010010000000000000010000 University of Wisconsin Madison 11 From C Code to Machine Instructions 3 4 C code what you write to implement an algorithm Intermediate Representation compiler converts your code to a specialized representation that it can optimize Assembly code another intermediate step for compiler humans can still read it Spend 5 mins here https godbolt org Machine code Instructions what the assembly code gets translated into and what the control unit CU digests Machine code what you see in an editor notepad vim etc if you open an executable file basically gibberish There is a direct correspondence between a line of assembly code and instructions this is often one to one particularly true for certain processors University of Wisconsin Madison 12 From C Code to Machine Instructions 4 4 Observations The compiler goes from C code to machine instructions without producing anything else unless you ask for it That is no assembly is saved for you to peek at again unless you ask the compiler for it Back in the day people programmed computers via assembly code Today writing assembly code done only for critical parts of a program by people who want to highly optimize the execution and choose to overrule the compiler University of Wisconsin Madison 13 More on the assembly instructions side of things We ll not cover assembly in ME759 If you really are into computing though you should be able to handle assembly code Why In critical cases you might want to check that the compiler does what you think it should do Examples you optimize the code with O3 and want to confirm that A for loop got unrolled to reduce the number of jump conditions and improve changes for pipelining A function got inlined to avoid a pair of jumps that ruin pipelining University of Wisconsin Madison 14 Same code same compiler gcc different flags No gcc flag used here O3 flag used here https godbolt org eax 32 bit general purpose register whose main purpose in life but not the only one is to store the return value of a function University of Wisconsin Madison 15 Example the same C code leads to different assembly code and different set of machine instructions not shown here int main const double fctr 3 14 180 0 double a 60 0 double b 120 0 double c c fctr a b return 0 C code Legend fldl load floating point flmulp multiply pop register stack movl move from one register to another
View Full Document