/* simple test case for shared file IO.
You MUST run it with 'yod -masync' or your IO will be ~15MB/sec
*/
#include <stdio.h>
#include <errno.h>
#include <nx.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#define FILNM "/pfs/pfay/tmp/tmpa"
#define FILNM "/pfs_grande/multi/tmp_1/pfay/tmp/tmpa"
#define MAX_WRITES 50
#define BUF_SIZE (2*1024*1024)
char buf[BUF_SIZE];
int main(int argc, char **argv)
{
void *dum, *dum1;
int status,i,fd,j,rc;
double x,y,bytes;
long long offset;
int max_writes=MAX_WRITES;
for(j=0; j<=2; j++)
{
fd = open(FILNM,O_WRONLY|O_CREAT,0777);
offset = mynode()*sizeof(buf);
if(fd == -1)
{fprintf(stderr,"cant open file\n"); perror(""); exit(1);}
if(j==0){max_writes = 10;}
else{max_writes = 50;}
bytes=0;
gsync();
x = dclock();
for(i=0; i< max_writes; i++)
{
if(j==0) {
eseek(fd,offset,SEEK_SET);
write(fd,buf,sizeof(buf));
}
if(j==1) {
eseek(fd,offset,SEEK_SET);
cwrite(fd,buf,sizeof(buf));
}
if(j==2) {
rc = iwriteoff(fd,offset,buf,sizeof(buf));
iowait(rc);
}
bytes += sizeof(buf);
offset += numnodes()*sizeof(buf);
}
gsync();
y = (dclock() -x);
x = bytes*numnodes()/(1024.0*1024.0);
close(fd);
if(mynode()==0) {
if(j==0){printf("eseek/write() runs at %f MB/s\n",x/y);}
if(j==1){printf("eseek/cwrite() runs at %f MB/s\n",x/y);}
if(j==2){printf("iwriteoff() runs at %f MB/s\n",x/y);}
}
fd = open(FILNM,O_RDONLY);
offset = mynode()*sizeof(buf);
if(fd == -1)
{fprintf(stderr,"cant open file\n"); perror(""); exit(1);}
bytes=0;
gsync();
x = dclock();
for(i=0; i< max_writes; i++)
{
if(j==0) {
eseek(fd,offset,SEEK_SET);
read(fd,buf,sizeof(buf));
}
if(j==1) {
eseek(fd,offset,SEEK_SET);
cread(fd,buf,sizeof(buf));
}
if(j==2) {
rc = ireadoff(fd,offset,buf,sizeof(buf));
iowait(rc);
}
offset += numnodes()*sizeof(buf);
bytes += sizeof(buf);
}
gsync();
y = (dclock() -x);
x = bytes*numnodes()/(1024.0*1024.0);
close(fd);
if(mynode()==0) {
if(j==0){printf("eseek/read() runs at %f MB/s\n",x/y);}
if(j==1){printf("eseek/cread() runs at %f MB/s\n",x/y);}
if(j==2){printf("ireadoff() runs at %f MB/s\n",x/y);}
}
}
}
Acknowledgement and Disclaimer