<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div class="moz-cite-prefix"><br>
Dear user,<br>
<br>
Please note that this mailing list is exclusively intended to
discuss potential issues with the MPICH MPI implementation. Since
your question is about general MPI usage, we cannot provide you
with that assistance here. You will surely find assistance in this
kind of topics in general programming forums such as
stackoverflow, where some of our team members contribute as well.
Also, web search engines are likely to be a good resource in your
case.<br>
<br>
Best regards,<br>
Antonio<br>
<br>
<br>
On 12/05/2014 11:50 AM, Chafik sanaa wrote:<br>
</div>
<blockquote cite="mid:CADH=Oj-A5MpudZ9ie5zNZXwnb1=1vVLtkncH6WnF7n4GRGn7cQ@mail.gmail.com" type="cite">
<div dir="ltr">I have a table "tab[]" with 10 elements "0 | 1 | 2
| 3 | 4 | 5 | 6 | 7 | 8 | 9 |" I am sending with the Scatterv
function; 4 elements to the process 0 "|0 | 1 | 2 | 3 | 4| "and
6 elements to process 1 "| 5 | 6 | 7 | 8 | 9 | ", after I did
the summation of the value" add " to each element of the
received table which gives me a new table "afteradd[] "for each
process, I want this time collecting the both tables
"afteradd[]" and send them to the process 0, after a little
research I found that there's a GATHERV function which do that
but I do not know how ?<br>
<div> </div>
<div>program:</div>
<div>
<div>#include <malloc.h></div>
<div>#include <stdlib.h></div>
<div>#include <stdio.h></div>
<div>#include <time.h></div>
<div>#include "math.h"</div>
<div>#include "mpi.h"</div>
<div><br>
</div>
<div>int main(int argc, char** argv)</div>
<div>{</div>
<div><span class="" style="white-space:pre"> </span>int
taskid, ntasks;</div>
<div><span class="" style="white-space:pre"> </span>int
ierr, i, itask;</div>
<div><span class="" style="white-space:pre"> </span>int<span class="" style="white-space:pre"> </span>
sendcounts[2048], displs[2048], recvcount;</div>
<div><span class="" style="white-space:pre"> </span>double
**sendbuff, *recvbuff,*afteradd, buffsum,
buffsums[2048];</div>
<div><span class="" style="white-space:pre"> </span>double
inittime, totaltime;</div>
<div><span class="" style="white-space:pre"> </span>const int
nbr_etat = 10;</div>
<div><span class="" style="white-space:pre"> </span>double
tab[nbr_etat];</div>
<div><span class="" style="white-space:pre"> </span>for (int
i = 0; i < nbr_etat; i++)</div>
<div><span class="" style="white-space:pre"> </span>tab[i] =
i;</div>
<div><span class="" style="white-space:pre"> </span>int
nbr_elm[2] = { 4, 6 };</div>
<div><span class="" style="white-space:pre"> </span>int
dpl[2] = { 0, 4 };</div>
<div><span class="" style="white-space:pre"> </span>MPI_Init(&argc,
&argv);</div>
<div><span class="" style="white-space:pre"> </span>MPI_Comm_rank(MPI_COMM_WORLD,
&taskid);</div>
<div><span class="" style="white-space:pre"> </span>MPI_Comm_size(MPI_COMM_WORLD,
&ntasks);</div>
<div><span class="" style="white-space:pre"> </span>recvbuff
= (double *)malloc(sizeof(double)*nbr_etat);</div>
<div><span class="" style="white-space:pre"> </span>if
(taskid == 0)</div>
<div><span class="" style="white-space:pre"> </span>{</div>
<div><span class="" style="white-space:pre"> </span>sendbuff
= (double **)malloc(sizeof(double *)*ntasks);// run for 2
proc</div>
<div><span class="" style="white-space:pre"> </span>sendbuff[0]
= (double *)malloc(sizeof(double)*ntasks*nbr_etat);</div>
<div><span class="" style="white-space:pre"> </span>for (i =
1; i < ntasks; i++)</div>
<div><span class="" style="white-space:pre"> </span>{</div>
<div><span class="" style="white-space:pre"> </span>sendbuff[i]
= sendbuff[i - 1] + nbr_etat;</div>
<div><span class="" style="white-space:pre"> </span>}</div>
<div><span class="" style="white-space:pre"> </span>}</div>
<div><span class="" style="white-space:pre"> </span>else</div>
<div><span class="" style="white-space:pre"> </span>{</div>
<div><span class="" style="white-space:pre"> </span>sendbuff
= (double **)malloc(sizeof(double *)* 1);</div>
<div><span class="" style="white-space:pre"> </span>sendbuff[0]
= (double *)malloc(sizeof(double)* 1);</div>
<div><span class="" style="white-space:pre"> </span>}</div>
<div><br>
</div>
<div><span class="" style="white-space:pre"> </span>if
(taskid == 0){</div>
<div><br>
</div>
<div><span class="" style="white-space:pre"> </span>srand((unsigned)time(NULL)
+ taskid);</div>
<div><span class="" style="white-space:pre"> </span>for
(itask = 0; itask<ntasks; itask++)</div>
<div><span class="" style="white-space:pre"> </span>{</div>
<div><span class="" style="white-space:pre"> </span>int k;</div>
<div><span class="" style="white-space:pre"> </span>displs[itask]
= itask*nbr_etat;</div>
<div><span class="" style="white-space:pre"> </span>int s =
dpl[itask];</div>
<div><span class="" style="white-space:pre"> </span>sendcounts[itask]
= nbr_elm[itask];</div>
<div><br>
</div>
<div><br>
</div>
<div><span class="" style="white-space:pre"> </span>for (i =
0; i<sendcounts[itask]; i++)</div>
<div><span class="" style="white-space:pre"> </span>{</div>
<div><span class="" style="white-space:pre"> </span>k = i +
s;</div>
<div><span class="" style="white-space:pre"> </span>sendbuff[itask][i]
= tab[k];</div>
<div><span class="" style="white-space:pre"> </span>printf("+
%0.0f ", sendbuff[itask][i]);</div>
<div><span class="" style="white-space:pre"> </span>}</div>
<div><span class="" style="white-space:pre"> </span>printf("\n");</div>
<div><span class="" style="white-space:pre"> </span>}</div>
<div><span class="" style="white-space:pre"> </span>}</div>
<div><br>
</div>
<div><span class="" style="white-space:pre"> </span>recvcount
= nbr_elm[taskid];</div>
<div><br>
</div>
<div><span class="" style="white-space:pre"> </span>inittime
= MPI_Wtime();</div>
<div><br>
</div>
<div><span class="" style="white-space:pre"> </span>ierr =
MPI_Scatterv(sendbuff[0], sendcounts, displs, MPI_DOUBLE,</div>
<div><span class="" style="white-space:pre"> </span>recvbuff,
recvcount, MPI_DOUBLE,</div>
<div><span class="" style="white-space:pre"> </span>0,
MPI_COMM_WORLD);</div>
<div><br>
</div>
<div><span class="" style="white-space:pre"> </span>totaltime
= MPI_Wtime() - inittime;</div>
<div><br>
</div>
<div><span class="" style="white-space:pre"> </span></div>
<div><span class="" style="white-space:pre"> </span>buffsum =
0.0;</div>
<div><span class="" style="white-space:pre"> </span>int add =
3;</div>
<div><span class="" style="white-space:pre"> </span>afteradd
= (double *)malloc(sizeof(double)*nbr_etat);</div>
<div><span class="" style="white-space:pre"> </span>for (i =
0; i<recvcount; i++)</div>
<div><span class="" style="white-space:pre"> </span>{</div>
<div><span class="" style="white-space:pre"> </span>afteradd
[i]= add + recvbuff[i];</div>
<div><span class="" style="white-space:pre"> </span>}</div>
<div><span class="" style="white-space:pre"> </span>for (i =
0; i<recvcount; i++)</div>
<div><span class="" style="white-space:pre"> </span>{</div>
<div><span class="" style="white-space:pre"> </span>printf("*
%0.0f<span class="" style="white-space:pre"> </span>",
afteradd[i]);</div>
<div><span class="" style="white-space:pre"> </span>}</div>
<div><span class="" style="white-space:pre"> </span>printf("\n");<span class="" style="white-space:pre"> </span>
</div>
<div><span class="" style="white-space:pre"> </span>if
(taskid == 0)</div>
<div><span class="" style="white-space:pre"> </span>{</div>
<div><span class="" style="white-space:pre"> </span>free(sendbuff[0]);</div>
<div><span class="" style="white-space:pre"> </span>free(sendbuff);</div>
<div><span class="" style="white-space:pre"> </span>}</div>
<div><span class="" style="white-space:pre"> </span>else</div>
<div><span class="" style="white-space:pre"> </span>{</div>
<div><span class="" style="white-space:pre"> </span>free(sendbuff[0]);</div>
<div><span class="" style="white-space:pre"> </span>free(sendbuff);</div>
<div><span class="" style="white-space:pre"> </span>free(recvbuff);</div>
<div><span class="" style="white-space:pre"> </span>}</div>
<div><span class="" style="white-space:pre"> </span>MPI_Finalize();</div>
<div><br>
</div>
<div>}</div>
<div><br>
</div>
</div>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
discuss mailing list <a class="moz-txt-link-abbreviated" href="mailto:discuss@mpich.org">discuss@mpich.org</a>
To manage subscription options or unsubscribe:
<a class="moz-txt-link-freetext" href="https://lists.mpich.org/mailman/listinfo/discuss">https://lists.mpich.org/mailman/listinfo/discuss</a></pre>
</blockquote>
<br>
<br>
<pre class="moz-signature" cols="72">--
Antonio J. Peña
Postdoctoral Appointee
Mathematics and Computer Science Division
Argonne National Laboratory
9700 South Cass Avenue, Bldg. 240, Of. 3148
Argonne, IL 60439-4847
<a class="moz-txt-link-abbreviated" href="mailto:apenya@mcs.anl.gov">apenya@mcs.anl.gov</a>
<a class="moz-txt-link-abbreviated" href="http://www.mcs.anl.gov/~apenya">www.mcs.anl.gov/~apenya</a></pre>
</body>
</html>