蝦想承為工程師
    • 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 No publishing access yet

      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.

      Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Explore these features while you wait
      Complete general settings
      Bookmark and like published notes
      Write a few more notes
      Complete general settings
      Write a few more notes
      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
    • Make a copy
    • 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 Make a copy 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 No publishing access yet

    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.

    Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Explore these features while you wait
    Complete general settings
    Bookmark and like published notes
    Write a few more notes
    Complete general settings
    Write a few more notes
    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
    ## 介紹訊息傳遞介面 (Message Passing Interface, MPI) 訊息傳遞介面(Message Passing Interface,MPI)是一套針對分散式記憶體系統中並行計算所設計的標準化通訊協定,它定義了一組函式庫,允許在不同處理器或計算節點之間進行資料交換與同步,MPI 被廣泛應用於高效能計算(HPC)領域,特別是在超級電腦和電腦叢集等非共享主記憶體環境中,用於執行需要大量計算資源的應用程式。 MPI 本身並非一個具體的程式庫,而是一個通訊標準,它規定了訊息傳遞程式庫的語法和語義,其標準化確保了程式碼的可移植性,使得開發人員能夠編寫一次程式碼,並在幾乎所有分散式記憶體架構上運行,這種跨不同硬體和軟體平台的可移植性,使得 MPI 成為分散式深度學習環境中一個極具吸引力的選擇。 此外,MPI 存在多個經過優化的實作版本,例如 Open MPI、MPICH、Intel MPI 和 MVAPICH2 等,這些不同的實作通常針對特定的網路互連技術(如 InfiniBand、Omni-Path)和處理器架構(如 Intel Xeon、GPU)進行了優化,使得使用者可以根據其具體的硬體和效能需求選擇最適合的程式庫。 ## MPI 的核心概念 MPI 的設計核心在於「訊息傳遞」模型,這是一種適用於分散式記憶體系統的平行運算範式。在這種模型中,每個處理器(或行程)擁有獨立的記憶體空間,無法直接存取其他處理器的資料。因此,行程之間必須透過明確的訊息傳遞來交換資料,以下是 MPI 的幾個核心概念。 ### Communicator 與 Process 在 MPI 中,通訊群組(communicator)是一組處理器(或行程)的集合,這些處理器可以相互通訊,每個通訊群組都定義了一個獨立的通訊範圍,預設的通訊群組是 MPI_COMM_WORLD,它包含程式啟動時所有的處理器。 每個處理器在通訊群組中都被分配一個唯一的「整數標示符」(rank),這是一個從 0 開始的整數,用於標識處理器在該群組中的身份,例如,在 MPI_COMM_WORLD 中,如果有 6 個處理器,它們的排名分別為 0~5。 ![image](https://hackmd.io/_uploads/r157-HBA1x.png) ### Point-to-Point Communication 點對點通訊涉及兩個特定處理程序之間的直接訊息傳遞 * MPI_Send:此操作將訊息從一個處理程序發送到另一個處理程序。 發送操作需要指定目標處理程序的秩、要發送的資料、資料類型以及一個用於訊息識別的標籤(Tag) 。   * MPI_Recv:此操作用於接收訊息。 接收操作需要指定來源處理程序的秩(可以使用 MPI_ANY_SOURCE 接收來自任何處理程序的訊息)、儲存接收資料的緩衝區、資料類型、預期的標籤(可以使用 MPI_ANY_TAG 接收任何標籤的訊息)以及一個用於獲取接收訊息狀態的狀態物件。 ![image](https://hackmd.io/_uploads/B1SsEBSC1l.png) MPI 還提供了阻塞和非阻塞兩種點對點通訊模式,阻塞通訊操作在完成發送或接收操作之前不會返回,而非阻塞通訊操作(如 MPI_Isend 和 MPI_Irecv)則允許處理程序在通訊進行的同時執行其他計算任務,從而提高程式的並行效率。 ### Collective Communication 集體通訊涉及通訊器(或其子群組)中所有處理程序之間的通訊,其中一些重要的包括 ![image](https://hackmd.io/_uploads/BkqRrBBAJg.png) ![image](https://hackmd.io/_uploads/HyWMBHHC1e.png) ## MPI 在深度學習中的應用 MPI 在深度學習領域的主要應用是實現跨多個計算節點和 GPU 的分散式訓練,以加速模型訓練過程並處理更大規模的資料集,以下列舉了 MPI 在深度學習中的一些具體應用方式 1. 資料並行(Data Parallel) 2. 模型並行(Model Parallel) 3. 混合並行(Hybrid Parallel) 詳細內容請參考[分散式訓練的類型:Data Parallel vs. Model Parallel vs. Pipeline Parallel](https://hackmd.io/@lcaMuWOwR1Ox5o5yeTEupA/ByK-wgNAyg) MPI 的靈活性使其能夠支援深度學習中各種並行化策略,以適應不同的模型和資料特性,無論是資料規模還是模型規模成為瓶頸,MPI 都提供了必要的通訊原語來實現有效的並行化,資料並行受益於高效的全歸約操作以實現梯度同步,而模型並行則需要更細粒度的中間結果通訊,MPI 都能夠處理這些需求。 此外,MPI 與流行的深度學習框架的整合降低了在高效能計算叢集上使用分散式訓練的門檻,深度學習從業者無需直接編寫複雜的 MPI 程式碼,即可利用框架提供的抽象層來輕鬆地在分散式環境中訓練模型。 ## MPI 的優缺點 ### 優點 * 可擴展性(Scalability):MPI 能夠無縫地將深度學習模型擴展到多個節點和 GPU 上,非常適合處理大規模資料集和複雜模型。   * 可移植性(Portability):作為一個標準化的介面,MPI 確保了深度學習應用程式可以在不同的高效能計算環境和架構之間輕鬆移植。   * 效能(Performance):MPI 的實作通常針對底層硬體和網路互連技術進行了高度優化,從而實現高效的通訊和更快的訓練速度。 ### 缺點 * 複雜性(Complexity):相較於某些深度學習框架提供的高階分散式訓練抽象,使用 MPI 進行程式設計可能更為複雜。 * 除錯挑戰 (Debugging Challenges):由於分散式 MPI 應用程式的並行和分散式特性,除錯可能非常困難,需要專門的工具和技術。   * 開銷 (Overhead):MPI 會引入通訊開銷,對於小規模資料集或簡單模型而言,這種開銷可能會抵消並行化帶來的效益。

    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
    Sign in via Facebook Sign in via X(Twitter) Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    By signing in, you agree to our terms of service.

    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