<html>
<head>
<style>
P
{
margin:0px;
padding:0px
}
body
{
FONT-SIZE: 10pt;
FONT-FAMILY:Tahoma
}
</style>
</head>
<body>Hi, the reasoning behind the if statements on the last process, is I might need to allocate 1 or 2 more elements to the last process it the vector_size / num_processes is not an even number. As far as debugging goes I have debugged it to the for loop, and everything seems fine until it. I think it has something to do with needing to have a lock on one or both of the file accesses. The problem is I have very limited knowledge of MPI-IO and was hoping someone who does could easily see what I am doing wrong with the I/O part.<BR> <BR>Thanks,<BR>Erich<BR><BR><BR><BR><BR>
<BLOCKQUOTE>
<HR id=EC_stopSpelling>
From: matthew.chambers@vanderbilt.edu<BR>To: mpich-discuss@mcs.anl.gov<BR>Subject: Re: [MPICH] Help With I/O<BR>Date: Wed, 18 Apr 2007 09:39:50 -0500<BR><BR>
<META content="Microsoft SafeHTML" name=Generator>
<STYLE>
.ExternalClass .EC_shape
{;}
</STYLE>
<STYLE>
</STYLE>
<STYLE>
.ExternalClass EC_p.MsoNormal, .ExternalClass EC_li.MsoNormal, .ExternalClass EC_div.MsoNormal
{margin-bottom:.0001pt;font-size:12.0pt;font-family:'Times New Roman';}
.ExternalClass EC_a:link, .ExternalClass EC_span.MsoHyperlink
{color:blue;text-decoration:underline;}
.ExternalClass EC_a:visited, .ExternalClass EC_span.MsoHyperlinkFollowed
{color:blue;text-decoration:underline;}
.ExternalClass p
{margin-bottom:.0001pt;font-size:12.0pt;font-family:'Times New Roman';}
.ExternalClass EC_span.EmailStyle18
{font-family:Arial;color:navy;}
.ExternalClass EC_span.EmailStyle19
{font-family:Arial;color:navy;}
@page Section1
{size:8.5in 11.0in;}
.ExternalClass EC_div.Section1
{page:Section1;}
.ExternalClass ol
{margin-bottom:0in;}
.ExternalClass ul
{margin-bottom:0in;}
</STYLE>
<DIV class=EC_Section1>
<P class=EC_MsoNormal><FONT face=Arial color=navy size=2><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial">Hi Erich,</SPAN></FONT></P>
<P class=EC_MsoNormal><FONT face=Arial color=navy size=2><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial"> </SPAN></FONT></P>
<P class=EC_MsoNormal><FONT face=Arial color=navy size=2><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial">Frankly the code leading up to that for loop is a bit scary. I don’t really know anything about MPI I/O, but I can get you a few tips on your C++:</SPAN></FONT></P>
<P class=EC_MsoNormal style="MARGIN-LEFT: 0.5in; TEXT-INDENT: -0.25in"><FONT face=Arial color=navy size=2><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial"><SPAN>-<FONT face="Times New Roman" size=1><SPAN style="FONT: 7pt 'Times New Roman'"> </SPAN></FONT></SPAN></SPAN></FONT><FONT face=Arial color=navy size=2><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial">Unless you’re using a horribly out of date compiler like MSVC 6, you should use the standard header names <iostream>, <vector>, <ctime>, etc.</SPAN></FONT></P>
<P class=EC_MsoNormal style="MARGIN-LEFT: 0.5in; TEXT-INDENT: -0.25in"><FONT face=Arial color=navy size=2><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial"><SPAN>-<FONT face="Times New Roman" size=1><SPAN style="FONT: 7pt 'Times New Roman'"> </SPAN></FONT></SPAN></SPAN></FONT><FONT face=Arial color=navy size=2><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial">If you are using a horribly out of date compiler like MSVC 6, you should upgrade to the free MSVC++ 2005 Express Edition.</SPAN></FONT></P>
<P class=EC_MsoNormal style="MARGIN-LEFT: 0.5in; TEXT-INDENT: -0.25in"><FONT face=Arial color=navy size=2><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial"><SPAN>-<FONT face="Times New Roman" size=1><SPAN style="FONT: 7pt 'Times New Roman'"> </SPAN></FONT></SPAN></SPAN></FONT><FONT face=Arial color=navy size=2><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial">In this case it’s a cosmetic fix, but you should probably pass the vector<bool> parameter by reference instead of by value.</SPAN></FONT></P>
<P class=EC_MsoNormal style="MARGIN-LEFT: 0.5in; TEXT-INDENT: -0.25in"><FONT face=Arial color=navy size=2><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial"><SPAN>-<FONT face="Times New Roman" size=1><SPAN style="FONT: 7pt 'Times New Roman'"> </SPAN></FONT></SPAN></SPAN></FONT><FONT face=Arial color=navy size=2><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial">You seem to be doing some mind boggling casting in order to determine if num_elements_per_rank is too big to fit in an int (but only on your last process?). You might get rid of that voodoo by using size_t (usually at least an unsigned 4 byte int) for your position indexes instead (vector<T>::size() returns vector<T>::size_type which usually boils down to size_t).</SPAN></FONT></P>
<P class=EC_MsoNormal><FONT face=Arial color=navy size=2><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial"> </SPAN></FONT></P>
<P class=EC_MsoNormal><FONT face=Arial color=navy size=2><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial">Beyond that, I would need to see some debug output from your for loop. For example, what indexes are actually being passed to the I/O calls by each process? Does MPI::File::Read_at() allocate memory for the “buf” variable you pass it? If not, you haven’t allocated any memory for it and that would lead to a crash before you could say “new char.”</SPAN></FONT></P>
<P class=EC_MsoNormal><FONT face=Arial color=navy size=2><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial"> </SPAN></FONT></P>
<P class=EC_MsoNormal><FONT face=Arial color=navy size=2><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial">Good luck,</SPAN></FONT></P>
<P class=EC_MsoNormal><FONT face=Arial color=navy size=2><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial">Matt Chambers</SPAN></FONT></P>
<P class=EC_MsoNormal><FONT face=Arial color=navy size=2><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial"> </SPAN></FONT></P>
<DIV style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0in; BORDER-TOP: medium none; PADDING-LEFT: 4pt; PADDING-BOTTOM: 0in; BORDER-LEFT: blue 1.5pt solid; PADDING-TOP: 0in; BORDER-BOTTOM: medium none">
<DIV>
<DIV class=EC_MsoNormal style="TEXT-ALIGN: center" align=center><FONT face="Times New Roman" size=3><SPAN style="FONT-SIZE: 12pt">
<HR align=center width="100%" SIZE=2>
</SPAN></FONT></DIV>
<P class=EC_MsoNormal><B><FONT face=Tahoma size=2><SPAN style="FONT-WEIGHT: bold; FONT-SIZE: 10pt; FONT-FAMILY: Tahoma">From:</SPAN></FONT></B><FONT face=Tahoma size=2><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Tahoma"> owner-mpich-discuss@mcs.anl.gov [mailto:owner-mpich-discuss@mcs.anl.gov] <B><SPAN style="FONT-WEIGHT: bold">On Behalf Of </SPAN></B>Erich Peterson<BR><B><SPAN style="FONT-WEIGHT: bold">Sent:</SPAN></B> Wednesday, April 18, 2007 3:02 AM<BR><B><SPAN style="FONT-WEIGHT: bold">To:</SPAN></B> mpich-discuss@mcs.anl.gov<BR><B><SPAN style="FONT-WEIGHT: bold">Subject:</SPAN></B> [MPICH] Help With I/O</SPAN></FONT></P></DIV>
<P class=EC_MsoNormal><FONT face="Times New Roman" size=3><SPAN style="FONT-SIZE: 12pt"> </SPAN></FONT></P>
<P class=EC_MsoNormal style="MARGIN-BOTTOM: 12pt"><FONT face=Tahoma size=2><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Tahoma">Hi all, I'm trying to write this little routine which is part of my graduate project. What I'm trying to do is pass a vector of bools in to the QueryData method. In that method I split the vector up into equal parts among the number of processes, have each process open a datafile which as 20 byte records (no new lines), read that record from the file if the vector they are checking has "true" (basically if vector[0] = true, it means grab the first record of the file), and lastly, it should output that record into a new file.<BR> <BR>I have been able to determine it is messing up on the for-loop. The error is:<BR> <BR>[Student@cluster1 erich_test_area]$ mpiexec -n 3 /mnt/pvfs2/acxiom/erich_test_area/RecordRetrieval<BR>terminate called after throwing an instance of 'MPI::Exception'<BR>terminate called after throwing an instance of 'MPI::Exception'<BR>terminate called after throwing an instance of 'MPI::Exception'<BR>rank 0 in job 1 cluster1_33602 caused collective abort of all ranks<BR> exit status of rank 0: killed by signal 6 <BR><BR>If someone could please tell me or edit the code if they see what is wrong. Thanks!<BR> <BR>Main.cpp:<BR><BR>#include "RecordRetrieval.h"<BR>#include <vector.h><BR>int main()<BR>{<BR> vector<bool> vec;<BR> vec.push_back(true);<BR> vec.push_back(false);<BR> vec.push_back(true);<BR> vec.push_back(false);<BR> vec.push_back(true);<BR> vec.push_back(false);<BR> RecordRetrieval rec;<BR> rec.QueryData(vec, "test.dat");<BR> return 0;<BR>}<BR><BR>RecordRetrieval.cpp:<BR> <BR>#include "RecordRetrieval.h"<BR>#include "mpi.h"<BR>#include "time.h"<BR>#include "iostream.h"<BR>void RecordRetrieval::QueryData(vector<bool> unencoded_vector, char * filename)<BR>{<BR> int num_processes;<BR> int num_vector_elements;<BR> float num_elements_per_rank;<BR> int local_start_position;<BR> int local_end_position;<BR> char * buf;<BR> int my_rank;<BR> MPI::File input_file;<BR> MPI::Status input_file_status;<BR> MPI::File output_file;<BR> MPI::Status output_file_status;<BR> //MPI::Offset filesize;<BR> char output_filename[30];<BR> size_t i;<BR> struct tm tim;<BR> time_t now;<BR> now = time(NULL);<BR> tim = *(localtime(&now));<BR> i = strftime(output_filename, 30, "%m_%d_%Y_%H_%M_%S", &tim);<BR><BR> /* Let the system do what it needs to start up MPI */<BR> MPI::Init();<BR> /* Get my process rank */<BR> my_rank = MPI::COMM_WORLD.Get_rank();<BR> /* Find out how many processes are being used */<BR> num_processes = MPI::COMM_WORLD.Get_size();<BR> num_vector_elements = unencoded_vector.size();<BR><BR> num_elements_per_rank = num_vector_elements / num_processes;<BR> local_start_position = my_rank * (int)num_elements_per_rank;<BR> if(my_rank == num_processes - 1)<BR> {<BR> if(num_elements_per_rank * num_processes == (int)num_elements_per_rank * num_processes)<BR> {<BR> local_end_position = local_start_position + ((int)num_elements_per_rank - 1);<BR> }<BR> else<BR> {<BR> local_end_position = (local_start_position + (int)num_elements_per_rank - 1) +<BR> (((int)num_elements_per_rank * num_processes) - ((int)num_elements_per_rank * num_processes));<BR> }<BR> }<BR> else<BR> {<BR> local_end_position = local_start_position + ((int)num_elements_per_rank - 1);<BR> }<BR> input_file = MPI::File::Open(MPI::COMM_WORLD, filename, MPI::MODE_RDONLY,<BR> MPI::INFO_NULL);<BR> output_file = MPI::File::Open(MPI::COMM_WORLD, output_filename, MPI::MODE_CREATE | MPI::MODE_WRONLY, MPI::INFO_NULL);<BR> // filesize = input_file.Get_size();<BR> for(int i = local_start_position; i < local_end_position + 1; i++)<BR> {<BR> if(unencoded_vector[i])<BR> {<BR> input_file.Read_at(i * 20, buf, 20, MPI_CHAR, input_file_status);<BR> output_file.Write_shared(buf, 20, MPI_CHAR, output_file_status);<BR> }<BR> }<BR> cout << "Error";<BR> input_file.Close();<BR> output_file.Close();<BR> <BR> MPI::Finalize();<BR>}</SPAN></FONT></P>
<DIV class=EC_MsoNormal style="TEXT-ALIGN: center" align=center><FONT face=Tahoma size=2><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Tahoma">
<HR align=center width="100%" SIZE=2>
</SPAN></FONT></DIV>
<P class=EC_MsoNormal><FONT face=Tahoma size=2><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Tahoma">Discover the new Windows Vista <A href="http://search.msn.com/results.aspx?q=windows+vista&mkt=en-US&form=QBRE" target=_blank>Learn more!</A></SPAN></FONT></P></DIV></DIV></BLOCKQUOTE><br /><hr />Invite your mail contacts to join your friends list with Windows Live Spaces. It's easy! <a href='http://spaces.live.com/spacesapi.aspx?wx_action=create&wx_url=/friends.aspx&mkt=en-us' target='_new'>Try it!</a></body>
</html>