[問題] mpi c改成分散式運算架構

看板C_and_CPP (C/C++)作者 (CEO)時間13年前 (2012/10/10 01:04), 編輯推噓2(2011)
留言13則, 4人參與, 最新討論串1/1
我要做多台雲端一起合作執行code,好像俗稱跨節點加分散式運算 以下是我原code #include <stdio.h> #include <time.h> main(){ int max = 10000; int i; time_t now; time(&now); for(i = 1; i <= max;i++){ printf("%d\n",i); } time_t now2; time(&now2); printf("It's %s\n", ctime(&now)); printf("It's %s", ctime(&now2)); } 後來我加了mpi #include <stdio.h> #include <mpi.h> #include <time.h> int main (argc, argv) int argc; char *argv[]; { int rank, size; MPI_Init (&argc, &argv); /* starts MPI */ MPI_Comm_rank (MPI_COMM_WORLD, &rank); /* get current process id */ MPI_Comm_size (MPI_COMM_WORLD, &size); /* get number of processes */ int max = 10000 int i; time_t now; time(&now); for(i = 0; i <= max;i++){ printf("%d\n",i); } time_t now2; time(&now2); printf("It's %s\n", ctime(&now)); printf("It's %s", ctime(&now2)); printf( "Hello world from process %d of %d\n", rank, size ); MPI_Finalize(); return 0; } 可是運算後好像不大對,變成每個節點都各算一遍, 而非我所要的各節點一起分工 請問有大大寫過mpi的嗎? 開發平台(Platform): (Ex: VC++, GCC, Linux, ...) 額外使用到的函數庫(Library Used): (Ex: OpenGL, ...) 問題(Question): 餵入的資料(Input): 預期的正確結果(Expected Output): 錯誤結果(Wrong Output): 程式碼(Code):(請善用置底文網頁, 記得排版) 補充說明(Supplement): -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 123.193.205.156

10/10 01:51, , 1F
為什麼你覺得迴圈把 i = 1 改成 i = 0 就可能有效果了...
10/10 01:51, 1F

10/10 01:52, , 2F
多了 rank 跟 size 你不知道怎麼用嗎?
10/10 01:52, 2F

10/10 06:05, , 3F
mpi 跟 雲端沒關係吧 @@
10/10 06:05, 3F

10/10 06:07, , 4F
用rank size知道自己的process該做的事再設定i值跟停止條件
10/10 06:07, 4F

10/10 12:44, , 5F
回t大 i=0改i=1那不是重點,想問後來增加的mpi架構是否改錯?
10/10 12:44, 5F

10/10 12:49, , 6F
回d大 聽說跨節點要用mpi,剛好在做遠端電腦。設定怎麼改阿?
10/10 12:49, 6F

10/10 17:37, , 7F
你的測試程式測不出什麼吧? 把 rank size 印出來比較實在
10/10 17:37, 7F

10/10 17:38, , 8F
可以把網卡號碼印在別台電腦出來試看看
10/10 17:38, 8F

10/11 16:54, , 9F
It's Thu Oct 11 16:50:48 2012It's Thu Oct 11 16:51:09 201
10/11 16:54, 9F

10/11 16:56, , 10F
Hello world from process 0 of 1;網卡印?我在用linux指令作
10/11 16:56, 10F

10/12 09:32, , 11F
印出結果:那兩段時間及那串process和1~10000
10/12 09:32, 11F

10/14 15:35, , 12F
for(i=rank; i<max; i+=size), 你要的是這個東西嗎?
10/14 15:35, 12F

10/14 15:44, , 13F
另外除了mpi外, 你應該還要去研究什麼是平行處理
10/14 15:44, 13F
文章代碼(AID): #1GT5aXnh (C_and_CPP)
文章代碼(AID): #1GT5aXnh (C_and_CPP)