ScholarQuill logoScholarQuillUniversity Notes
  • Notes
  • Past Papers
  • Blogs
  • Todo
Login
ScholarQuill logoScholarQuillUniversity Notes
Login
NotesPast PapersBlogsTodo
More
SubjectsDiscussionCGPA CalculatorGPA CalculatorStudent PortalCourse Outline
About
About usPrivacy PolicyReportContact
Notes
Past Papers
Blogs
Todo
Analytics
    Current Subject
    🧩
    Parallel & Distributed Computing
    DC-323
    Progress0 / 35 topics
    Topics
    1. Asynchronous/synchronous computation/communication2. Concurrency control3. Fault tolerance4. GPU architecture and programming5. Heterogeneity6. Interconnection topologies7. Load balancing8. Memory consistency model9. Memory hierarchies10. Message passing interface (MPI)11. MIMD/SIMD12. Multithreaded programming13. Parallel algorithms & architectures14. Parallel I/O15. Performance analysis and tuning16. Power considerations17. Programming models18. Data parallel programming19. Task parallel programming20. Process-centric programming21. Shared memory programming22. Distributed memory programming23. Scalability and performance studies24. Scheduling25. Storage systems26. Synchronization27. Parallel computing tools28. CUDA, Swift29. Globus, Condor30. Amazon AWS, OpenStack31. Cilk32. GDB for parallel debugging33. Threads programming34. MPICH, OpenMP35. Hadoop, FUSE
    DC-323›MPICH, OpenMP
    Parallel & Distributed ComputingTopic 34 of 35

    MPICH, OpenMP

    7 minread
    1,251words
    Intermediatelevel

    MPICH (Message Passing Interface - MPICH)

    MPICH is an open-source implementation of the Message Passing Interface (MPI) standard, which is widely used for parallel and distributed computing. MPI is a specification for a message-passing system designed to enable processes to communicate with each other, typically across multiple nodes or computers in a distributed system or a cluster. MPICH provides the necessary tools and functions to implement MPI-based communication between processes, allowing for efficient data exchange in parallel applications.

    Key Concepts of MPICH

    1. Message Passing Interface (MPI):

      • MPI is a standard for parallel programming that enables processes to communicate by passing messages. It allows processes to run on different nodes (distributed memory) and exchange data, as opposed to relying on shared memory.
      • MPI defines a set of functions for point-to-point communication (e.g., MPI_Send and MPI_Recv), collective communication (e.g., MPI_Bcast and MPI_Reduce), and synchronization (e.g., MPI_Barrier).
    2. Communication Models:

      • Point-to-Point Communication: Involves direct communication between two processes, such as sending and receiving messages.
      • Collective Communication: Involves communication among multiple processes simultaneously, such as broadcasting data to all processes or reducing data across processes.
      • Synchronization: Ensures that processes work together in a coordinated manner, often through barriers or synchronized events.
    3. Distributed Memory:

      • MPICH is designed for distributed memory systems, where each process has its own memory space. Processes need to communicate explicitly through message passing, as opposed to shared memory models like OpenMP.
    4. MPICH Features:

      • Portability: MPICH is highly portable and can run on various architectures, from shared-memory systems to distributed-memory clusters.
      • Performance: MPICH is designed to maximize performance by efficiently managing the communication between processes, especially in high-performance computing (HPC) environments.
      • Scalability: MPICH scales well to large numbers of processes, making it suitable for supercomputers and distributed systems.

    Basic Example of MPI Program using MPICH

    Here’s a simple example of an MPI program that performs a basic communication between processes using MPICH:

    #include <mpi.h>
    #include <stdio.h>
    
    int main(int argc, char *argv[]) {
        int rank, size;
        MPI_Init(&argc, &argv);  // Initialize MPI environment
        MPI_Comm_rank(MPI_COMM_WORLD, &rank);  // Get process rank
        MPI_Comm_size(MPI_COMM_WORLD, &size);  // Get number of processes
    
        printf("Hello from process %d of %d\n", rank, size);
    
        MPI_Finalize();  // Finalize MPI environment
        return 0;
    }
    
    • In this example, MPI_Init initializes the MPI environment, MPI_Comm_rank gets the rank of each process, and MPI_Comm_size gets the total number of processes. After all processes print their message, MPI_Finalize cleans up the MPI environment.

    Advantages of MPICH:

    • Portability: MPICH is cross-platform and can run on various systems.
    • High Performance: Optimized for high-performance applications, particularly in scientific computing.
    • Extensive Support: MPICH has broad support for advanced MPI features and is widely used in academic and research institutions for parallel and distributed computing.

    OpenMP (Open Multi-Processing)

    OpenMP is an API (Application Programming Interface) for parallel programming in shared-memory environments. It provides a set of compiler directives, library routines, and environment variables to create parallel applications, especially for multi-core processors. OpenMP is widely used for parallelizing tasks within a single node (shared-memory systems) and is simpler to implement than message-passing models like MPI.

    Key Concepts of OpenMP

    1. Shared Memory:

      • OpenMP is designed for shared-memory systems, where all threads can access the same memory space. It allows multiple threads to operate on shared data structures and variables.
    2. Parallelism with Directives:

      • OpenMP uses compiler directives (pragmas) to specify parallel regions of code. These directives indicate which sections of the code should be executed by multiple threads.
      • #pragma Directives: The #pragma keyword is used to specify parallel regions in the code. For example:
        • #pragma omp parallel: Specifies a block of code to be executed in parallel by multiple threads.
        • #pragma omp for: Used to divide loops into iterations to be executed in parallel.
    3. Thread Management:

      • OpenMP allows the programmer to define the number of threads for parallel execution through environment variables or directives. The runtime system dynamically handles thread scheduling.
      • The threads share the same memory space but may have private variables and data.
    4. Work Sharing:

      • OpenMP divides work among threads using work-sharing constructs, such as for, sections, and single, which specify how the work should be divided.
    5. Synchronization:

      • OpenMP provides synchronization mechanisms to manage access to shared variables, such as critical sections, atomic operations, and barriers.
    6. Performance:

      • OpenMP is typically easier to implement than MPI because it relies on shared memory rather than explicit message-passing. However, OpenMP is generally limited to multi-core systems and does not scale as well across distributed memory systems as MPI does.

    Basic Example of OpenMP Program

    Here is an example of an OpenMP program that parallelizes a simple loop:

    #include <stdio.h>
    #include <omp.h>
    
    int main() {
        int i, sum = 0;
        #pragma omp parallel for reduction(+:sum) // Parallelize the loop and perform reduction on sum
        for (i = 0; i < 100; i++) {
            sum += i;
        }
        printf("Total sum is: %d\n", sum);
        return 0;
    }
    
    • In this example:
      • The #pragma omp parallel for directive tells the compiler to parallelize the loop.
      • The reduction(+:sum) clause ensures that each thread gets a private copy of sum to prevent data races and then combines the results at the end.

    Advantages of OpenMP:

    • Ease of Use: OpenMP is easier to implement for shared-memory systems compared to message-passing models like MPI.
    • Portable: OpenMP is supported by most major compilers, including GCC, Intel, and IBM, making it portable across different systems.
    • Flexibility: OpenMP can be used in a mixed-parallel approach with MPI (hybrid programming), enabling developers to write parallel programs that scale across both shared and distributed memory systems.

    MPICH vs OpenMP

    1. Memory Model:

      • MPICH: Designed for distributed-memory systems, where each process has its own private memory space, and communication happens through message-passing.
      • OpenMP: Designed for shared-memory systems, where multiple threads share the same memory space and work on data in parallel.
    2. Communication:

      • MPICH: Uses message passing for communication between processes. It’s suitable for distributed systems and clusters.
      • OpenMP: Relies on shared memory, and parallelism is achieved through threads that share data.
    3. Scalability:

      • MPICH: Scales well across distributed systems, enabling efficient communication between processes on different nodes, and can handle large-scale parallelism.
      • OpenMP: Primarily designed for multi-core systems and does not scale as efficiently as MPICH for large distributed systems.
    4. Ease of Use:

      • MPICH: Requires explicit management of processes and communication, making it more complex to implement compared to OpenMP.
      • OpenMP: Easier to use for parallelizing loops and other code in shared-memory systems, especially with minimal code changes required.
    5. Suitability:

      • MPICH: Best for large-scale distributed computing applications, where multiple machines are involved.
      • OpenMP: Best suited for parallelizing applications running on shared-memory multi-core processors, typically within a single node.

    Conclusion

    • MPICH and OpenMP are both important tools for parallel computing, but they are designed for different environments. MPICH is ideal for large-scale distributed computing, where communication between nodes is essential, while OpenMP is more suited for shared-memory systems, where multiple threads execute within the same memory space.
    • MPICH is a key player in parallel programming for distributed systems, while OpenMP simplifies the parallelization of programs running on multi-core processors within a single machine. Both tools are complementary in certain hybrid models, where MPI handles communication across machines, and OpenMP handles parallelism within each machine.
    Previous topic 33
    Threads programming
    Next topic 35
    Hadoop, FUSE

    Past Papers

    Open this section to load past papers

    Click on Show Past Papers to see past papers.
    On This Page
      Reading Stats
      Est. reading time7 min
      Word count1,251
      Code examples0
      DifficultyIntermediate