MPI基礎入門 1

2021-10-20 13:42:26 字數 2056 閱讀 7381

mpi將一組程序定義成乙個通訊器.每個程序都有乙個識別符號range.

int

mpi_init

(int argc,

char

* ar**)

建立乙個通訊器,這個通訊器就包含了所有的程序,預設為mpi_comm_world,很形象的定義乙個mpi的共有世界。

argc表示變數的數目,ar**是具體的傳入引數

int

mpi_finalize

()

關閉mpi的執行環境。

int

mpi_comm_rank

(mpi_comm comm,

int*rank)

用來確定當前程序在本通訊器裡的程序號,建議主程序為0.

int

mpi_comm_size

(mpi_comm comm,

int*size)

用來返回當前的通訊器裡有多少個程序.

同步訊息傳輸

int

mpi_send

(void

*buf,

int count, mpi_datatype datatype,

int dest,

int tag, mpi_comm comm)

阻塞訊息傳送

訊息資料:

buf:所發訊息的首位址

count:傳送的資料的個數

datatype:傳送資料的資料型別

訊息信封:

dest:接受訊息的程序的標識號

tag:訊息的標籤

comm:通訊器

int

mpi_recv

(void

*buf,

int count, mpi_datatype datatype,

int source,

int tag, mpi_comm comm, mpi_status*status)

只要沒有新的訊息,這個程序就會阻塞

buf:所發訊息的首位址

count:傳送的資料的個數

datatype:傳送資料的資料型別

訊息信封:

dest:接受訊息的程序的標識號

tag:訊息的標籤

comm:通訊器

status:表示接受訊息時的返回狀態(mpi_source,mpi_tag,mpi_error)

int

mpi_reduce

(void

*sendbuf,

void

*recvbuf,

int count,mpi_datatype datatype, mpi_op op,

int root, mpi_comm comm)

sendbuf:傳送訊息的首位址

recvbuf:接受訊息的首位址

count:傳送的資料的個數

datatype:傳送資料的資料型別

op:規約操作

-mpi_max : 最大值

– mpi_min : 最小值

– mpi_sum : 和

– mpi_prod : 積

– mpi_land : 邏輯與

– mpi_band : 按位與

– mpi_lor 邏輯或

– mpi_bor : 按位或

– mpi_lxor : 邏輯異或

– mpi_bxor : 按位異或

root:接受訊息的程序的程序號

comm:通訊器

int

mpi_bcast

(void

*buffer,

int count, mpi_datatype datatype,

int root, mpi_comm comm)

允許從根程序廣播到組中的所有其他程序。其引數與mpi_send()函式的引數相同。

MPI入門例項講解

mpi hello.cpp include include mpi int main int argv,char argc mpi init argv,argc cout hello world 編譯 mpicxx o mpi hello mpi hello.cpp 執行 mpirun np 3 m...

mpi學習日誌 1 mpi與python

mpi是什麼?它用來幹什麼?mpi是資訊傳遞介面 message passing inte ce 簡單來說就是乙個用來實現程序通訊的庫.它很多時候用於並行演算法的設計.下面我們先使用windows環境下python語言來了解mpi的使用.mpi在python的環境還是很好配置的.首先你得安裝好pyt...

MPI基礎知識

mpi6個常用的函式 1.mpi init 2.mpi comm size 3.mpi comm rank 4.mpi send 5.mpi recv 6.mpi finalize mpi集群通訊函式 1.廣播broadcast int mpi bcast void buffer,傳送 接收buf ...