Jih-Wei Liang
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # 9 Advanced MPI Communication Techniques Part 1 ###### tags: `SS2021-IN2147-PP` ## Communication Protocols ### Create a “Logical” Topology * Establish overlap, e.g., halos * Define neighborhood information * Establish communication direction #### Arrange data items as needed * Define base elements * Create mapping of element to MPI process #### Understand frequency of needed communication ### Common Operation: Bidirectional Exchange ![](https://i.imgur.com/wZWyNJy.png =400x) ### How Messages are Transferred ![](https://i.imgur.com/qwPOb44.png) ![](https://i.imgur.com/RXyEizT.png) ### Send Variants ```c // Standard send operation MPI_Send // Buffered Send // Force the use of a send buffer // Returns immediately, but costs resources MPI_Bsend // Synchronous send // Wait!!! // Only returns once receive has started // Adds extra synchronization, but can be costly MPI_Ssend // Ready Send // "User" must "ensure" that receive has been posted // Enables faster communication, but needs implicit synchronization MPI_Rsend ``` ### Checking the UMQ with MPI_Probe/Iprobe ```c /* Receive Side */ // Blocks until a matching message was found // Output: status object MPI_Probe // Terminates after checking whether a matching messages is available // Output: yes/no, status object (if yes) // Can be used to overlap wait time with useful work MPI_Iprobe ``` ### Issue: Copy Overhead #### Eager Protocol > Copy too much times!!! ![](https://i.imgur.com/vLId5At.png) #### Rendevouz Protocol > Send envelope (metadata) ![](https://i.imgur.com/GBNI5ZY.png) #### Eager vs. Rendezvous Protocol * Eager Protocol * Suitable for short messsages * Rendezvous Protocol * Suitable for long messsages * Cross-over point (交叉點!!!) * MPI **`switch`** protocol based on ***message size*** * Typically defined as **`eager limit`** * Depends on system setup * Can often be modified #### Deadlock with Rendevouz Protocol > Both wait for Recv to get envelop and respond handshake ![](https://i.imgur.com/9NKfFZU.png) ### Bidirectional Send/Recv ```c // Combined blocking send and receive int MPI_Sendrecv (void *sendbuf, int sendcount, MPI_Datatype sendtype, int dest, int sendtag, void *recvbuf, int recvcount, MPI_Datatype recvtype, int source, MPI_Datatype recvtag, MPI_Comm comm, MPI_Status *status) // Combined send and receive buffer int MPI_Sendrecv_replace(void *buf, int count, MPI_Datatype datatype, int dest, int sendtag, int source, int recvtag, MPI_Comm comm, MPI_Status *status) ``` ## Nonblocking operations ![](https://i.imgur.com/93WhFSW.png =300x) * Useful for `long operations` * Waiting for events * Long I/O operations due to data size * Completion options * Separate wait operations * Polling * Interrupts ### Nonblocking P2P Operations in MPI ```c // Request object // User allocates object, but MPI maintains state // Initiated operations must be completed MPI_Request int MPI_Isend (void* buf, int count, MPI_Datatype dtype, int dest, int tag, MPI_Comm comm, MPI_Request* request) int MPI_Irecv (void* buf, int count, MPI_Datatype dtype, int source, int tag, MPI_Comm comm, MPI_Request* request) ``` #### Nonblocking Send Variants ```c MPI_Isend MPI_Ibsend MPI_Issend MPI_Irsend ``` #### Completion Operations ```c // Option 1: Blocking completion int MPI_Wait (MPI_Request *request, MPI_Status *status) // Option 2: Nonblocking/Polling completion int MPI_Test (MPI_Request *request, int *flag, MPI_Status *status) ``` ### How Messages are Transferred (Blocking) ![](https://i.imgur.com/NfSIK2B.png) ### How Messages are Transferred (Nonblocking) ![](https://i.imgur.com/sJGtuvk.png) ### MPI Terminology May Not Be What it Seems ![](https://i.imgur.com/jTHwztU.png) * Blocking routines * buffers can be reused * Nonblocking routines * buffers are still under MPI control ![](https://i.imgur.com/sTv2rhB.png) * Non-Local routines * Requires some (specific) other execution to run in another process * E.g., for MPI_Recv to complete, another process must call MPI_(X)send * Local routines * Not non-local (warning, MPI Standard currently being updated) ### Persistent Communication * Establish ***repeating communication*** * **`”Init” call`** to setup communication * **`MPI_Start`** to kickoff communication * Example ```c MPI_Request req; MPI_Status status; int msg [10]; // Same signature as MPI_Isend call MPI_Send_start(msg, 10, MPI_INT, 1, 42, MPI_COMM_WORLD, &req); // Information stored in request, which is inactive // Start the communication MPI_Start(&req) // request now active, basically a nonblocking operation // complete communication with Wait/Test routines MPI_Wait(&req, status); // request now inactive and can be reused MPI_Request_free(&req); ``` ## Collective Operations * Executed by `all processes` * Executed in the `same sequence` * Can be `blocking` or `non-blocking` ### MPI_Barrier ```c int MPI_Barrier (MPI_Comm comm) ``` ### Broadcast Communication: MPI_Bcast ```c // do not necessarily synchronize // MPI_Bcast is not sync!!!!! int MPI_Bcast (void *buf, int count, MPI_Datatype dtype, int root, MPI_Comm comm) ``` ### MPI_Gather ```c int MPI_Gather (void *sendbuf, int sendcount, MPI_Datatype sendtype, void* recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm) ``` ![](https://i.imgur.com/dmCwwqh.png) ### MPI_Scatter ```c int MPI_Scatter (void *sendbuf, int sendcount, MPI_Datatype sendtype, void* recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm) ``` ![](https://i.imgur.com/gtwmTl3.png) ### Other Collective Communication Routines ```c MPI_Gatherv MPI_Allgather MPI_Allgatherv MPI_Scatterv MPI_Alltoall MPI_Alltoallv MPI_Alltoallw ``` #### MPI_Gatherv ```c int MPI_Gatherv (void *sendbuf, int sendcount, MPI_Datatype sendtype, void* recvbuf, int *recvcount, int *displs, MPI_Datatype recvtype, int root, MPI_Comm comm) ``` ![](https://i.imgur.com/nisWrfr.png) #### MPI_Alltoall ```c int MPI_Alltoall(void* sendbuf, int sendcount, MPI_Datatype sendtype, void* recvbuf, int recvcount, MPI_Datatype recvtype, MPI_Comm comm) ``` ![](https://i.imgur.com/krFWc4S.png) ### MPI_Reduce ```c int MPI_Reduce (void* sbuf, void* rbuf, int count, MPI_Datatype dtype, MPI_Op op, int root, MPI_Comm comm) ``` ### Nonblocking Collectives (since MPI 3.0) ```c // Include MPI_Ibarrier, the non-blocking barrier // Returns request object int MPI_Ibcast(void* buffer, int count, MPI_Datatype datatype, int root, MPI_Comm comm, MPI_Request *request) ``` ## Communicators ### Communicators and MPI_COMM_WORLD * A process can have different ranks in different communicators * one MPI process can be in multiple communicators ### Creating New Communicators ```c int MPI_Comm_dup(MPI_Comm comm, MPI_Comm *newcomm) // Also exists as MPI_Comm_Idup ``` ### Creating Subcommunicators ```c // Creates new communicator(s) // All MPI processes that pass the same color, will be in same new communicator // Key argument determines the rank order in the new communicator int MPI_Comm_split(MPI_Comm comm, int color, int key, MPI_Comm *newcomm) // Communicators should be freed, when no longer in use int MPI_Comm_free(MPI_Comm *comm) ``` ### Example: Row and Column Communicators ![](https://i.imgur.com/BU9qEfo.png)

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully