[MPICH] Help With I/O
Erich Peterson
erichpeterson at hotmail.com
Wed Apr 18 18:23:43 CDT 2007
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.
Here is the revised code, I am now just referencing the files directly in the code.
PS - I know it is not a permission thing, I gave full permission to out.dat.
#include "RecordRetrieval.h"#include "mpi.h"#include <time.h>#include <iostream>
using namespace std;
void RecordRetrieval::QueryData(vector<bool> unencoded_vector, char * filename){ int num_processes; int num_vector_elements; float num_elements_per_rank; int local_start_position; int local_end_position; char * buf; int my_rank; MPI::File input_file; MPI::Status input_file_status; MPI::File output_file; MPI::Status output_file_status; //MPI::Offset filesize; char output_filename[30]; size_t i; struct tm tim; time_t now; now = time(NULL); tim = *(localtime(&now)); i = strftime(output_filename, 30, "%m_%d_%Y_%H_%M_%S", &tim);
/* Let the system do what it needs to start up MPI */ MPI::Init(); /* Get my process rank */ my_rank = MPI::COMM_WORLD.Get_rank(); /* Find out how many processes are being used */ num_processes = MPI::COMM_WORLD.Get_size(); num_vector_elements = unencoded_vector.size();
num_elements_per_rank = num_vector_elements / num_processes; local_start_position = my_rank * (int)num_elements_per_rank; if(my_rank == num_processes - 1) { if(num_elements_per_rank * num_processes == (int)num_elements_per_rank * num_processes) { local_end_position = local_start_position + ((int)num_elements_per_rank - 1); } else { local_end_position = (local_start_position + (int)num_elements_per_rank - 1) + (((int)num_elements_per_rank * num_processes) - ((int)num_elements_per_rank * num_processes)); } } else { local_end_position = local_start_position + ((int)num_elements_per_rank - 1); }
buf = (char *) malloc(20);
input_file = MPI::File::Open(MPI::COMM_WORLD, "test.dat", MPI::MODE_RDONLY, MPI::INFO_NULL);
output_file = MPI::File::Open(MPI::COMM_WORLD, "out.dat", MPI::MODE_CREATE | MPI::MODE_WRONLY, MPI::INFO_NULL); // filesize = input_file.Get_size(); for(int i = local_start_position; i < local_end_position + 1; i++) { if(unencoded_vector[i]) { input_file.Read_at(i * 20, buf, 20, MPI_BYTE, input_file_status); cout << "Loop: " << i << "Buffer; " << buf; output_file.Write_shared(buf, 20, MPI_BYTE, output_file_status); } } free(buf);
input_file.Close(); output_file.Close(); MPI::Finalize();}
Regards,Erich
From: samm at sammiller.orgSubject: Re: [MPICH] Help With I/ODate: Wed, 18 Apr 2007 18:03:40 -0500To: erichpeterson at hotmail.com
On Apr 18, 2007, at 5:45 PM, Erich Peterson wrote:
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: #include "RecordRetrieval.h"#include "mpi.h"#include "time.h"#include "iostream.h"
Erich,
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:
#include <iostream> rather than #include "iostream.h"
#include <ctime> rather than #include "time.h"
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:
furlong:~ samm$ cat badheader.cc
#include <iostream.h>
int main() {
cout << "hello world" << endl;
}
furlong:~ samm$ g++ badheader.cc
In file included from /usr/include/c++/4.0.0/backward/iostream.h:31,
from badheader.cc:1:
/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.
furlong:~ samm$ ./a.out
hello world
furlong:~ samm$ cat goodheader.cc
#include <iostream>
using std::cout;
using std::endl;
int main() {
cout << "hello world" << endl;
}
furlong:~ samm$ g++ goodheader.cc
furlong:~ samm$ ./a.out
hello world
furlong:~ samm$
This was on a mac w/ gcc 4.0.1 but you should see similar results on a Linux box or cluster.
Cheers,
Sam Miller
http://www.sammiller.org
"Generally speaking, people provide better maintenance for their cars than for their own bodies." - Scott Adams
_________________________________________________________________
Invite your mail contacts to join your friends list with Windows Live Spaces. It's easy!
http://spaces.live.com/spacesapi.aspx?wx_action=create&wx_url=/friends.aspx&mkt=en-us
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/mpich-discuss/attachments/20070418/96e056a0/attachment.htm>
More information about the mpich-discuss
mailing list