<html>
<head>
<style>
P
{
margin:0px;
padding:0px
}
body
{
FONT-SIZE: 10pt;
FONT-FAMILY:Tahoma
}
</style>
</head>
<body>OK, I have changed to all the new non-deprecated libraries, except for time.h, I don't have <time>. Everything compiles fine, and still have the same problem. I cout the buf just before the Write operation and buf contains the correct record "11111111111111111111", it is still failing on the write, even with just one process.<BR>
<BR>
Here is the revised code, I am now just referencing the files directly in the code. <BR>
<BR>
PS - I know it is not a permission thing, I gave full permission to out.dat.<BR>
<BR>
#include "RecordRetrieval.h"<BR>#include "mpi.h"<BR>#include <time.h><BR>#include <iostream><BR>
using namespace std;<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, "test.dat", MPI::MODE_RDONLY,<BR> MPI::INFO_NULL);<BR>
output_file = MPI::File::Open(MPI::COMM_WORLD, "out.dat", MPI::MODE_CREATE | MPI::MODE_WRONLY, MPI::INFO_NULL);<BR> <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> cout << "Loop: " << i << "Buffer; " << buf;<BR> output_file.Write_shared(buf, 20, MPI_BYTE, output_file_status);<BR> }<BR> }<BR> <BR> free(buf); <BR>
input_file.Close();<BR> output_file.Close();<BR> <BR> MPI::Finalize();<BR>}<BR><BR>
<BR>
<BR> <BR>Regards,<BR>Erich <BR><BR><BR><BR><BR><BR>
<BLOCKQUOTE>
<HR id=EC_stopSpelling>
From: samm@sammiller.org<BR>Subject: Re: [MPICH] Help With I/O<BR>Date: Wed, 18 Apr 2007 18:03:40 -0500<BR>To: erichpeterson@hotmail.com<BR><BR><BR>
<DIV>
<DIV>On Apr 18, 2007, at 5:45 PM, Erich Peterson wrote:</DIV><BR class=EC_Apple-interchange-newline>
<BLOCKQUOTE><SPAN class=EC_Apple-style-span style="WORD-SPACING: 0px; FONT: 12px Helvetica; TEXT-TRANSFORM: none; COLOR: rgb(0,0,0); TEXT-INDENT: 0px; WHITE-SPACE: normal; LETTER-SPACING: normal; BORDER-COLLAPSE: separate"><SPAN class=EC_Apple-style-span style="FONT-SIZE: 13px; FONT-FAMILY: Tahoma">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:</SPAN><BR style="FONT-SIZE: 13px; FONT-FAMILY: Tahoma"><SPAN class=EC_Apple-style-span style="FONT-SIZE: 13px; FONT-FAMILY: Tahoma"> </SPAN><BR style="FONT-SIZE: 13px; FONT-FAMILY: Tahoma"><SPAN class=EC_Apple-style-span style="FONT-SIZE: 13px; FONT-FAMILY: Tahoma">#include "RecordRetrieval.h"</SPAN><BR style="FONT-SIZE: 13px; FONT-FAMILY: Tahoma"><SPAN class=EC_Apple-style-span style="FONT-SIZE: 13px; FONT-FAMILY: Tahoma">#include "mpi.h"</SPAN><BR style="FONT-SIZE: 13px; FONT-FAMILY: Tahoma"><SPAN class=EC_Apple-style-span style="FONT-SIZE: 13px; FONT-FAMILY: Tahoma">#include "time.h"</SPAN><BR style="FONT-SIZE: 13px; FONT-FAMILY: Tahoma"><SPAN class=EC_Apple-style-span style="FONT-SIZE: 13px; FONT-FAMILY: Tahoma">#include "iostream.h"</SPAN></SPAN></BLOCKQUOTE></DIV>
<DIV><BR class=EC_khtml-block-placeholder></DIV>Erich,
<DIV><BR class=EC_khtml-block-placeholder></DIV>
<DIV>I believe Matthew previously mentioned this in his first reply, and I noticed you have not changed it yet. I suggest you use the correct header names and namespace scoping:</DIV>
<DIV><BR class=EC_khtml-block-placeholder></DIV>
<DIV>#include <iostream> rather than #include "iostream.h"</DIV>
<DIV>#include <ctime> rather than #include "time.h"</DIV>
<DIV><BR class=EC_khtml-block-placeholder></DIV>
<DIV>While it won't make your problem disappear, it's good practice to follow. Your compiler should warn you about using the incorrect header names, like so:</DIV>
<DIV><BR class=EC_khtml-block-placeholder></DIV>
<DIV>furlong:~ samm$ cat badheader.cc </DIV>
<DIV>#include <iostream.h></DIV>
<DIV><BR class=EC_khtml-block-placeholder></DIV>
<DIV>int main() {</DIV>
<DIV> cout << "hello world" << endl;</DIV>
<DIV>}</DIV>
<DIV>furlong:~ samm$ g++ badheader.cc </DIV>
<DIV>In file included from /usr/include/c++/4.0.0/backward/iostream.h:31,</DIV>
<DIV> from badheader.cc:1:</DIV>
<DIV>/usr/include/c++/4.0.0/backward/backward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <iostream> instead of the deprecated header <iostream.h>. To disable this warning use -Wno-deprecated.</DIV>
<DIV>furlong:~ samm$ ./a.out </DIV>
<DIV>hello world</DIV>
<DIV>furlong:~ samm$ cat goodheader.cc </DIV>
<DIV>#include <iostream></DIV>
<DIV><BR class=EC_khtml-block-placeholder></DIV>
<DIV>using std::cout;</DIV>
<DIV>using std::endl;</DIV>
<DIV><BR class=EC_khtml-block-placeholder></DIV>
<DIV>int main() {</DIV>
<DIV> cout << "hello world" << endl;</DIV>
<DIV>}</DIV>
<DIV>furlong:~ samm$ g++ goodheader.cc </DIV>
<DIV>furlong:~ samm$ ./a.out </DIV>
<DIV>hello world</DIV>
<DIV>furlong:~ samm$</DIV>
<DIV><BR class=EC_khtml-block-placeholder></DIV>
<DIV>This was on a mac w/ gcc 4.0.1 but you should see similar results on a Linux box or cluster.</DIV>
<DIV><BR class=EC_khtml-block-placeholder></DIV>
<DIV><BR class=EC_khtml-block-placeholder></DIV>
<DIV>Cheers,<BR>
<DIV><SPAN class=EC_Apple-style-span style="WORD-SPACING: 0px; FONT: 12px Helvetica; TEXT-TRANSFORM: none; COLOR: rgb(0,0,0); TEXT-INDENT: 0px; WHITE-SPACE: normal; LETTER-SPACING: normal; BORDER-COLLAPSE: separate">
<DIV><BR class=EC_khtml-block-placeholder></DIV>
<DIV>Sam Miller</DIV>
<DIV><A href="http://www.sammiller.org/" target=_blank>http://www.sammiller.org</A></DIV>
<DIV>"Generally speaking, people provide better maintenance for their cars than for their own bodies." - Scott Adams</DIV>
<DIV><BR class=EC_khtml-block-placeholder></DIV>
<DIV><BR class=EC_khtml-block-placeholder></DIV><BR class=EC_Apple-interchange-newline></SPAN></DIV><BR></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>