<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:st1="urn:schemas-microsoft-com:office:smarttags" xmlns="http://www.w3.org/TR/REC-html40">

<head>
<meta http-equiv=Content-Type content="text/html; charset=us-ascii">
<meta name=Generator content="Microsoft Word 11 (filtered medium)">
<!--[if !mso]>
<style>
v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style>
<![endif]--><o:SmartTagType
 namespaceuri="urn:schemas-microsoft-com:office:smarttags" name="PersonName"/>
<!--[if !mso]>
<style>
st1\:*{behavior:url(#default#ieooui) }
</style>
<![endif]-->
<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;}

 /* Font Definitions */
 @font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman";}
a:link, span.MsoHyperlink
        {color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {color:blue;
        text-decoration:underline;}
p
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman";}
p.ecmsonormal, li.ecmsonormal, div.ecmsonormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman";}
p.ececmsonormal, li.ececmsonormal, div.ececmsonormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman";}
span.EmailStyle20
        {mso-style-type:personal-reply;
        font-family:Arial;
        color:navy;}
@page Section1
        {size:8.5in 11.0in;
        margin:1.0in 1.25in 1.0in 1.25in;}
div.Section1
        {page:Section1;}
-->
</style>

</head>

<body lang=EN-US link=blue vlink=blue>

<div class=Section1>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>The cout school of debugging has a lot to
recommend it, but I don&#8217;t see the cout statements in your code and you
haven&#8217;t described in more detail how you&#8217;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&#8217;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.<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'><o:p>&nbsp;</o:p></span></font></p>

<div style='border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt'>

<div>

<div class=MsoNormal align=center style='text-align:center'><font size=3
face="Times New Roman"><span style='font-size:12.0pt'>

<hr size=2 width="100%" align=center tabindex=-1>

</span></font></div>

<p class=MsoNormal><b><font size=2 face=Tahoma><span style='font-size:10.0pt;
font-family:Tahoma;font-weight:bold'>From:</span></font></b><font size=2
face=Tahoma><span style='font-size:10.0pt;font-family:Tahoma'> <st1:PersonName
w:st="on">owner-<st1:PersonName w:st="on">mpich-discuss@mcs.anl.gov</st1:PersonName></st1:PersonName>
[mailto:<st1:PersonName w:st="on">owner-<st1:PersonName w:st="on">mpich-discuss@mcs.anl.gov</st1:PersonName></st1:PersonName>]
<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> <st1:PersonName w:st="on">mpich-discuss@mcs.anl.gov</st1:PersonName><br>
<b><span style='font-weight:bold'>Subject:</span></b> RE: [MPICH] Help With I/O</span></font><o:p></o:p></p>

</div>

<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoNormal style='margin-bottom:12.0pt'><font size=3
face="Times New Roman"><span style='font-size:12.0pt'>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 &quot;RecordRetrieval.h&quot;<br>
#include &quot;mpi.h&quot;<br>
#include &quot;time.h&quot;<br>
#include &quot;iostream.h&quot;<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,
&quot;%m_%d_%Y_%H_%M_%S&quot;, &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>
<o:p></o:p></span></font></p>

</div>

</div>

</body>

</html>