<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’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. For example, how many iterations does the loop go through
before crashing? Does it even get through one? I’m still not
sure what your code is supposed to do. Are you trying to read 20 bytes
each iteration? I would think that Read_at overwrites the contents of buf
instead of appending onto the end of where the last read stopped. 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. 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> </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> </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 "RecordRetrieval.h"<br>
#include "mpi.h"<br>
#include "time.h"<br>
#include "iostream.h"<br>
<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>
<br>
buf = (char *) malloc((local_end_position - local_start_position)
+ 1); <br>
<br>
input_file = MPI::File::Open(MPI::COMM_WORLD, filename,
MPI::MODE_RDONLY,<br>
MPI::INFO_NULL);<br>
<br>
output_file = MPI::File::Open(MPI::COMM_WORLD,
output_filename, MPI::MODE_CREATE | MPI::MODE_WRONLY, MPI::INFO_NULL);<br>
<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>
}<br>
}<br>
<br>
output_file.Write_shared(buf, ((local_end_position -
local_start_position) + 1), MPI_CHAR, output_file_status);<br>
<br>
free(buf);<br>
<br>
input_file.Close();<br>
output_file.Close();<br>
<br>
MPI::Finalize();<br>
}<br>
<br>
<br>
<o:p></o:p></span></font></p>
</div>
</div>
</body>
</html>