原创 CPP-operator==,
如果已經定義了operator==,那麼operator!=很容易實現,只要調用operator==,然後取反。 bool Array::operator!=(const Array& v) const { return
原创 Example-2-MPI_Scatterv,MPI_Send,MPI_Recv
此例將例1擴展一點,根進程分散數據後,進程間再進行數據交換,具體來說,第i個進程發送一定量的數據到第i+1和第i-1個進程。注意每個進程要更新當前數據,數據交換過程如下圖所示: 代碼如下: #include "mpi.h" #i
原创 boost mpi send recv-vector
接上例:如果vector中元素是class,要將他們分給不同進程,程序如下: #include "stdafx.h" #include <boost/mpi.hpp> #include <iostream> #include <v
原创 MPI-Communication modes(通訊模式)
MPI提供四種通訊模式: “MPI defines four communication modes which are selected via the specific SEND routine used. The comm
原创 CPP-類的位置(Placement of class)
當寫簡單程序時候,所有東西可以放在一個文件中,但程序較大時,這樣做並不明智。前面我們討論過如何將程序分割,即應該成對的構建程序文件。對每個函數定義文件(definition),應該有相應的函數聲明頭文件(declaration).
原创 CPP-類定義(Class definitions)
Member function 的declaration和普通函數一樣。僅有的差別是放在類的定義裏面。同樣數據成員的declaration和普通變量也一樣,只是放在類的定義裏面。保留字public和private用來實現信息隱藏。
原创 Example-1-MPI_Scatterv and MPI_Gather
目的:利用例子說明collective communication函數功能 Example 1: This program shows how to use MPI_Scatterv and MPI_Gather. 假設有np個
原创 Example of MPI_Type_struct
#include "mpi.h" #include <stdio.h> #include <stdlib.h> #include <iostream> using namespace std; #define NELEM 25
原创 MPI集體通訊(一)
集體通訊(collective communications) 能夠在MPI指定的通訊域中所有的進程之間傳遞數據。MPI提供以下幾種集體通訊例子: 1) 同步所有進程 2)全局通訊函數:包括Broadcase,Gather,S
原创 MPI_Probe-Dynamically allocate memory
某些情況下,接收者不知道消息尺寸,此時當然可以用一個足夠大的空間去接收,但我們可以用MPI_Probe去首先探測消息尺寸,然後再分配相應空間,然後再正式接收消息,可以認爲MPI_Probe和MPI_Recv很類似,只是不真正執行接
原创 MPI-Avoid deadlock
MPI-DEADLOCK ISSUE! 設進程i向i+1發送數據(循環進行,週期性拓撲)。進行i可以用標準模式向右邊近鄰發送數據,然後用blocking模式接收左邊近鄰的數據。 MPI_Comm_size(comm,&size)
原创 Example-3-Using MPI_Sendrecv
例2中,每個進程既接收又發送數據,可以利用MPI_Sendrecv函數進行簡化,此例和例2功能完全相同,首先看MPI_Sendrecv的用法 代碼如下: MPI_Sendrecv( void *sendbuf //initial
原创 Boost mpi gatherv example
#include "stdafx.h" #include <boost/mpi.hpp> #include <iostream> #include <vector> namespace mpi = boost::mpi; #define
原创 Boost MPI scatter
boost::mpi::scatter 可以把一個vector中的元素傳遞給其他所有進程。 #include "stdafx.h" #include <boost/mpi.hpp> #include <boost/serializatio
原创 boost mpi send recv-vector<class>
接上例:如果vector中元素是class,要將他們分給不同進程,程序如下: #include "stdafx.h" #include <boost/mpi.hpp> #include <iostream> #include <vecto