#include &lt;mpi.h&gt;<br>#include &lt;stdio.h&gt;<br>#include &lt;stdlib.h&gt;<br>#define  TRUE 1<br>#include &quot;math.h&quot;<br>#include &lt;time.h&gt;<br>int IncOrder(const void *e1, const void *e2 ) <br>    {<br>          return (*((int *)e1) - *((int *)e2));<br>

    }<br><br>DisplayError(char *str)<br>{<br>    printf(&quot;Error: %s \n&quot;,str);<br>} <br><br>int Partition(int *arr, int left, int right) {<br>int i = left, j = right;<br>int tmp;<br>int pivot = arr[(left + right) / 2];<br>

/* partition */<br>while (i &lt;= j) {<br>while (arr[i] &lt; pivot)<br>i++;<br>while (arr[j] &gt; pivot)<br>j--;<br>if (i &lt;= j) {<br>tmp = arr[i];<br>arr[i] = arr[j];<br>arr[j] = tmp;<br>i++;<br>j--;<br>}<br>}<br>return j;<br>

}<br><br>int PowerOf2(int num)<br>{<br>    int i;<br><br>    i=1;<br><br>    while(num&gt;0)<br>    {<br>        num--;<br>        i=i*2;<br>    }<br>    <br>    return i;<br>}<br><br><br>PQuickSort(int *Array,int start,int end,int m,int id,int MyRank)<br>

{<br>    int j;<br>    int r;<br>    int LocalLength;<br>    int *tmp;<br>    //int newsize;<br>    MPI_Status status;<br>    LocalLength=-1;<br><br>    if(m==0)<br>{<br>    if(MyRank==id)<br><br>    qsort(Array, end-start, sizeof *Array, IncOrder);    <br>

    return 0;<br>}    <br><br>if(MyRank==id)<br>{<br>    r=Partition(Array,start,end);    <br>    LocalLength=end-r;    <br>MPI_Send(&amp;LocalLength,1,MPI_INT,id+PowerOf2(m-1),MyRank,MPI_COMM_WORLD);<br><br>if(LocalLength!=0)<br>

<br>MPI_Send(Array+r+1,LocalLength,MPI_INT,id+PowerOf2(m-1),MyRank,MPI_COMM_WORLD);<br>    }<br><br>    if(MyRank==id+PowerOf2(m-1))<br>    {<br>        MPI_Recv(&amp;LocalLength,1,MPI_INT,id,id,MPI_COMM_WORLD,&amp;status);<br>

        <br>       if(LocalLength!=0)<br>        {<br>             tmp=(int *)malloc(LocalLength*sizeof(int));<br>             if(tmp==0)<br>                 DisplayError(&quot;Malloc memory error!&quot;);<br>              MPI_Recv(tmp,LocalLength,MPI_INT,id,id,MPI_COMM_WORLD,&amp;status);<br>

        }<br>    }<br><br>    j=r-1-start;    <br>    MPI_Bcast(&amp;j,1,MPI_INT,id,MPI_COMM_WORLD);<br>    if(j&gt;0)<br>        PQuickSort(Array,start,r-1,m-1,id,MyRank);<br><br>    j=LocalLength;    <br>    MPI_Bcast(&amp;j,1,MPI_INT,id,MPI_COMM_WORLD);<br>

    if(j&gt;0)<br>        PQuickSort(tmp,0,LocalLength-1,m-1,id+PowerOf2(m-1),MyRank);<br><br>    if((MyRank==id+PowerOf2(m-1)) &amp;&amp; (LocalLength!=0))<br>        MPI_Send(tmp,LocalLength,MPI_INT,id,id+PowerOf2(m-1),MPI_COMM_WORLD);<br>

<br>    if((MyRank==id) &amp;&amp; (LocalLength!=0))<br>        MPI_Recv(Array+r+1,LocalLength,MPI_INT,id+PowerOf2(m-1),id+PowerOf2  (m-1),MPI_COMM_WORLD,&amp;status);<br><br>}<br><br>int LogBase2(int num)<br>{<br>    int i, j;<br>

<br>    i=1;    <br>    j=2;<br><br>    while(j&lt;num)<br>    {<br>        j=j*2;<br>        i++;<br>    }<br><br>    if(j&gt;num)<br>        i--;<br><br>    return i;<br>}<br><br><br>main(int argc,char *argv[])<br>{<br>

    int     ArraySize;<br>    int     *Array;<br>    int    MyRank, npes;<br>    int     i;<br>    int     m ;<br>    double     t1,t2,t3;<br><br><br>    //MPI_Status status;<br>    MPI_Init(&amp;argc,&amp;argv);<br>        <br>

    MPI_Comm_rank(MPI_COMM_WORLD,&amp;MyRank);    <br><br>    MPI_Comm_size(MPI_COMM_WORLD,&amp;npes);    <br>    <br>    if(MyRank==0)<br>    {<br>        ArraySize=1000000;<br>        printf(&quot;%d\n&quot;,ArraySize);<br>

        Array=(int *)malloc(ArraySize*sizeof(int));<br><br>        if(Array==0) <br>            printf(&quot;Malloc memory error!&quot;);<br><br>        srand(396);<br>        for(i=0;i&lt;ArraySize;i++)<br>        {<br>
            Array[i]=(int)rand()%1000;<br>
        }<br>        printf(&quot;\n&quot;);<br>    }<br>    <br>    m=LogBase2(npes);<br><br>    MPI_Bcast(&amp;ArraySize,1,MPI_INT,0,MPI_COMM_WORLD);<br>        t1=MPI_Wtime();<br>    PQuickSort(Array,0,ArraySize-1,m,0,MyRank);<br>

        t2=MPI_Wtime();<br>        t3=t2-t1;<br>    <br>    if(MyRank==0)<br>    {<br>        for(i=0;i&lt;ArraySize;i++)<br>        {<br>            printf(&quot;%10d&quot;,Array[i]);<br>                printf(&quot;\t&quot;);<br>

        }<br>        printf(&quot;\n&quot;);<br>    printf(&quot;MPI_time :%6.3f\n&quot;,t3);<br>        <br>    }<br><br>    MPI_Finalize();        <br>    return 0;<br>}<br><br>when I increase the number of process this code take more time. :(<br>

<br>