Multi-processing and Multi-threading Dr. Soumya Indela Topics • Multi-processing • Amdahl’s Law • Scaling • Multi-threading • Fine-grained • Coarse-grained • Simultaneous Process vs Thread • Processes • • • • An instance of a computer program Shared Memory, different address spaces Separate Resources - Registers, file storage, network connections, etc. Independent of each other • Threads – subset of process • • • • Set of tasks within a process Shared Address space Shared Registers, file storage, network connections. Interdependent, can be scheduled independently Amdahl’s Law • Improvement in Performance or Speedup is limited by the Serial portion 1 • Theoretical Speed-up = 𝑓 1−𝑓 + 𝑠 • f : Fraction of execution for the parallel portion • s : Scaling factor or number of processes parallel portion can be split into Program Serial Portion Parallel Portion Scaling • Strong Scaling: Speed-up achieved without increasing size of program • Weak Scaling: Speed-up achieved by increasing size of program Program Serial Portion Parallel Portion Program Serial Portion Parallel Portion Context Switch • • • • Important when switching between threads Save current state of thread being stopped If required, retrieve previous state of thread being resumed Otherwise, start a new thread Context or State Thread ID Registers Program Counter Stack Pointer Etc. Example Threads • Every line is an instruction • Stalls - Blank space between set of instructions Time Fine-grained Multi-threading • Switch between threads after every instruction • Advantage: less throughput losses due to short and long stalls, as instructions from other threads can be executed during the stalls • Disadvantage: more execution time for individual threads, since a thread that is ready to execute will be delayed Time Coarse-grained Multi-threading • Switch between threads after significant events like cache miss, etc. • Advantage: Less thread switching, so less likely to slow down the execution of an individual thread • Disadvantage: Limited ability to overcome throughput losses from shorter stalls due to pipeline refill overhead Time Simultaneous Multi-threading • Executes multiple threads simultaneously utilizing multi-issue resources • Dynamically scheduled microarchitecture • Advantage: Least cost of multithreading • Disadvantage: Additional Resources required Time Multi-processing vs Multi-threading Multi-processing Multi-threading Multiple processors Single Processor Single or Multiple threads Multiple threads Parallel Execution Concurrent Execution Only Shared Memory, all other resources are separate All shared resources – address space, registers, file storage, network connections, etc. Applicable for Compute intensive processes, like CPU bound processes Applicable for I/O bound processes Questions Thank you!