<meta http-equiv="Content-Type" content="text/html; charset=utf-8"><div dir="ltr">hi, thanks</div><div class="gmail_extra"><br><div class="gmail_quote">2014-12-05 19:37 GMT+01:00 "Antonio J. Peña" <span dir="ltr"><<a href="mailto:apenya@mcs.anl.gov" target="_blank">apenya@mcs.anl.gov</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div bgcolor="#FFFFFF" text="#000000">
<div><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<div><div class="h5"><br>
<br>
<br>
On 12/05/2014 11:50 AM, Chafik sanaa wrote:<br>
</div></div></div>
<blockquote type="cite"><div><div class="h5">
<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 style="white-space:pre-wrap"> </span>int
taskid, ntasks;</div>
<div><span style="white-space:pre-wrap"> </span>int
ierr, i, itask;</div>
<div><span style="white-space:pre-wrap"> </span>int<span style="white-space:pre-wrap"> </span>
sendcounts[2048], displs[2048], recvcount;</div>
<div><span style="white-space:pre-wrap"> </span>double
**sendbuff, *recvbuff,*afteradd, buffsum,
buffsums[2048];</div>
<div><span style="white-space:pre-wrap"> </span>double
inittime, totaltime;</div>
<div><span style="white-space:pre-wrap"> </span>const int
nbr_etat = 10;</div>
<div><span style="white-space:pre-wrap"> </span>double
tab[nbr_etat];</div>
<div><span style="white-space:pre-wrap"> </span>for (int
i = 0; i < nbr_etat; i++)</div>
<div><span style="white-space:pre-wrap"> </span>tab[i] =
i;</div>
<div><span style="white-space:pre-wrap"> </span>int
nbr_elm[2] = { 4, 6 };</div>
<div><span style="white-space:pre-wrap"> </span>int
dpl[2] = { 0, 4 };</div>
<div><span style="white-space:pre-wrap"> </span>MPI_Init(&argc,
&argv);</div>
<div><span style="white-space:pre-wrap"> </span>MPI_Comm_rank(MPI_COMM_WORLD,
&taskid);</div>
<div><span style="white-space:pre-wrap"> </span>MPI_Comm_size(MPI_COMM_WORLD,
&ntasks);</div>
<div><span style="white-space:pre-wrap"> </span>recvbuff
= (double *)malloc(sizeof(double)*nbr_etat);</div>
<div><span style="white-space:pre-wrap"> </span>if
(taskid == 0)</div>
<div><span style="white-space:pre-wrap"> </span>{</div>
<div><span style="white-space:pre-wrap"> </span>sendbuff
= (double **)malloc(sizeof(double *)*ntasks);// run for 2
proc</div>
<div><span style="white-space:pre-wrap"> </span>sendbuff[0]
= (double *)malloc(sizeof(double)*ntasks*nbr_etat);</div>
<div><span style="white-space:pre-wrap"> </span>for (i =
1; i < ntasks; i++)</div>
<div><span style="white-space:pre-wrap"> </span>{</div>
<div><span style="white-space:pre-wrap"> </span>sendbuff[i]
= sendbuff[i - 1] + nbr_etat;</div>
<div><span style="white-space:pre-wrap"> </span>}</div>
<div><span style="white-space:pre-wrap"> </span>}</div>
<div><span style="white-space:pre-wrap"> </span>else</div>
<div><span style="white-space:pre-wrap"> </span>{</div>
<div><span style="white-space:pre-wrap"> </span>sendbuff
= (double **)malloc(sizeof(double *)* 1);</div>
<div><span style="white-space:pre-wrap"> </span>sendbuff[0]
= (double *)malloc(sizeof(double)* 1);</div>
<div><span style="white-space:pre-wrap"> </span>}</div>
<div><br>
</div>
<div><span style="white-space:pre-wrap"> </span>if
(taskid == 0){</div>
<div><br>
</div>
<div><span style="white-space:pre-wrap"> </span>srand((unsigned)time(NULL)
+ taskid);</div>
<div><span style="white-space:pre-wrap"> </span>for
(itask = 0; itask<ntasks; itask++)</div>
<div><span style="white-space:pre-wrap"> </span>{</div>
<div><span style="white-space:pre-wrap"> </span>int k;</div>
<div><span style="white-space:pre-wrap"> </span>displs[itask]
= itask*nbr_etat;</div>
<div><span style="white-space:pre-wrap"> </span>int s =
dpl[itask];</div>
<div><span style="white-space:pre-wrap"> </span>sendcounts[itask]
= nbr_elm[itask];</div>
<div><br>
</div>
<div><br>
</div>
<div><span style="white-space:pre-wrap"> </span>for (i =
0; i<sendcounts[itask]; i++)</div>
<div><span style="white-space:pre-wrap"> </span>{</div>
<div><span style="white-space:pre-wrap"> </span>k = i +
s;</div>
<div><span style="white-space:pre-wrap"> </span>sendbuff[itask][i]
= tab[k];</div>
<div><span style="white-space:pre-wrap"> </span>printf("+
%0.0f ", sendbuff[itask][i]);</div>
<div><span style="white-space:pre-wrap"> </span>}</div>
<div><span style="white-space:pre-wrap"> </span>printf("\n");</div>
<div><span style="white-space:pre-wrap"> </span>}</div>
<div><span style="white-space:pre-wrap"> </span>}</div>
<div><br>
</div>
<div><span style="white-space:pre-wrap"> </span>recvcount
= nbr_elm[taskid];</div>
<div><br>
</div>
<div><span style="white-space:pre-wrap"> </span>inittime
= MPI_Wtime();</div>
<div><br>
</div>
<div><span style="white-space:pre-wrap"> </span>ierr =
MPI_Scatterv(sendbuff[0], sendcounts, displs, MPI_DOUBLE,</div>
<div><span style="white-space:pre-wrap"> </span>recvbuff,
recvcount, MPI_DOUBLE,</div>
<div><span style="white-space:pre-wrap"> </span>0,
MPI_COMM_WORLD);</div>
<div><br>
</div>
<div><span style="white-space:pre-wrap"> </span>totaltime
= MPI_Wtime() - inittime;</div>
<div><br>
</div>
<div><span style="white-space:pre-wrap"> </span></div>
<div><span style="white-space:pre-wrap"> </span>buffsum =
0.0;</div>
<div><span style="white-space:pre-wrap"> </span>int add =
3;</div>
<div><span style="white-space:pre-wrap"> </span>afteradd
= (double *)malloc(sizeof(double)*nbr_etat);</div>
<div><span style="white-space:pre-wrap"> </span>for (i =
0; i<recvcount; i++)</div>
<div><span style="white-space:pre-wrap"> </span>{</div>
<div><span style="white-space:pre-wrap"> </span>afteradd
[i]= add + recvbuff[i];</div>
<div><span style="white-space:pre-wrap"> </span>}</div>
<div><span style="white-space:pre-wrap"> </span>for (i =
0; i<recvcount; i++)</div>
<div><span style="white-space:pre-wrap"> </span>{</div>
<div><span style="white-space:pre-wrap"> </span>printf("*
%0.0f<span style="white-space:pre-wrap"> </span>",
afteradd[i]);</div>
<div><span style="white-space:pre-wrap"> </span>}</div>
<div><span style="white-space:pre-wrap"> </span>printf("\n");<span style="white-space:pre-wrap"> </span>
</div>
<div><span style="white-space:pre-wrap"> </span>if
(taskid == 0)</div>
<div><span style="white-space:pre-wrap"> </span>{</div>
<div><span style="white-space:pre-wrap"> </span>free(sendbuff[0]);</div>
<div><span style="white-space:pre-wrap"> </span>free(sendbuff);</div>
<div><span style="white-space:pre-wrap"> </span>}</div>
<div><span style="white-space:pre-wrap"> </span>else</div>
<div><span style="white-space:pre-wrap"> </span>{</div>
<div><span style="white-space:pre-wrap"> </span>free(sendbuff[0]);</div>
<div><span style="white-space:pre-wrap"> </span>free(sendbuff);</div>
<div><span style="white-space:pre-wrap"> </span>free(recvbuff);</div>
<div><span style="white-space:pre-wrap"> </span>}</div>
<div><span style="white-space:pre-wrap"> </span>MPI_Finalize();</div>
<div><br>
</div>
<div>}</div>
<div><br>
</div>
</div>
</div>
<br>
<fieldset></fieldset>
<br>
</div></div><pre>_______________________________________________
discuss mailing list <a href="mailto:discuss@mpich.org" target="_blank">discuss@mpich.org</a>
To manage subscription options or unsubscribe:
<a href="https://lists.mpich.org/mailman/listinfo/discuss" target="_blank">https://lists.mpich.org/mailman/listinfo/discuss</a></pre><span class="HOEnZb"><font color="#888888">
</font></span></blockquote><span class="HOEnZb"><font color="#888888">
<br>
<br>
<pre 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 href="mailto:apenya@mcs.anl.gov" target="_blank">apenya@mcs.anl.gov</a>
<a href="http://www.mcs.anl.gov/~apenya" target="_blank">www.mcs.anl.gov/~apenya</a></pre>
</font></span></div>
<br>_______________________________________________<br>
discuss mailing list <a href="mailto:discuss@mpich.org">discuss@mpich.org</a><br>
To manage subscription options or unsubscribe:<br>
<a href="https://lists.mpich.org/mailman/listinfo/discuss" target="_blank">https://lists.mpich.org/mailman/listinfo/discuss</a><br></blockquote></div><br></div>