<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;}
/* 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";}
span.EmailStyle19
        {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'>Oh, good point. I didn’t
notice that the num_elements_per_rank was a float. Still, there are
better, more transparent ways to do that (like using modulus: “if(
num_vector_elements % num_processes == 0 ) /* num_elements_per_rank will be an
integer */). But you seem to have ignored the rest of my post. I
said that it would be useful to see the debug output from your for loop (I
accepted your assertion that the program was ok until then). And what is
the status on the buf variable being allocated?<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
12:39 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=2 face=Tahoma><span
style='font-size:10.0pt;font-family:Tahoma'>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>
<o:p></o:p></span></font></p>
<div class=MsoNormal align=center style='text-align:center'><font size=2
face=Tahoma><span style='font-size:10.0pt;font-family:Tahoma'>
<hr size=2 width="100%" align=center id="EC_stopSpelling">
</span></font></div>
<p class=MsoNormal style='margin-bottom:12.0pt'><font size=2 face=Tahoma><span
style='font-size:10.0pt;font-family:Tahoma'>From: <st1:PersonName w:st="on">matthew.chambers@vanderbilt.edu</st1:PersonName><br>
To: <st1:PersonName w:st="on">mpich-discuss@mcs.anl.gov</st1:PersonName><br>
Subject: Re: [MPICH] Help With I/O<br>
Date: Wed, 18 Apr 2007 09:39:50 -0500<o:p></o:p></span></font></p>
<div>
<p class=ecmsonormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>Hi Erich,</span></font><font size=2
face=Tahoma><span style='font-size:10.0pt;font-family:Tahoma'><o:p></o:p></span></font></p>
<p class=ecmsonormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'> </span></font><font size=2
face=Tahoma><span style='font-size:10.0pt;font-family:Tahoma'><o:p></o:p></span></font></p>
<p class=ecmsonormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>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><font size=2
face=Tahoma><span style='font-size:10.0pt;font-family:Tahoma'><o:p></o:p></span></font></p>
<p class=ecmsonormal style='margin-left:.5in;text-indent:-.25in'><font size=2
color=navy face=Arial><span style='font-size:10.0pt;font-family:Arial;
color:navy'>-</span></font><font size=1 color=navy><span style='font-size:7.0pt;
color:navy'> </span></font><font
size=2 color=navy face=Arial><span style='font-size:10.0pt;font-family:Arial;
color:navy'>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><font size=2 face=Tahoma><span
style='font-size:10.0pt;font-family:Tahoma'><o:p></o:p></span></font></p>
<p class=ecmsonormal style='margin-left:.5in;text-indent:-.25in'><font size=2
color=navy face=Arial><span style='font-size:10.0pt;font-family:Arial;
color:navy'>-</span></font><font size=1 color=navy><span style='font-size:7.0pt;
color:navy'> </span></font><font
size=2 color=navy face=Arial><span style='font-size:10.0pt;font-family:Arial;
color:navy'>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><font
size=2 face=Tahoma><span style='font-size:10.0pt;font-family:Tahoma'><o:p></o:p></span></font></p>
<p class=ecmsonormal style='margin-left:.5in;text-indent:-.25in'><font size=2
color=navy face=Arial><span style='font-size:10.0pt;font-family:Arial;
color:navy'>-</span></font><font size=1 color=navy><span style='font-size:7.0pt;
color:navy'> </span></font><font
size=2 color=navy face=Arial><span style='font-size:10.0pt;font-family:Arial;
color:navy'>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><font
size=2 face=Tahoma><span style='font-size:10.0pt;font-family:Tahoma'><o:p></o:p></span></font></p>
<p class=ecmsonormal style='margin-left:.5in;text-indent:-.25in'><font size=2
color=navy face=Arial><span style='font-size:10.0pt;font-family:Arial;
color:navy'>-</span></font><font size=1 color=navy><span style='font-size:7.0pt;
color:navy'> </span></font><font
size=2 color=navy face=Arial><span style='font-size:10.0pt;font-family:Arial;
color:navy'>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><font size=2 face=Tahoma><span style='font-size:
10.0pt;font-family:Tahoma'><o:p></o:p></span></font></p>
<p class=ecmsonormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'> </span></font><font size=2
face=Tahoma><span style='font-size:10.0pt;font-family:Tahoma'><o:p></o:p></span></font></p>
<p class=ecmsonormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>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><font size=2
face=Tahoma><span style='font-size:10.0pt;font-family:Tahoma'><o:p></o:p></span></font></p>
<p class=ecmsonormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'> </span></font><font size=2
face=Tahoma><span style='font-size:10.0pt;font-family:Tahoma'><o:p></o:p></span></font></p>
<p class=ecmsonormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>Good luck,</span></font><font size=2
face=Tahoma><span style='font-size:10.0pt;font-family:Tahoma'><o:p></o:p></span></font></p>
<p class=ecmsonormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>Matt Chambers</span></font><font size=2
face=Tahoma><span style='font-size:10.0pt;font-family:Tahoma'><o:p></o:p></span></font></p>
<p class=ecmsonormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'> </span></font><font size=2
face=Tahoma><span style='font-size:10.0pt;font-family:Tahoma'><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>
</span></font></div>
<p class=ecmsonormal><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
3:02 AM<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> [MPICH] Help With I/O<o:p></o:p></span></font></p>
</div>
<p class=ecmsonormal><font size=3 face="Times New Roman"><span
style='font-size:12.0pt'> </span></font><font size=2 face=Tahoma><span
style='font-size:10.0pt;font-family:Tahoma'><o:p></o:p></span></font></p>
<p class=ecmsonormal style='margin-bottom:12.0pt'><font size=2 face=Tahoma><span
style='font-size:10.0pt;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>
}<o:p></o:p></span></font></p>
<div class=MsoNormal align=center style='text-align:center'><font size=2
face=Tahoma><span style='font-size:10.0pt;font-family:Tahoma'>
<hr size=2 width="100%" align=center>
</span></font></div>
<p class=ecmsonormal><font size=2 face=Tahoma><span style='font-size:10.0pt;
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><o:p></o:p></span></font></p>
</div>
</div>
<p class=MsoNormal><font size=2 face=Tahoma><span style='font-size:10.0pt;
font-family:Tahoma'><o:p> </o:p></span></font></p>
<div class=MsoNormal align=center style='text-align:center'><font size=2
face=Tahoma><span style='font-size:10.0pt;font-family:Tahoma'>
<hr size=2 width="100%" align=center>
</span></font></div>
<p class=MsoNormal><font size=2 face=Tahoma><span style='font-size:10.0pt;
font-family:Tahoma'>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><o:p></o:p></span></font></p>
</div>
</div>
</body>
</html>