<html>
<head>
<style>
P
{
margin:0px;
padding:0px
}
body
{
FONT-SIZE: 10pt;
FONT-FAMILY:Tahoma
}
</style>
</head>
<body>UPDATE: I tried to use gdb a little bit, running only one process, and it is throwing the exception on the first Write_shared call. But, I still don't know what the underlying problem is. I've re-arranged the code like we have discussed below:<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>
/* 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>
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>
buf = (char *) malloc(20); <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> <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_BYTE, input_file_status);<BR> output_file.Write_shared(buf, 20, MPI_BYTE, output_file_status);<BR> }<BR> }<BR> <BR> <BR> free(buf);<BR>
input_file.Close();<BR> output_file.Close();<BR> <BR> MPI::Finalize();<BR>}<BR><BR><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. 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.</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 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"> </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<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></SPAN></FONT></P></DIV></DIV></BLOCKQUOTE><br /><hr />Discover the new Windows Vista <a href='http://search.msn.com/results.aspx?q=windows+vista&mkt=en-US&form=QBRE' target='_new'>Learn more!</a></body>
</html>