Hello all,
I have a program in which 2 threads write data to a pvfs2 fs using the writev function. I am seeing an incorrect file size after the writes are done.

This is what the program does:
- Spawn 2 threads using OpenMP. Thread0 will write to file test1.out, thread1 will write to file test2.out - In a single writev call, each thread writes an iovec array of 512 elements, each element of size 1M. So a single writev call writes 512M data. This cycle is performed twice in total, so each thread writes a file of size 1G.

Once the program finishes, I see that the two files created are of size 512M each, instead of 1G. I ran this program on a local hard drive, and it works fine.

I have attached the program here. Any help is appreciated.

Regards,
Kshitij Mehta
PhD candidate
Parallel Software Technologies Lab
Dept. of Computer Science
University of Houston
Houston, Texas, USA
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <sys/time.h>
#include <sys/uio.h>
#include <unistd.h>
#include <errno.h>
#include <omp.h>

int seg_rows, DEBUG, num_threads; //num_threads to be ignored for this program
double total_size, t1, t2;
long seg_size;
char* filename;

void omp_write_sep();

typedef struct _LL
{
        char *str;
        struct _LL* next;
} LL;

void create_ll(LL** head)
{
        int i;
        LL* prev = NULL;
        for (i=0; i<seg_rows; i++)
        {
                LL *tmpll = (LL *) malloc (sizeof(LL));
                tmpll->str = (char*) malloc (seg_size * sizeof(char));

                tmpll->next = NULL;
                if(i==0)
                        *head = tmpll;
                else
                        prev->next = tmpll;

                prev = tmpll;
        }
}

void create_iovec(struct iovec ** iovarr, LL* head)
{
        *iovarr = (struct iovec *) malloc (seg_rows * sizeof(struct iovec));

        int i;
        LL* iterator = head;
        for (i=0; i<seg_rows; i++)
        {
                (*iovarr)[i].iov_base = iterator->str;
                (*iovarr)[i].iov_len = seg_size;
                iterator = iterator->next;
        }
}

int main(int argc, char** argv)
{
        //initialize some variables
        DEBUG = 1;      //enable printing
        num_threads = 2;        
        total_size = 2147483648; //2GB
        seg_size = 1048576;     //1MB
        seg_rows = 512;

        omp_write_sep();
        return 0;
}

void omp_write_sep()
{
        int iter, i;
        iter = total_size/(num_threads*seg_rows*seg_size);
#pragma omp parallel default(shared) private(i)
        {
                int fd;
                LL* my_ll;
                create_ll (&my_ll);
                struct iovec* iovarr;
                create_iovec (&iovarr, my_ll);

                if(omp_get_thread_num() == 0)
                        filename="/pvfs2/test1.out";
                else
                        filename="/pvfs2/test2.out";

                if(-1 == (fd = open(filename, O_RDWR|O_CREAT, 0644)))
                {
                        fprintf(stderr, "Error opening file. Exiting..\n");
                        exit(-1);
                }   

                for(i=0; i<iter; i++)
                {
                        if(DEBUG) 
                        {
                                printf("T%d iter %d\n", omp_get_thread_num(), 
i);
                                printf("T%d wrote %ld bytes\n", 
omp_get_thread_num(), writev(fd, iovarr, seg_rows));
                        }
                        else
                                writev(fd, iovarr, seg_rows);
                }   //omp for
                fsync(fd);

                close(fd);
        }       //omp parallel 
}
_______________________________________________
Pvfs2-users mailing list
[email protected]
http://www.beowulf-underground.org/mailman/listinfo/pvfs2-users

Reply via email to