On Wed, Mar 14, 2012 at 1:33 PM, Xiangdong Liang <span dir="ltr"><<a href="mailto:xdliang@gmail.com">xdliang@gmail.com</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On Tue, Mar 13, 2012 at 5:57 PM, Matthew Knepley <<a href="mailto:knepley@gmail.com">knepley@gmail.com</a>> wrote:<br>
> On Tue, Mar 13, 2012 at 4:39 PM, Xiangdong Liang <<a href="mailto:xdliang@gmail.com">xdliang@gmail.com</a>> wrote:<br>
>><br>
>> Hello everyone,<br>
>><br>
>> Can someone provide me advice on using OpenMP in PETSc? I am solving a<br>
>> problem like this:<br>
>><br>
>> int main()<br>
>> {<br>
>> vec vsum;<br>
>><br>
>> for(i=0; i< N; i++)<br>
>> {<br>
>> vec vi;<br>
>> fcomputev(i, vi);<br>
>> VecAXPY(vsum, 1.0, vi); // vsum +=vi;<br>
>> }<br>
>><br>
>> }<br>
>><br>
>> Can I use OpenMP "omp parallel for" to do the loop in parallel? For<br>
>> example, suppose I have 8 processes. It would be nice if each petsc<br>
>> subrountine fcomputev uses 2 processes while 4 different i's are<br>
>> computed in parallel (since different i's are independent).<br>
><br>
><br>
> PETSc is not threadsafe. This is trivial to do in MPI where the comm for eah<br>
> Vec is a group of 2 procs.<br>
<br>
Do you mean the use of MPI_Reduce? If I use MPI_Reduce, should I<br>
convert the Vec objects into regular array by vecgetarray first, then<br>
apply the MPI_Op (MPI_SUM) on these arrays? Is there any way to<br>
circumvent this vec-arrary converting by define MPI_Op and<br>
MPI_datatype on Vec ?<br></blockquote><div><br></div><div>I think you miss my point. This is the difference between writing SPMD programs</div><div>and threaded programs. PETSc is SPMD, and I don't ever expect that to change.</div>
<div>CUDA, for instance, is also SPMD.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Another quick question, where can I find the implementation of vec<br>
ops? For example, In petscvec.h, VecAXPY is implemented like<br>
(*y->ops->axpy)(y,alpha,x). Can you point me to the implementation of<br>
methods ops->axpy?<br></blockquote><div><br></div><div>src/vec/vec/impls</div><div><br></div><div> Matt</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Thanks.<br>
Xiangdong<br>
<br>
<br>
<br>
><br>
> Matt<br>
><br>
>><br>
>> Any helps or hints on this would be appreciated.<br>
>><br>
>> Best,<br>
>> Xiangdong<br>
><br>
><br>
><br>
<span class="HOEnZb"><font color="#888888">><br>
> --<br>
> What most experimenters take for granted before they begin their experiments<br>
> is infinitely more interesting than any results to which their experiments<br>
> lead.<br>
> -- Norbert Wiener<br>
</font></span></blockquote></div><br><br clear="all"><div><br></div>-- <br>What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br>
-- Norbert Wiener<br>