I am testing my program to update a number (num_commit) always at the end of the file. This number is used to track how many times the files has been written. I am using lseek/SEEK_END, but I am still trying to figure out how this works. I wrote the following code to test the possibility, but the num_commit seems overwritten. I am looking for help with the correct way of doing this:
#define MAX_PATHNAME_LEN 256
int main()
{
int commit_times = 10;
char pathFile[MAX_PATHNAME_LEN];
sprintf(pathFile, "my_log2.bin");
int filedescriptor = open(pathFile, O_RDWR | O_CREAT, 0777);
int num_segs = 10;
int mods = 200;
const char *segname = "testfil";
char real_segname[128];
strcpy(real_segname, segname); /* in my real program segname is passed into the function */
lseek(filedescriptor, 0, SEEK_END); /* write commit_times always at the end of the file */
write(filedescriptor, &commit_times, sizeof(int));
lseek(filedescriptor, 0, SEEK_SET); /* start writing at the beginning */
write(filedescriptor, &num_segs, sizeof(int));
int name_length = strlen(real_segname);
write(filedescriptor, &name_length, sizeof(int));
write(filedescriptor, real_segname, name_length);
write(filedescriptor, &mods, sizeof(int));
commit_times++; /* increment commit_times */
lseek(filedescriptor, -sizeof(int), SEEK_END); /* then update the commit_times at the end of the file (overwrite the existing number) */
write(filedescriptor, &commit_times, sizeof(int));
close(filedescriptor);
/* now read back the file */
int readfd = open(pathFile, O_RDONLY);
read(readfd, &num_segs, sizeof(int));
read(readfd, &name_length, sizeof(int));
read(readfd, real_segname, name_length);
read(readfd, &mods, sizeof(int));
int num_commit;
read(readfd, &num_commit, sizeof(int));
printf("num_segs=%d, name_length=%d, real_segname=%s, mods=%d, num_commit=%d \n", num_segs, name_length, real_segname, mods, num_commit);
close(readfd);
return 0;
}
Here's my output, as you can see num_commit is overwritten by the mods value:
num_segs=10, name_length=7, real_segname=testfil, mods=200, num_commit=200
This is my answer to my original question. The code below will always write the number of commits at the end of the file. Whenever new entries are written to the file, I make sure it will overwrite the last number of commits and append new number of commits at the end. This way will increment the number of commits and maintain only one copy of num_commit always at the end of the file.
int main()
{
int name_length;
char pathFile[MAX_PATHNAME_LEN];
sprintf(pathFile, "my_log2.bin");
int filedescriptor = open(pathFile, O_RDWR | O_CREAT, 0777);
int num_segs = 10;
int mods = 200;
const char *segname = "testfil";
char real_segname[128];
strcpy(real_segname, segname); /* in my real program segname is passed into the function */
int i;
for (i = 1; i <= 100; i++)
{
if (i > 1)
{
lseek(filedescriptor, -sizeof(int), SEEK_END); /* overwrite the last num_commit */
}
write(filedescriptor, &num_segs, sizeof(int));
name_length = strlen(real_segname);
write(filedescriptor, &name_length, sizeof(int));
write(filedescriptor, real_segname, name_length);
write(filedescriptor, &mods, sizeof(int));
write(filedescriptor, &i, sizeof(int)); /* number of commits */
}
close(filedescriptor);
/* now read back the file */
int readfd = open(pathFile, O_RDONLY);
lseek(readfd, -sizeof(int), SEEK_END); /* read the number of commit first from the end of the file */
int num_commit;
read(readfd, &num_commit, sizeof(int));
printf("num_commit = %d \n", num_commit);
lseek(readfd, 0, SEEK_SET); /* start reading from the beginning of the file*/
int a, b, m;
char *name;
for (i = 0; i < num_commit; i++)
{
read(readfd, &a, sizeof(int));
read(readfd, &b, sizeof(int));
name = malloc(b);
read(readfd, name, b);
read(readfd, &m, sizeof(int));
printf("commit# = %d, num_segs=%d, name_length=%d, real_segname=%s, mods=%d \n", i+1, a, b, name, m);
free(name);
name = NULL;
}
close(readfd);
return 0;
}
As an alternative, I also tested maintaining the num_commit at the beginning of the file, which is a lot easier/less mind-twisting than using SEEK_END:
#define MAX_PATHNAME_LEN 256
int main()
{
int commit_times = 10;
char pathFile[MAX_PATHNAME_LEN];
sprintf(pathFile, "my_log2.bin");
int filedescriptor = open(pathFile, O_RDWR | O_CREAT, 0777);
int num_segs = 10;
int mods = 200;
const char *segname = "testfil";
char real_segname[128];
// strncpy(real_segname, segname, sizeof(real_segname));
strcpy(real_segname, segname);
lseek(filedescriptor, 0, SEEK_SET); /* write commit_times always at the beginning of the file */
write(filedescriptor, &commit_times, sizeof(int));
lseek(filedescriptor, sizeof(int), SEEK_SET); /* start writing after num_commit value */
write(filedescriptor, &num_segs, sizeof(int));
int name_length = strlen(real_segname);
write(filedescriptor, &name_length, sizeof(int));
write(filedescriptor, real_segname, name_length);
write(filedescriptor, &mods, sizeof(int));
commit_times++;
lseek(filedescriptor, 0, SEEK_SET); /* update the commit_times at the beginning of the file */
write(filedescriptor, &commit_times, sizeof(int));
close(filedescriptor);
/* now read back the file */
int readfd = open(pathFile, O_RDONLY);
int num_commit;
read(readfd, &num_commit, sizeof(int));
read(readfd, &num_segs, sizeof(int));
read(readfd, &name_length, sizeof(int));
read(readfd, real_segname, name_length);
read(readfd, &mods, sizeof(int));
printf("num_segs=%d, name_length=%d, real_segname=%s, mods=%d, num_commit=%d \n", num_segs, name_length, real_segname, mods, num_commit);
close(readfd);
return 0;
}
Related
I'm facing a very odd issue when trying to read a file in C.
I've parsed a file path via a command line argument, and gotten the size using the stat() function, and this works fine. However, after I read the file, all of my integers become arbitrarily large, and I cannot for the life of me figure out why!
Here is the relevant code from my main function:
int main( int argc, char *argv[] ) {
char *filepath = argv[1];
startaddress = strtol(argv[2], &endptra, 16);
endaddress = strtol(argv[3], &endptrb, 16);
int filesize = getfilesize(filepath);
printf("Filesize is %d\n", filesize);
unsigned char *mem = malloc( filesize );
printf("Filesize here is %d\n", filesize);
int size2 = filesize;
int test3 = 18;
printf("Size 2 set to %d\n", size2);
printf("Test 3 set to %d\n", test3);
// READ FILE
loadimage(filepath, &mem, filesize);
printf("Right after load image, file size is %d\n", filesize);
printf("%s\n", strerror(errno));
printf("Filesize is %d\n", filesize);
printf("size2: %d\n", size2);
printf("test3: %d\n", test3);
exit(0);
}
"getfilesize" is a relatively simple function that appears to work well:
int getfilesize(char *path) {
struct stat sbuffer;
int filesize = 0;
filesize = stat(path, &sbuffer);
if (filesize == -1) {
return 0;
} else {
return sbuffer.st_size;
}
}
Here is the loadimage function:
int loadimage(char *path, unsigned char *mem[], int size) {
int fdin, retval;
unsigned char buf[2048];
int nread;
printf("Path is: %s\n", path);
printf("Size is: %d\n", size);
fdin = open(path, O_RDONLY);
printf("fdin: %d\n", fdin);
if(fdin == -1) {
die(strerror( errno ));
}
int count = 0;
nread = read(fdin, buf, 2048);
for(; count < nread; count++) {
mem[count] = &buf[count];
}
if(nread == -1) {
die(strerror( errno ));
}
retval = close(fdin);
printf("Size is now %d\n", size);
return 1;
}
And this is the output of the result:
Filesize is 39
Filesize here is 39
Size 2 set to 39
Test 3 set to 18
Path is: test_file.txt
Size is: 39
fdin: 3
Size is now 39
Right after load image, file size is 32765
Success
Filesize is 32765
size2: 1418855892
test3: 32765
This is baffling to me and I cannot figure it out! It's confusing that even integers that I don't pass to the function are being modified as well. I'm assuming there's some sort of memory overflow happening somewhere, but I'm not used to working in the file system in C.
Thanks!
It seems to me that the problem is here:
int loadimage(char *path, unsigned char *mem[], int size) {
The mem argument should be just a pointer, or just an array, but not both. Aside from that, you're doing the same with the buf local variable, you're dereferencing it more than once when you use it (however that case might be harmless, I'm not sure). loadimage() should be:
int loadimage(char *path, unsigned char *mem, int size) {
int fdin, retval;
unsigned char buf[2048];
int nread;
printf("Path is: %s\n", path);
printf("Size is: %d\n", size);
fdin = open(path, O_RDONLY);
printf("fdin: %d\n", fdin);
if(fdin == -1) {
die(strerror( errno ));
}
int count = 0;
nread = read(fdin, buf, 2048);
for(; count < nread; count++) {
mem[count] = buf[count]; //no need for derefencing
}
if(nread == -1) {
die(strerror( errno ));
}
retval = close(fdin);
printf("Size is now %d\n", size);
return 1;
}
then, when calling it, do not dereference mem:
loadimage(filepath, mem, filesize);
Sorry, I don't have time so I haven't compiled it, but you get the idea, most probably that's the problem.
I am trying to write multiple random numbers into the memory, but I am having an issue where the for loop does not initilize the number required, and I get an output of one random integer, and random number of spaces and new lines.
int random_range (unsigned const low, unsigned const high) {...}
/* Create and write to a shared file for communication with another process.
*
* argv[1] = file name
*
* Note: Error processing is omitted
*/
int main (int argc, char* const argv[]) {
int fd;
int* file_memory;
int numOfInt;
numOfInt = atoi(argv[2]); //Turning 2nd argument into an integer
/* seed the random number generator */
srand (time (NULL));
/* open or create a file to hold an unsigned integer */
fd = open (argv[1], O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
/* write FILESIZE spaces */
for (int i=0; i<FILESIZE; i++) write (fd, " ", 1);
write (fd, "", 1); /* write a NULL at EOF */
file_memory = mmap (NULL, FILESIZE, PROT_WRITE, MAP_SHARED, fd, 0);
close (fd);
int* temp = file_memory;
/* write a random integer to memory-mapped area */
for(int x=0; x<numInt; ++x){
if(x!=(numInt-1))
sprintf((char*) file_memory++, "%d ", random_range (-100, 100));
else
sprintf((char*) file_memory++, "%d\n",random_range (-100, 100));
}
file_memory = temp;
/* release the memory */
munmap (file_memory, FILESIZE);
}
I wrote a toy program to learn file I/O in C, the following is part of my code, and the output from this program is just wrong - I've no idea what is wrong in my code.
int fd = open(path_to_file, O_RDWR | O_APPEND | O_CREAT, 0777);
int size = 100;
int offset = 0;
write(fd, &size, sizeof(int));
write(fd, &offset, sizeof(int));
lseek(fd, 0, SEEK_SET); /* start reading from the beginning */
int *size = malloc(sizeof(int));
int *offset = malloc(sizeof(int));
read(fd, size, sizeof(int));
read(fd, offset, sizeof(int));
printf("size is %d, offset is %d \n", *size, *offset);
free(size);
free(offset);
The output I got is:
size is 1953719668, offset is 1684497779
These numbers are so huge, but they should be 100, and 0, respectively. I don't understand how this happens. Could someone offer help with understanding this?
Ingo has it right, if the file already exists you append to it...
Mallocing for 1 single int is not very efficient, but that should work.
I guess you copied and pasted your code, the same names on variables prevent it from compiling.
Working example even if the file exists:
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int main() {
int fd = open("test.dat", O_RDWR | O_CREAT, 0777);
int size = 100;
int offset = 0;
write(fd, &size, sizeof(int));
write(fd, &offset, sizeof(int));
lseek(fd, 0, SEEK_SET); /* start reading from the beginning */
int *result_size = malloc(sizeof(int));
int *result_offset = malloc(sizeof(int));
read(fd, result_size, sizeof(int));
read(fd, result_offset, sizeof(int));
printf("size is %d, offset is %d \n", *result_size, *result_offset);
free(result_size);
free(result_offset);
}
I am working on a project of converting a Point to Point Communication to a Collective Communication.
Essentially, what I would like to do is use MPI_Scatterv instead of MPI_Send and MPI_Recv. What I am having trouble determining is the correct arguments for Scatterv.
Here is the function that I am working in:
void read_block_vector (
char *s, /* IN - File name */
void **v, /* OUT - Subvector */
MPI_Datatype dtype, /* IN - Element type */
int *n, /* OUT - Vector length */
MPI_Comm comm) /* IN - Communicator */
{
int datum_size; /* Bytes per element */
int i;
FILE *infileptr; /* Input file pointer */
int local_els; /* Elements on this proc */
MPI_Status status; /* Result of receive */
int id; /* Process rank */
int p; /* Number of processes */
int x; /* Result of read */
datum_size = get_size (dtype);
MPI_Comm_size(comm, &p);
MPI_Comm_rank(comm, &id);
/* Process p-1 opens file, determines number of vector
elements, and broadcasts this value to the other
processes. */
if (id == (p-1)) {
infileptr = fopen (s, "r");
if (infileptr == NULL) *n = 0;
else fread (n, sizeof(int), 1, infileptr);
}
MPI_Bcast (n, 1, MPI_INT, p-1, comm);
if (! *n) {
if (!id) {
printf ("Input file '%s' cannot be opened\n", s);
fflush (stdout);
}
}
/* Block mapping of vector elements to processes */
local_els = BLOCK_SIZE(id,p,*n);
/* Dynamically allocate vector. */
*v = my_malloc (id, local_els * datum_size);
if (id == (p-1)) {
for (i = 0; i < p-1; i++) {
x = fread (*v, datum_size, BLOCK_SIZE(i,p,*n),
infileptr);
MPI_Send (*v, BLOCK_SIZE(i,p,*n), dtype, i, DATA_MSG,
comm);
}
x = fread (*v, datum_size, BLOCK_SIZE(id,p,*n),
infileptr);
fclose (infileptr);
} else {
MPI_Recv (*v, BLOCK_SIZE(id,p,*n), dtype, p-1, DATA_MSG,
comm, &status);
}
// My Attempt at making this collective communication:
if(id == (p-1))
{
x = fread(*v,datum_size,*n,infileptr);
for(i = 0; i < p; i++)
{
size[i] = BLOCK_SIZE(i,p,*n);
}
//x = fread(*v,datum_size,BLOCK_SIZE(id, p, *n),infileptr);
fclose(infileptr);
}
MPI_Scatterv(v,send_count,send_disp, dtype, storage, size[id], dtype, p-1, comm);
}
Any help would be appreciated.
Thank you
It's easier for people to answer your question if you post a small, self-contained, reproducible example.
For the Scatterv, you need to provide the list of counts to send to each process, which appears to be your size[] array, and the displacements within the data to send out. The mechanics of Scatter vs Scatterv are described in some detail in this answer. Trying to infer what all your variables and un-supplied functions/macros do, the example below scatters a file out to the processes.
But also note that if you're doing this, it's not much harder to actually use MPI-IO to coordinate the file access directly, avoiding the need to have one process read all of the data in the first place. Code for that is also supplied.
#include <stdio.h>
#include <stdlib.h>
#include <mpi.h>
int main(int argc, char **argv) {
int id, p;
int *block_size;
int datasize = 0;
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &p);
MPI_Comm_rank(MPI_COMM_WORLD, &id);
block_size = malloc(p * sizeof(int));
for (int i=0; i<p; i++) {
block_size[i] = i + 1;
datasize += block_size[i];
}
/* create file for reading */
if (id == p-1) {
char *data = malloc(datasize * sizeof(char));
for (int i=0; i<datasize; i++)
data[i] = 'a' + i;
FILE *f = fopen("data.dat","wb");
fwrite(data, sizeof(char), datasize, f);
fclose(f);
printf("Initial data: ");
for (int i=0; i<datasize; i++)
printf("%c", data[i]);
printf("\n");
free(data);
}
if (id == 0) printf("---Using MPI-Scatterv---\n");
/* using scatterv */
int local_els = block_size[id];
char *v = malloc ((local_els + 1) * sizeof(char));
char *all;
int *counts, *disps;
counts = malloc(p * sizeof(int));
disps = malloc(p * sizeof(int));
/* counts.. */
for(int i = 0; i < p; i++)
counts[i] = block_size[i];
/* and displacements (where the data starts within the send buffer) */
disps[0] = 0;
for(int i = 1; i < p; i++)
disps[i] = disps[i-1] + counts[i-1];
if(id == (p-1))
{
all = malloc(datasize*sizeof(char));
FILE *f = fopen("data.dat","rb");
int x = fread(all,sizeof(char),datasize,f);
fclose(f);
}
MPI_Scatterv(all, counts, disps, MPI_CHAR, v, local_els, MPI_CHAR, p-1, MPI_COMM_WORLD);
if (id == (p-1)) {
free(all);
}
v[local_els] = '\0';
printf("[%d]: %s\n", id, v);
/* using MPI I/O */
fflush(stdout);
MPI_Barrier(MPI_COMM_WORLD); /* only for syncing output to screen */
if (id == 0) printf("---Using MPI-IO---\n");
for (int i=0; i<local_els; i++)
v[i] = 'X';
/* create the file layout - the subarrays within the 1d array of data */
MPI_Datatype myview;
MPI_Type_create_subarray(1, &datasize, &local_els, &(disps[id]),
MPI_ORDER_C, MPI_CHAR, &myview);
MPI_Type_commit(&myview);
MPI_File mpif;
MPI_Status status;
MPI_File_open(MPI_COMM_WORLD, "data.dat", MPI_MODE_RDONLY, MPI_INFO_NULL, &mpif);
MPI_File_set_view(mpif, (MPI_Offset)0, MPI_CHAR, myview, "native", MPI_INFO_NULL);
MPI_File_read_all(mpif, v, local_els, MPI_CHAR, &status);
MPI_File_close(&mpif);
MPI_Type_free(&myview);
v[local_els] = '\0';
printf("[%d]: %s\n", id, v);
free(v);
free(counts);
free(disps);
MPI_Finalize();
return 0;
}
Running this gives (output re-ordered for clarity)
$ mpirun -np 6 ./foo
Initial data: abcdefghijklmnopqrstu
---Using MPI-Scatterv---
[0]: a
[1]: bc
[2]: def
[3]: ghij
[4]: klmno
[5]: pqrstu
---Using MPI-IO---
[0]: a
[1]: bc
[2]: def
[3]: ghij
[4]: klmno
[5]: pqrstu
i'm writing a C/MPI program that making many processes read from a data file.
When using the standard functions from stdio (fopen, fread, fseek) everything goes well. The problem that i can't go beyond 4 Go offsets. So i used MPI-IO functions to read a big file and at this moment memory doesn't liberate well.
In fact i read a buffer, i process it then i free the allocated memory. The memory usage per process is perfect but the global memory usage doesn't stop increasing. I don't have this problem by just replacing mpi_file_read at by fread.
there is my code :
double CPUtime(){ return ((double) clock())/CLOCKS_PER_SEC;}int main(int argc, char* argv []){
if(argc != 5) {
printf("\t[Dictionary file] [Dictionary] [Input file] [Buffer size]\n");
exit(0);
}
char* sInput = malloc (sizeof(char)*maxLength);
char* sOutput = malloc (sizeof(char)*maxLength);
char* compl = malloc (sizeof(char)*maxLength);
char* sDictionaryFileName = argv[1];
char* sDictionaryName = argv[2];
char* filename = argv[3];
int Mbuffer = atoi(argv[4]);
int maxBuffer = Mbuffer*1024*1024;
int over = 10000;
int rank,numprocess;
long int offset;
char* buffer;
char* opbuffer;
double tstart=CPUtime();
MPI_Init( &argc, &argv );
MPI_Comm_rank( MPI_COMM_WORLD, &rank );
/* mpi version */
/* open the file*/
MPI_File fh;
int err;
err = MPI_File_open(MPI_COMM_WORLD, filename, MPI_MODE_RDONLY, MPI_INFO_NULL, &fh);
if (err != MPI_SUCCESS) {
char errstr[MPI_MAX_ERROR_STRING];
int errlen;
MPI_Error_string(err, errstr, &errlen);
printf("Error at opening file %s (%s)\n",filename,errstr);
MPI_Finalize();
exit(1);
}
// get offsets and buffer size
MPI_Offset sfile;
MPI_File_get_size(fh,&sfile);
MPI_Status status;
/* C version */
/*FILE* fh;
long int sfile;
fh =fopen( filename,"rb");
if (fh==NULL) {
printf("Error at opening file %s\n",filename);
exit(1);
}
// get offsets and buffer size
fseek(fh, 0L, SEEK_END);
sfile = ftell(fh);
fseek(fh, 0L, SEEK_SET);*/
MPI_Comm_size( MPI_COMM_WORLD, &numprocess );
/* number of iterations */
long int data_size = (long int)(sfile/(numprocess));
int nbIter = data_size/maxBuffer;
if(nbIter<=1){
nbIter = 1;
maxBuffer = data_size;
}
/* offsets */
offset = data_size*(rank);
long int cursor = offset;
char* header;
if(rank==0){
FILE* fh;
fh =fopen( filename,"rb");
if (fh==NULL) {
printf("Error at opening file %s\n",filename);
exit(1);
}
/* read the header and broadcast it */
header = malloc(sizeof(char)*1000);
fgets(header,1000,fh);
fclose(fh);
//broadcast header
int sndHeader = strlen(header);
//cursor+=sndHeader;
int process_counter;
for(process_counter=1;process_counter<numprocess;process_counter++){
int ierr = MPI_Send(&sndHeader, 1, MPI_INT, process_counter, 42,MPI_COMM_WORLD);
if (ierr != MPI_SUCCESS) {
int errclass,resultlen;
char err_buffer[MPI_MAX_ERROR_STRING];
MPI_Error_class(ierr,&errclass);
if (errclass== MPI_ERR_RANK) {
fprintf(stderr,"Invalid rank used in MPI send call\n");
MPI_Error_string(ierr,err_buffer,&resultlen);
fprintf(stderr,err_buffer);
MPI_Finalize();
}
}
MPI_Send(header, sndHeader, MPI_CHAR, process_counter, 43, MPI_COMM_WORLD);
}
}
else{
/* receive the header */
int sizeofHeader;
MPI_Status s ;
MPI_Recv(&sizeofHeader,1,MPI_INT,0,42,MPI_COMM_WORLD,&s);
header = malloc (sizeof(char)*sizeofHeader+1);
MPI_Recv(header,sizeofHeader,MPI_CHAR,0,43,MPI_COMM_WORLD,&s);
}
/* Synchronization barrier */
MPI_Barrier(MPI_COMM_WORLD);
int count;
opbuffer = malloc(sizeof(char)*maxBuffer);
/* C version */
//fseek(fh,cursor,SEEK_SET);
for(count=0;count<nbIter;count++){
if(count==0 && rank==numprocess-1){ //init ring
//send the token to p0
int token=1;
MPI_Send(&token,sizeof(int),MPI_INT,0,55,MPI_COMM_WORLD);
}
//recv
int token;
int sender;
if(rank==0)
sender = numprocess-1;
else
sender=rank-1;
MPI_Status s;
MPI_Recv(&token,sizeof(int),MPI_INT,sender,55,MPI_COMM_WORLD,&s);
fflush(stdout);printf("P%d got the token at %G\n",rank,CPUtime());
//read
double start=CPUtime();
/*double readtime;
double sread=CPUtime();//read time*/
//read
if(token==1){
/* MPI version */
int err=MPI_File_read_at(fh, cursor,opbuffer, sizeof(char)*maxBuffer, MPI_CHAR, &status);
if(err!=MPI_SUCCESS){
/*char errstr[MPI_MAX_ERROR_STRING];
int errlen;
MPI_Error_string(err, errstr, &errlen);
printf("Error reading file %s (%s)\n",filename,errstr);*/
MPI_Finalize();
exit(0);
}
/* C version of read */
/*int k=fread(opbuffer,sizeof(char),maxBuffer,fh);
if(k==0)
perror("fread");*/
cursor+=maxBuffer;
buffer=opbuffer;
}
else{
printf("Error token!\n");
token=1;
}
//printf("P%d readtime=%G\n",rank,CPUtime()-sread);
//Isend
int next = (rank+1)%numprocess;
MPI_Send(&token,sizeof(int),MPI_INT,next,55,MPI_COMM_WORLD);
/* start processing*/
/* end processing */
}
free(opbuffer);
int er=MPI_File_close(&fh);
if(er!=MPI_SUCCESS){
printf("Error closing file\n");
MPI_Finalize();
exit(1);
}
MPI_Finalize();
printf("Global time : %G\n",CPUtime()-tstart);
return 0;
}
If any one have any idea of what is it i would apprciate that.
Thank you.
It's probably that you're never calling MPI_File_close. That will cause intermediate operations on the file to leak. Note that you should also close it under the error condition if(err!=MPI_SUCCESS) if you really want to write clean code.