<html>
<head>
<style>
P
{
margin:0px;
padding:0px
}
body
{
FONT-SIZE: 10pt;
FONT-FAMILY:Tahoma
}
</style>
</head>
<body><BR>I have taken out the cout statements, and I have not tried very hard to debug the for loop, b/c I can't make any assumptions about the relative time it takes to execute an instruction. For instance, if I put a cout in the for loop I get half of a processes output and then half of another's after that. <BR>
&nbsp;<BR>
Here is hopefully a butter description of what I am wanting to do:<BR>
&nbsp;<BR>
Say in my test.dat file I have the following:<BR>
111111111111111111112222222222222222222233333333333333333333444444444444444444445555555555555555555566666666666666666666<BR>
&nbsp;<BR>
Then I set my vector&lt;bool&gt; to have the following items (starting with the first element [0]): true, false, true, false, true, false. Say I run the program using 3 processes, I will have each process take 2 elements of the vector. Then each process will look and see if element[i] is true, if so seek in the test.dat file to position 20 * i and grab 20 characters, lastly, output those 20 characters to the output file. <BR>
&nbsp;<BR>
Hope that helps in the understanding of the problem.<BR>
&nbsp;<BR>
Regards,<BR>
Erich<BR><BR><BR><BR>
<BLOCKQUOTE>
<HR id=EC_stopSpelling>
From: matthew.chambers@vanderbilt.edu<BR>To: erichpeterson@hotmail.com; mpich-discuss@mcs.anl.gov<BR>Subject: RE: [MPICH] Help With I/O<BR>Date: Wed, 18 Apr 2007 14:36:43 -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 EC_span.EmailStyle18
{font-family:Arial;color:navy;}
.ExternalClass EC_span.EmailStyle19
{font-family:Arial;color:navy;}
.ExternalClass EC_div.Section1
{page:Section1;}
.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 EC_p.ecmsonormal, .ExternalClass EC_li.ecmsonormal, .ExternalClass EC_div.ecmsonormal
{margin-bottom:.0001pt;font-size:12.0pt;font-family:'Times New Roman';}
.ExternalClass EC_span.EmailStyle19
{font-family:Arial;color:navy;}
.ExternalClass EC_div.Section1
{page:Section1;}
.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_p.ecmsonormal, .ExternalClass EC_li.ecmsonormal, .ExternalClass EC_div.ecmsonormal
{margin-bottom:.0001pt;font-size:12.0pt;font-family:'Times New Roman';}
.ExternalClass EC_p.ececmsonormal, .ExternalClass EC_li.ececmsonormal, .ExternalClass EC_div.ececmsonormal
{margin-bottom:.0001pt;font-size:12.0pt;font-family:'Times New Roman';}
.ExternalClass EC_span.EmailStyle20
{font-family:Arial;color:navy;}
@page Section1
{size:8.5in 11.0in;}
.ExternalClass EC_div.Section1
{page:Section1;}

</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">The cout school of debugging has a lot to recommend it, but I don’t see the cout statements in your code and you haven’t described in more detail how you’ve used them to debug your for loop. &nbsp;For example, how many iterations does the loop go through before crashing? &nbsp;Does it even get through one?&nbsp; I’m still not sure what your code is supposed to do. &nbsp;Are you trying to read 20 bytes each iteration?&nbsp; I would think that Read_at overwrites the contents of buf instead of appending onto the end of where the last read stopped. &nbsp;In that case, you were right to have the output happen right after the input (however, it would probably be better to have a secondary buffer which buf is appended onto after each read operation, and after all the reads, you can write that secondary buffer out once.&nbsp; It would be helpful if you would describe what your file reading is supposed to do more clearly.</SPAN></FONT></P>
<P class=EC_MsoNormal><FONT face=Arial color=navy size=2><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial">&nbsp;</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 1:45 PM<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> RE: [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">&nbsp;</SPAN></FONT></P>
<P class=EC_MsoNormal style="MARGIN-BOTTOM: 12pt"><FONT face="Times New Roman" size=3><SPAN style="FONT-SIZE: 12pt">Yeah you are totally right about the buf not being allocated, I think I have allocated it correctly now. I also think I should take the write function out of the for loop and place it at the end, and just let it write out what is in the buffer totally. Below is my revised code. It is still giving me the same errors though. Another problem is, I have no idea how to debug using Linux (I'm a .Net Windows guy), which is what I have to use for this project. I have like one week left of school, and I don't think I have enough time to learn gdb. So, I'm just been placing cout statements everywhere to see it I have correct file handles, etc...<BR><BR>#include "RecordRetrieval.h"<BR>#include "mpi.h"<BR>#include "time.h"<BR>#include "iostream.h"<BR><BR>void RecordRetrieval::QueryData(vector&lt;bool&gt; unencoded_vector, char * filename)<BR>{<BR>&nbsp;&nbsp;&nbsp; int num_processes;<BR>&nbsp;&nbsp;&nbsp; int num_vector_elements;<BR>&nbsp;&nbsp;&nbsp; float num_elements_per_rank;<BR>&nbsp;&nbsp;&nbsp; int local_start_position;<BR>&nbsp;&nbsp;&nbsp; int local_end_position;<BR>&nbsp;&nbsp;&nbsp; char * buf;<BR>&nbsp;&nbsp;&nbsp; int my_rank;<BR>&nbsp;&nbsp;&nbsp; MPI::File input_file;<BR>&nbsp;&nbsp;&nbsp; MPI::Status input_file_status;<BR>&nbsp;&nbsp;&nbsp; MPI::File output_file;<BR>&nbsp;&nbsp;&nbsp; MPI::Status output_file_status;<BR>&nbsp;&nbsp;&nbsp; //MPI::Offset filesize;<BR>&nbsp;&nbsp;&nbsp; char output_filename[30];<BR>&nbsp;&nbsp;&nbsp; size_t i;<BR>&nbsp;&nbsp;&nbsp; struct tm tim;<BR>&nbsp;&nbsp;&nbsp; time_t now;<BR>&nbsp;&nbsp;&nbsp; now = time(NULL);<BR>&nbsp;&nbsp;&nbsp; tim = *(localtime(&amp;now));<BR>&nbsp;&nbsp;&nbsp; i = strftime(output_filename, 30, "%m_%d_%Y_%H_%M_%S", &amp;tim);<BR><BR>&nbsp;&nbsp;&nbsp; /* Let the system do what it needs to start up MPI */<BR>&nbsp;&nbsp;&nbsp; MPI::Init();<BR>&nbsp;&nbsp;&nbsp; /* Get my process rank */<BR>&nbsp;&nbsp;&nbsp; my_rank = MPI::COMM_WORLD.Get_rank();<BR>&nbsp;&nbsp;&nbsp; /* Find out how many processes are being used */<BR>&nbsp;&nbsp;&nbsp; num_processes = MPI::COMM_WORLD.Get_size();<BR>&nbsp;&nbsp;&nbsp; num_vector_elements = unencoded_vector.size();<BR><BR>&nbsp;&nbsp;&nbsp; num_elements_per_rank = num_vector_elements / num_processes;<BR>&nbsp;&nbsp;&nbsp; local_start_position = my_rank * (int)num_elements_per_rank;<BR>&nbsp;&nbsp;&nbsp; if(my_rank == num_processes - 1)<BR>&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(num_elements_per_rank * num_processes == (int)num_elements_per_rank * num_processes)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; local_end_position = local_start_position + ((int)num_elements_per_rank - 1);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; local_end_position = (local_start_position + (int)num_elements_per_rank - 1) +<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (((int)num_elements_per_rank * num_processes) - ((int)num_elements_per_rank * num_processes));<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp; else<BR>&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; local_end_position = local_start_position + ((int)num_elements_per_rank - 1);<BR>&nbsp;&nbsp;&nbsp; }<BR><BR>&nbsp;&nbsp; buf = (char *) malloc((local_end_position - local_start_position) + 1); <BR><BR>&nbsp;&nbsp;&nbsp; input_file = MPI::File::Open(MPI::COMM_WORLD, filename, MPI::MODE_RDONLY,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MPI::INFO_NULL);<BR><BR>&nbsp;&nbsp;&nbsp; output_file = MPI::File::Open(MPI::COMM_WORLD, output_filename, MPI::MODE_CREATE | MPI::MODE_WRONLY, MPI::INFO_NULL);<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; // filesize = input_file.Get_size();<BR>&nbsp;&nbsp;&nbsp; for(int i = local_start_position; i &lt; local_end_position + 1; i++)<BR>&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(unencoded_vector[i])<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; input_file.Read_at(i * 20, buf, 20, MPI_CHAR, input_file_status);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; output_file.Write_shared(buf, ((local_end_position - local_start_position) + 1), MPI_CHAR, output_file_status);<BR>&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; free(buf);<BR><BR>&nbsp;&nbsp;&nbsp; input_file.Close();<BR>&nbsp;&nbsp;&nbsp; output_file.Close();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; MPI::Finalize();<BR>}<BR><BR><BR></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>