Thanks for all your help. My code works but part of it still has memory leaks. Hopefully the solution to that lies in the answer to this question(s):<div><br><div> Currently I let all processors create one sequential array and populate the same array. Is this thread-safe? Or should I let root node create the array and then broadcast it? If I let root node create that array, how do i ensure other nodes/processors are not going to jump and execute the statements below the array creation?</div>
<div><br></div><div>Thanks again</div><div><div><div><div><br><div><br><div class="gmail_quote">On Thu, Dec 9, 2010 at 4:30 PM, Jayesh Krishna <span dir="ltr"><<a href="mailto:jayesh@mcs.anl.gov">jayesh@mcs.anl.gov</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Hi,<br>
Yes, you can execute non-parallel version of class 1 from the root MPI process (rank = 0) and broadcast the result to other MPI processes. Typically you divide work (computation) among MPI processes if the work is scalable and the cost of computation of the results using a single worker is greater than the (cost of computation of the divided work in a single worker + cost of communication of the result among MPI processes). If the work is significantly small you might be better off doing it in a single process.<br>
Make sure that when you call MPI_Bcast() from all the MPI processes (Correctly speaking, all MPI processes belonging to the same communicator should call MPI_Bcast(). In your case the communicator, MPI_COMM_WORLD, consists of all the MPI processes).<br>
From your email I am guessing that you no longer have any problems executing your MPI program with MPICH2 (Am I right ? ).<br>
<div class="im"><br>
Regards,<br>
Jayesh<br>
----- Original Message -----<br>
From: Prashanth <<a href="mailto:prashanth.dumpuri@gmail.com">prashanth.dumpuri@gmail.com</a>><br>
To: Jayesh Krishna <<a href="mailto:jayesh@mcs.anl.gov">jayesh@mcs.anl.gov</a>><br>
Cc: <a href="mailto:mpich-discuss@mcs.anl.gov">mpich-discuss@mcs.anl.gov</a><br>
</div><div><div></div><div class="h5">Sent: Thu, 09 Dec 2010 15:38:55 -0600 (CST)<br>
Subject: Re: [mpich-discuss] MPICH2 hangs during debug<br>
<br>
Jayesh,<br>
Just playing catch up in the next 2 lines - I have 3 classes 2 of<br>
which have been parallelized using MPI and all 3 are being instantiated and<br>
executed in my main code. Since one of the classes was not parallelized i<br>
had it inside an "if" condition: if rank==zero then execute the non-parallel<br>
class1. I then used MPI_BCast to broadcast the results from class1 to all<br>
the processors.<br>
Turns out this "if" condition caused the child processors (those<br>
with rank not equal to zero) to jump directly to the functions below the<br>
MPI_BCast command while root node was still stuck at MPI_BCast. This caused<br>
my code/debugger to hang.<br>
It takes me less than 2seconds to execute class1 so I can get away<br>
with running class1 on all the processors but I want to learn the "proper"<br>
way to execute a MPI application. Any thoughts?<br>
Please let me know if the above email was confusing.<br>
Thanks<br>
Prashanth<br>
<br>
<br>
On Thu, Dec 9, 2010 at 1:48 PM, Prashanth <<a href="mailto:prashanth.dumpuri@gmail.com">prashanth.dumpuri@gmail.com</a>>wrote:<br>
<br>
> Jayesh,<br>
> Thanks for the immediate response (again). You need VTK (visualization<br>
> toolkit) and PETSc (parallel sparse matrix) libraries to compile my code.<br>
> Can I include these toolkits in the zip file i'm going to send you?<br>
> Thanks<br>
> Prashanth<br>
><br>
> On Thu, Dec 9, 2010 at 1:44 PM, Jayesh Krishna <<a href="mailto:jayesh@mcs.anl.gov">jayesh@mcs.anl.gov</a>> wrote:<br>
><br>
>> Hi,<br>
>> The parameters to MPI_Bcast() look alright. It might be easier for me to<br>
>> debug if you can send me the complete code. Can you send a zip of the<br>
>> complete code to <a href="mailto:jayesh@mcs.anl.gov">jayesh@mcs.anl.gov</a> ?<br>
>><br>
>> Regards,<br>
>> Jayesh<br>
>> ----- Original Message -----<br>
>> From: Prashanth <<a href="mailto:prashanth.dumpuri@gmail.com">prashanth.dumpuri@gmail.com</a>><br>
>> To: Jayesh Krishna <<a href="mailto:jayesh@mcs.anl.gov">jayesh@mcs.anl.gov</a>><br>
>> Cc: <a href="mailto:mpich-discuss@mcs.anl.gov">mpich-discuss@mcs.anl.gov</a><br>
>> Sent: Thu, 09 Dec 2010 13:33:08 -0600 (CST)<br>
>> Subject: Re: [mpich-discuss] MPICH2 hangs during debug<br>
>><br>
>> Jayesh,<br>
>> Thanks for the immediate response. The example MPI application ran fine<br>
>> in the Debug mode. MPI_BCast did not hang for the example application. To<br>
>> answer your question as to why i'm reading the same file from all MPI<br>
>> processes, I couldn't figure out how to use MPI_Byte(s) / MPI_Send() to<br>
>> send<br>
>> data from root node to all the child nodes. Once I figure that out I'll<br>
>> ask<br>
>> my code to read the data on the root node and then broadcast it to child<br>
>> nodes.<br>
>> I'm not sure if can attach documents to this mailing list and hence 'am<br>
>> just pasting the snippet of my code containing the MPI call. If you need<br>
>> the<br>
>> entire code, please let me know how to send it to you and i'll send it to<br>
>> you. The code hangs at the MPI_BCast command in the Debug mode. FYI, I'm<br>
>> using another toolkit VTK - visualization toolkit - to format my data.<br>
>> Output1 from class1 is in the vtk data format and translates to a double<br>
>> array in C++.<br>
>><br>
>> int main( int argc, char * argv[] )<br>
>> {<br>
>><br>
>> MPI_Init(&argc,&argv);<br>
>> int rank, number_of_processors;<br>
>> MPI_Comm_size(MPI_COMM_WORLD,& number_of_processors);<br>
>> MPI_Comm_rank(MPI_COMM_WORLD,&rank);<br>
>><br>
>> // read inputs on all processors<br>
>> // snipped for brevity<br>
>><br>
>> // class1 - read the inputs and generate output1: need not be<br>
>> parallelized<br>
>> vtkSmartPointer<vtkGetSignedClosestPointDistances><br>
>> ComputeSignedClosestPointDistances =<br>
>><br>
>><br>
>> vtkSmartPointer<vtkGetSignedClosestPointDistances>::New();<br>
>> if ( rank == 0 )<br>
>> {<br>
>> ComputeSignedClosestPointDistances->SetInput( inputs i just read<br>
>> );<br>
>> ComputeSignedClosestPointDistances->Update();<br>
>> }<br>
>> // get output1 from class1<br>
>> vtkSmartPointer<vtkDoubleArray> signedclosestpointdistancesbefore =<br>
>> vtkSmartPointer<vtkDoubleArray>::New();<br>
>><br>
>> signedclosestpointdistancesbefore->DeepCopy(<br>
>> ComputeSignedClosestPointDistances->GetSignedClosestPointDistances() );<br>
>><br>
>> // GetVoidPointer(0) returns the void pointer at 0th element<br>
>> // GetNumberOfTuples - size of the array<br>
>> MPI_Bcast( signedclosestpointdistancesbefore->GetVoidPointer(0),<br>
>> signedclosestpointdistancesbefore->GetNumberOfTuples(), MPI_DOUBLE, 0,<br>
>> MPI_COMM_WORLD );<br>
>><br>
>> // code snipped for brevity<br>
>><br>
>> MPI_Finalize();<br>
>><br>
>> return 0;<br>
>> }<br>
>><br>
>> Thanks again for all your help<br>
>> Prashanth<br>
>><br>
>><br>
><br>
<br>
</div></div></blockquote></div><br></div></div></div></div></div></div>