MPI並行實現列舉排序

2021-06-22 04:37:08 字數 1573 閱讀 4392

mpi並行實現列舉排序,**如下:

#include #include #include /*

* 函式名: main

* 功能: 主函式,實現列舉排序

* 輸入:argc為命令列引數個數;

* argv為每個命令列引數組成的字串陣列

* 輸出:返回1代表程式正常結束

*/int main(int argc,char *argv)

else

if(myid==0)

} return 1;}/*

* 函式名: errmsg

* 功能: 讀入待排序序列的長度

* 輸入: 無

* 輸出: 返回待排序序列的長度

*/int getdatasize()

return i;}/*

* 函式名: errmsg

* 功能: 輸出錯誤資訊

* 輸入: msg:出錯資訊字串

* 輸出:返回1代表程式正常結束

*/int errmsg(char *msg)

example:

編譯:mpicc rank_sort.c –o rank

執行:可以使用命令 mpirun –np size rank來執行該串匹配程式,其中size是所使用的處理器個數。本例項中使用了size=3個處理器。

mpirun –np 3 rank

執行結果:

input the data size :30

please input seed:396

random numbers:

2706       3767       9343       9387       8259       2684        833       5815       7745         21       3250       6612       2836       7702         88         9407        545       2622       3538       7774       3156       4385       2856       6387         19       9982       5602       2571        706        5412

output:

19         21         88        545        706        833       2571       2622       2684       2706       2836       2856       3156       3250       3538       3767       4385       5412       5602       5815       6387       6612       7702       7745       7774       8259       9343       9387       9407       9982

說明:該執行例項中可以動態的輸入待排序序列的長度,這裡選擇的是60。隨機數的種子設為396

列舉排序各種並行之MPI

宣告 執行mpi程式之前必須先將mpich配置好,可以參照 include stdafx.h include mpi.h 一定好放到stafx.h後面 include include include include 函式名 getrank 功能 計算所屬部分資料的秩 比該元素小的數的個數 輸入 hx...

MPI 列舉排序實現

dfdfdfssfd.cpp 定義控制台應用程式的入口點。include stdafx.h include stdlib.h include stdio.h include mpi.h void countrank int rank,int perlen,int len,int p,int tota...

運用MPI並行實現歸併排序

include include include define max size 10000 void merge int a,int b,int start,int middle,int end else if na1 middle if na2 end for i start i end i vo...