unsigned int map_getport(mapping_t* pmap) { int port; struct pbuf *pbuf; struct pbuf *ret; debug("Getting port\n"); pmap->port = 0; /* add the xid */ pbuf = initbuf(PMAP_NUMBER, PMAP_VERSION, PMAPPROC_GETPORT); /* pack up the map struct */ addtobuf(pbuf, (char*) pmap, sizeof(mapping_t)); /* make the call */ ret = rpc_call(pbuf, PMAP_PORT); assert(ret != NULL); /* now we can extract the port */ getfrombuf(ret, (char*) &port, sizeof(port)); pmap->port = port; debug("Got port %d\n", port); return 0; }
int nfs_write(struct cookie *fh, int offset, int count, void *data, void (*func) (uintptr_t, int, fattr_t *), uintptr_t token) { struct pbuf *pbuf; writeargs_t args; /* now the user data struct is setup, do some call stuff! */ pbuf = initbuf(NFS_NUMBER, NFS_VERSION, NFSPROC_WRITE); /* copy in the fhandle */ memcpy(&args.file, (char*) fh, sizeof(struct cookie)); args.offset = offset; args.beginoffset = 0; /* unused as per RFC */ args.totalcount = 0; /* unused as per RFC */ /* add them to the buffer */ addtobuf(pbuf, (char*) &args, sizeof(args)); /* put the data in */ adddata(pbuf, data, count); return rpc_send(pbuf, nfs_port, nfs_write_cb, func, token); }
/* send a request for a directory item */ int nfs_readdir(struct cookie *pfh, int cookie, int size, void (*func) (uintptr_t , int, int, struct nfs_filename *, int), uintptr_t token) { readdirargs_t args; struct pbuf *pbuf; /* now the user data struct is setup, do some call stuff! */ pbuf = initbuf(NFS_NUMBER, NFS_VERSION, NFSPROC_READDIR); /* copy the buffer */ memcpy(&args.dir, pfh, sizeof(struct cookie)); /* set the cookie */ args.cookie = cookie; args.count = size; /* copy the arguments into the packet */ addtobuf(pbuf, (char*) &args, sizeof(args)); /* make the call! */ return rpc_send(pbuf, nfs_port, nfs_readdir_cb, func, token); }
unsigned int mnt_get_export_list(void) { struct pbuf *pbuf; struct pbuf *ret; char str[100]; int opt; pbuf = initbuf(MNT_NUMBER, MNT_VERSION, MNTPROC_EXPORT); ret = rpc_call(pbuf, mount_port); while (getfrombuf(ret, (char*) &opt, sizeof(opt)), opt) { debug( "NFS Export...\n" ); getstring(ret, str, 100); debug( "* Export name is %s\n", (char*) &str ); /* now to extract more stuff... */ while (getfrombuf(ret, (char*) &opt, sizeof(opt)), opt) { getstring(ret, str, 100 ); debug("* Group %s\n", (char*) str); } } return 0; }
int init_socket(socket_queue *sock) { int RetCode; if (!sock) return -1; if ((RetCode = initbuf(&(sock->msgbuf))) != 0) return RetCode; if ((RetCode = initbuf(&(sock->restbuf))) != 0) return RetCode; return 0; }
unsigned int mnt_mount(char *dir, struct cookie *pfh) { struct pbuf *pbuf, *ret; int status; pbuf = initbuf(MNT_NUMBER, MNT_VERSION, MNTPROC_MNT); addstring(pbuf, dir); ret = rpc_call(pbuf, mount_port); if (ret == 0) { debug( "mount call failed :(\n" ); return 1; } /* now we do some stuff :) */ getfrombuf(ret, (char*) &status, sizeof(status)); if (status != 0) { debug( "Could not mount %s, %d!\n", dir, status ); return 1; } debug("All seems good for mount: %s!\n", dir); getfrombuf(ret, (char*) pfh, sizeof(struct cookie)); return 0; }
void PrintBuf::init(PtrLen<char> buf) { close(); clearOverflowFlag(); initbuf(buf); }
int main(int argc, char **argv) { int c; const char *termtype; FILE *f; char termcap[1024]; setlocale(LC_ALL, ""); termtype = getenv("TERM"); if (termtype == NULL || (argv[0][0] == 'c' && !isatty(1))) termtype = "lpr"; while ((c=getopt(argc, argv, "it:T:")) != -1) switch(c) { case 't': case 'T': /* for nroff compatibility */ termtype = optarg; break; case 'i': iflag = 1; break; default: usage(); } switch(tgetent(termcap, termtype)) { case 1: break; default: warnx("trouble reading termcap"); /* FALLTHROUGH */ case 0: /* No such terminal type - assume dumb */ (void)strcpy(termcap, "dumb:os:col#80:cr=^M:sf=^J:am:"); break; } initcap(); if ( (tgetflag("os") && ENTER_BOLD==NULL ) || (tgetflag("ul") && ENTER_UNDERLINE==NULL && UNDER_CHAR==NULL)) must_overstrike = 1; initbuf(); if (optind == argc) filter(stdin); else for (; optind<argc; optind++) { f = fopen(argv[optind],"r"); if (f == NULL) err(1, "%s", argv[optind]); else filter(f); } exit(0); }
int main(){ char *response; char buf[1024]; int exersocket, getsocket; socklen_t getsocketlen; struct sockaddr_in exer_addr, get_addr; iserror = 0; bzero((char *)&exer_addr,sizeof(exer_addr)); exer_addr.sin_family = AF_INET; exer_addr.sin_port = getexerport(); exer_addr.sin_addr.s_addr = getexerip(); printf("\nexer: to ip: %x port: %d h ip: %x port: %d\n", exer_addr.sin_addr.s_addr, exer_addr.sin_port, getexerip(), getexerport()); exersocket = socket(AF_INET,SOCK_STREAM,0); if (exersocket < 0) { printf("\nexer: fail to create server socket, socketid: %d\n", exersocket); exit(1); } printf("\nexer: succeed to create server socket, socketid: %d\n", exersocket); if (bind(exersocket,(struct sockaddr *)&exer_addr,sizeof(exer_addr)) < 0) { printf("\nexer: fail to bind server socket\n"); exit(1); } printf("\nexer: succeed to bind server socket\n"); if (listen(exersocket, 5) < 0) { printf("\nexer: fail to listen %x : %d\n", exer_addr.sin_addr.s_addr, exer_addr.sin_port); exit(1); } bzero(&get_addr, sizeof(get_addr)); while (1) { if ((getsocket = accept(exersocket, (sockaddr *)&get_addr, &getsocketlen)) < 0) { printf("\nexer: fail to accept\n"); exit(1); } //recv command if (recv(getsocket, buf, 1024, 0) < 0) { printf("\nexer: fail to recv response\n"); exit(1); } printf("\nsayer: %s\n", buf); //do command doonecommand(buf); initbuf(buf); //say back to sayer response = getresponse(); if (send(getsocket, response, strlen(response), 0) < 0) { printf("\nexer: fail to send back\n"); exit(1); } printf("\nexer: succeed to send back: %s\n", response); close(getsocket); } close(exersocket); return 0; }
int vsamecom(int stepflag, int comflag) { int i,j,k,id; int ip; int len; int ibc; int ngrp; int iblk; int error; int *ndx; double mass; double norm; double *x; double *y; double *z; double *nm; double *xa; double *ya; double *za; error = 0; if (!ifvsame) { return(error); } if (ifparallel) { STARTTIMER(VSAMECOM) ; curcombuf = VSAMECOM; if (comflag==COM_COLLECT) { initbuf(VSAMECOM,COM_COLLECT); } } if (ifcom) { for (iblk = 0; iblk < nblk; iblk++ ) { for (ibc = 0 ; ibc < domains[iblk].nbnd; ibc++) { ndx = domains[iblk].bnd[ibc].ndx_send; len = domains[iblk].bnd[ibc].len_nsend1+ domains[iblk].bnd[ibc].len_nsend2+domains[iblk].bnd[ibc].len_nsendc; for (i = 0; i < len; i++) { domains[iblk].node[ndx[i]]++; } } } } for (id = 0; id < vsame_max_id; id++) { if ((vsame_order[id].len > 0) && (comflag == COM_COLLECT)) { iblk = vsame_order[id].blk[0]; ibc = vsame_order[id].tag[0]; ngrp = domains[iblk].bc[ibc].ngrp; if (ndims == 2) { nm = ALLOT(double,ngrp); xa = ALLOT(double,ngrp); ya = ALLOT(double,ngrp); } else {
int Write(socket_queue* sock) { /* ACHTUNG IN DIESER FKT DARF KEIN print_msg() AUFGERUFEN WERDEN !!!!! */ int RetCode; static buffer *buf = NULL; char *Ptr; if (sock->descriptor < 0) { #ifdef DEBUG syslog(LOG_DEBUG,"Write: Invalid Descriptor %d",sock->descriptor); #endif return 1; } if (!buf) { buf = (buffer*) calloc(1,sizeof(buffer)); if (!buf) return NO_MEMORY; if ((RetCode = initbuf(buf)) != 0) return RetCode; } if ((Ptr = itos(sock->msgbuf.used+_MSG_LEN+_MSG_MSG,_MSG_LEN)) == NULL) return -1; memcpy(buf->buf,Ptr,_MSG_LEN); buf->used = _MSG_LEN; if ((Ptr = itos(sock->msg,_MSG_MSG)) == NULL) return -1; #ifdef DEBUG syslog(LOG_DEBUG,"Write: Message %d:*%s*",sock->msg,sock->msgbuf.buf); #endif sock->msg = NO_MSG; memcpy(buf->buf+_MSG_LEN,Ptr,_MSG_MSG); buf->used += _MSG_MSG; if ((RetCode = bufcat(buf,&(sock->msgbuf),0,sock->msgbuf.used)) != 0) return RetCode; return write(sock->descriptor,buf->buf,buf->used); }
int nfs_getattr(struct cookie *fh, void (*func) (uintptr_t, int, fattr_t *), uintptr_t token) { struct pbuf *pbuf; /* now the user data struct is setup, do some call stuff! */ pbuf = initbuf(NFS_NUMBER, NFS_VERSION, NFSPROC_GETATTR); /* put in the fhandle */ addtobuf(pbuf, (char*) fh, sizeof(struct cookie)); /* send it! */ return rpc_send(pbuf, nfs_port, nfs_getattr_cb, func, token); }
int main(int argc, char *argv[]) { int c; size_t i; Buffer *buf; errno = 0; setpname(argv[0]); if (argc < 2) die(2, "usage: %s file", getpname()); if ((c = open(argv[1], O_RDONLY)) == -1) die(1, "failed to open file %s:", argv[1]); if ((buf = makebuf(512)) == NULL) die(1, "allocating buffer failed:"); if (initbuf(buf, c, O_RDONLY) == EOF) die(1, "initializing buffer failed:"); i = 0; while ((c = bgetchar(buf)) != EOF) { if (i == 511 || i == 512 || i == 513) { if (bungetchar(buf) == EOF) { die(1, "bungetchar failed at char %lu", i); break; } if ((c = bgetchar(buf)) == EOF) break; } putc(c, stdout); i++; } if (errno != 0) die(1, "bgetchar failed at char %lu:", i); fprintf(stderr, "reached end of input file %s\n", argv[1]); fprintf(stderr, "%lu bytes read\n", i); bclose(buf); exit(0); }
/* remove a file named 'name' in directory 'cwd' */ int nfs_remove(struct cookie *cwd, char *name, void (*func) (uintptr_t, int), uintptr_t token) { struct pbuf *pbuf; /* now the user data struct is setup, do some call stuff! */ pbuf = initbuf(NFS_NUMBER, NFS_VERSION, NFSPROC_REMOVE); /* put in the fhandle */ addtobuf(pbuf, (char*) cwd, sizeof(struct cookie)); /* put in the name */ addstring(pbuf, name); /* send it! */ return rpc_send(pbuf, nfs_port, nfs_remove_cb, func, token); }
int nfs_create(struct cookie *fh, char *name, sattr_t *sat, void (*func) (uintptr_t, int, struct cookie *, fattr_t *), uintptr_t token) { struct pbuf *pbuf; /* now the user data struct is setup, do some call stuff! */ pbuf = initbuf(NFS_NUMBER, NFS_VERSION, NFSPROC_CREATE); /* put in the fhandle */ addtobuf(pbuf, (char*) fh, sizeof(struct cookie)); /* put in the name */ addstring(pbuf, name); addtobuf(pbuf, (char*) sat, sizeof(sattr_t)); return rpc_send(pbuf, nfs_port, nfs_create_cb, func, token); }
void run(void) { int i; fbx_struct stressfb; memset(&stressfb, 0, sizeof(stressfb)); try { int mywidth, myheight, myx=0, myy=0; if(myrank<2) {mywidth=width/2; myx=0;} else {mywidth=width-width/2; myx=width/2;} if(myrank%2==0) {myheight=height/2; myy=0;} else {myheight=height-height/2; myy=height/2;} fbx(fbx_init(&stressfb, wh, mywidth, myheight, useshm)); if(useshm && !stressfb.shm) _throw("MIT-SHM not available"); initbuf(myx, myy, mywidth, stressfb.pitch, myheight, stressfb.format, (unsigned char *)stressfb.bits); for (i=0; i<iter; i++) fbx(fbx_write(&stressfb, 0, 0, myx, myy, mywidth, myheight)); } catch(...) {fbx_term(&stressfb); throw;} }
static void flushln(void) { register int lastmode; register int i; int hadmodes = 0; lastmode = NORMAL; for (i=0; i<maxcol; i++) { obaccs(i); if (obuf[i].c_mode != lastmode) { hadmodes++; setmod(obuf[i].c_mode); lastmode = obuf[i].c_mode; } if (obuf[i].c_char == '\0') { if (upln) { put(cursor_right); } else outc(' '); } else outc(obuf[i].c_char); while (i < maxcol-1 && obuf[i+1].c_mode & FILLER) i++; } if (lastmode != NORMAL) { setmod(0); } if (must_overstrike && hadmodes) overstrike(); putchar('\n'); if (iflag && hadmodes) iattr(); fflush(stdout); if (upln) upln--; initbuf(); }
int nfs_read(struct cookie *fh, int pos, int count, void (*func) (uintptr_t, int, fattr_t *, int, char *), uintptr_t token) { struct pbuf *pbuf; readargs_t args; /* now the user data struct is setup, do some call stuff! */ pbuf = initbuf(NFS_NUMBER, NFS_VERSION, NFSPROC_READ); /* copy in the fhandle */ memcpy(&args.file, (char*) fh, sizeof(struct cookie)); args.offset = pos; args.count = count; args.totalcount = 0; /* unused as per RFC */ /* add them to the buffer */ addtobuf(pbuf, (char*) &args, sizeof(args)); return rpc_send(pbuf, nfs_port, nfs_read_cb, func, token); }
static void flushln(void) { int lastmode; int i; int hadmodes = 0; lastmode = NORMAL; for (i=0; i<maxcol; i++) { if (obuf[i].c_mode != lastmode) { hadmodes++; setnewmode(obuf[i].c_mode); lastmode = obuf[i].c_mode; } if (obuf[i].c_char == '\0') { if (upln) PRINT(CURS_RIGHT); else outc(' ', 1); } else outc(obuf[i].c_char, obuf[i].c_width); if (obuf[i].c_width > 1) i += obuf[i].c_width - 1; } if (lastmode != NORMAL) { setnewmode(0); } if (must_overstrike && hadmodes) overstrike(); putwchar('\n'); if (iflag && hadmodes) iattr(); (void)fflush(stdout); if (upln) upln--; initbuf(); }
// Platform-specific write test void nativewrite(int useshm) { fbx_struct s; int n, i; double rbtime; memset(&s, 0, sizeof(s)); try { fbx(fbx_init(&s, wh, 0, 0, useshm)); if(useshm && !s.shm) _throw("MIT-SHM not available"); fprintf(stderr, "Native Pixel Format: %s", fbx_formatname(s.format)); fprintf(stderr, "\n"); if(s.width!=width || s.height!=height) _throw("The benchmark window lost input focus or was obscured.\nSkipping native write test\n"); clearfb(); initbuf(0, 0, width, s.pitch, height, s.format, (unsigned char *)s.bits); if(useshm) fprintf(stderr, "FBX bottom-up write [SHM]: "); else fprintf(stderr, "FBX bottom-up write: "); n=N; do { n+=n; timer.start(); for (i=0; i<n; i++) { if(checkdb) { memset(s.bits, 255, s.pitch*s.height); fbx(fbx_awrite(&s, 0, 0, 0, 0, 0, 0)); initbuf(0, 0, width, s.pitch, height, s.format, (unsigned char *)s.bits); } fbx(fbx_flip(&s, 0, 0, 0, 0)); fbx(fbx_write(&s, 0, 0, 0, 0, 0, 0)); } rbtime=timer.elapsed(); } while(rbtime<1.); fprintf(stderr, "%f Mpixels/sec\n", (double)n*(double)(width*height)/((double)1000000.*rbtime)); clearfb(); if(useshm) fprintf(stderr, "FBX top-down write [SHM]: "); else fprintf(stderr, "FBX top-down write: "); n=N; do { n+=n; timer.start(); for (i=0; i<n; i++) { if(checkdb) { memset(s.bits, 255, s.pitch*s.height); fbx(fbx_awrite(&s, 0, 0, 0, 0, 0, 0)); initbuf(0, 0, width, s.pitch, height, s.format, (unsigned char *)s.bits); } fbx(fbx_write(&s, 0, 0, 0, 0, 0, 0)); } rbtime=timer.elapsed(); } while(rbtime<1.); fprintf(stderr, "%f Mpixels/sec\n", (double)n*(double)(width*height)/((double)1000000.*rbtime)); } catch(rrerror &e) {fprintf(stderr, "%s\n", e.getMessage());} fbx_term(&s); }
qryproc() { register QTREE *root; register QTREE *q; register int i; register int mode; register int result_num; register int retr_uniq; extern long AAccuread; extern long AAccuwrite; extern long AAccusread; extern int derror(); extern QTREE *trbuild(); extern QTREE *readqry(); # ifdef xDTM if (AAtTf(76, 1)) timtrace(23, 0); # endif # ifdef xDTR1 if (AAtTf(50, 0)) AAccuread = AAccusread = AAccuwrite = 0; # endif /* initialize query buffer */ initbuf(Qbuf, QBUFSIZ, QBUFFULL, derror); /* init various variables in decomp for start of this query */ startdecomp(); /* Read in query, range table and mode */ root = readqry(); mode = Qmode; /* Initialize relation descriptors */ initdesc(mode); /* re-build the tree */ root = trbuild(root); if (!root) derror(STACKFULL); /* locate pointers to QLEND and TREE nodes */ for (q = root->right; q->sym.type != QLEND; q = q->right) continue; Qle = q; for (q = root->left; q->sym.type != TREE; q = q->left) continue; Tr = q; /* map the complete tree */ mapvar(root, 0); /* set logical locks */ lockit(root, Resultvar); /* If there is no result variable then this must be a retrieve to the terminal */ Qry_mode = Resultvar < 0 ? (int) mdRETTERM : mode; /* if the mode is retrieve_unique, then make a result rel */ retr_uniq = mode == (int) mdRET_UNI; if (retr_uniq) { mk_unique(root); mode = (int) mdRETR; } /* get id of result relation */ if (Resultvar < 0) result_num = NORESULT; else result_num = Rangev[Resultvar].relnum; /* evaluate aggregates in query */ aggregate(root); /* decompose and process aggregate free query */ decomp(root, mode, result_num); /* If this is a retrieve unique, then retrieve results */ if (retr_uniq) pr_unique(root, Resultvar); if (mode != (int) mdRETR) i = ACK; else i = NOACK; i = endovqp(i); /* call update processor if batch mode */ if (i == UPDATE) { initp(); call_dbu(mdUPDATE, -1); } /* ** send eop back to parser to indicate completion ** if UPDATE then return block comes from dbu else ** return block comes from decomp */ writeback(i == UPDATE ? -1 : 1); # ifdef xDTM if(AAtTf(76, 1)) timtrace(24, 0); # endif # ifdef xDTR1 AAtTfp(50, 1, "DECOMP read %ld pages,%ld catalog pages,wrote %ld pages\n", AAccuread, AAccusread, AAccuwrite); # endif /* clean decomp */ reinit(); /* return */ }
int main(int argc, char **argv) { int c; char *termtype; #ifdef USE_TERMCAP char termcap[2048]; #endif struct iblok *f; progname = basename(argv[0]); setlocale(LC_CTYPE, ""); mb_cur_max = MB_CUR_MAX; termtype = getenv("TERM"); if (termtype == NULL || (progname[0] == 'c' && !isatty(1))) termtype = "lpr"; while ((c=getopt(argc, argv, "it:T:?")) != EOF) switch(c) { case 't': case 'T': /* for nroff compatibility */ termtype = optarg; break; case 'i': iflag = 1; break; default: fprintf(stderr, "Usage: %s [ -i ] [ -tTerm ] file...\n", progname); exit(1); } #ifndef USE_TERMCAP setupterm(termtype, 1, &c); if (c < 0) fprintf(stderr,"trouble reading termcap"); if (c <= 0) termtype = "dumb"; #else /* USE_TERMCAP */ switch (tgetent(termcap, termtype)) { case 1: break; default: fprintf(stderr,"trouble reading termcap"); /*FALLTHRU*/ case 0: strcpy(termcap, "dumb:os:col#80:cr=^M:sf=^J:am:"); } initcap(); #endif /* USE_TERMCAP */ if ( (over_strike && enter_bold_mode==NULL ) || (transparent_underline && enter_underline_mode==NULL && underline_char==NULL)) must_overstrike = 1; initbuf(); if (optind == argc) filtr(ib_alloc(0, 0)); else for (; optind<argc; optind++) { f = ib_open(argv[optind], 0); if (f == NULL) { perror(argv[optind]); exit(1); } else { filtr(f); ib_close(f); } } exit(0); }
int Read(socket_queue* sock) { int RetCode; int SelRet; fd_set readmask; struct timeval timeout = {0,0}; static buffer *buf = NULL; if (sock->descriptor < 0) { #ifdef DEBUG syslog(LOG_DEBUG,"Write: Invalid Descriptor %d",sock->descriptor); #endif return 1; } if (sock->restbuf.len > BUF_SIZE && sock->restbuf.used == 0) { free(sock->restbuf.buf); sock->restbuf.buf = NULL; initbuf(&(sock->restbuf)); } if (sock->msgbuf.len > BUF_SIZE && sock->msgbuf.used == 0) { free(sock->msgbuf.buf); sock->msgbuf.buf = NULL; initbuf(&(sock->msgbuf)); } else sock->msgbuf.used = 0; if (!buf) { if ((buf = (buffer*) calloc(1,sizeof(buffer))) == NULL) return NO_MEMORY; if ((RetCode = initbuf(buf)) != 0) return RetCode; } else if (buf->len > BUF_SIZE) { free(buf->buf); buf->buf = NULL; initbuf(buf); } FD_ZERO(&readmask); FD_SET(sock->descriptor,&readmask); while ((SelRet = select(sock->descriptor+1,&readmask,NULL,NULL,&timeout)) > 0 && FD_ISSET(sock->descriptor,&readmask)) if ((RetCode = buf->used = read(sock->descriptor,buf->buf,buf->len)) > 0) { if ((RetCode = bufcat(&(sock->restbuf),buf,0,buf->used)) != 0) return RetCode; } else return -1; if (SelRet < 0) return -1; if (sock->restbuf.used) if ((RetCode = get_msg(sock,buf)) != 0) return RetCode; return -1; /* Sollte nur ein Wert > 0 zurueckliefern */ }
int main(int argc, char **argv) { int c, ret; char *termtype; FILE *f; setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); signal(SIGINT, sig_handler); signal(SIGTERM, sig_handler); termtype = getenv("TERM"); if (termtype == NULL || (argv[0][0] == 'c' && !isatty(1))) termtype = "lpr"; while ((c = getopt(argc, argv, "it:T:")) != -1) switch(c) { case 't': case 'T': /* for nroff compatibility */ termtype = optarg; break; case 'i': iflag = 1; break; default: fprintf(stderr, _("Usage: %s [ -i ] [ -tTerm ] file...\n"), program_invocation_short_name); return EXIT_FAILURE; } setupterm(termtype, 1, &ret); switch(ret) { case 1: break; default: warnx(_("trouble reading terminfo")); /* fall through to ... */ case 0: /* No such terminal type - assume dumb */ setupterm("dumb", 1, (int *)0); break; } initinfo(); if ( (tigetflag("os") && ENTER_BOLD==NULL ) || (tigetflag("ul") && ENTER_UNDERLINE==NULL && UNDER_CHAR==NULL)) must_overstrike = 1; initbuf(); if (optind == argc) filter(stdin); else for (; optind<argc; optind++) { f = fopen(argv[optind],"r"); if (!f) err(EXIT_FAILURE, _("%s: open failed"), argv[optind]); filter(f); } if (ferror(stdout) || fclose(stdout)) return EXIT_FAILURE; return EXIT_SUCCESS; }
int main(int argc, char *argv[]) { double t_begin, t_end; int i; int width = WIDTH; int height = HEIGHT; REAL *fout, *fin, *ftmp; REAL *fa = (REAL *)malloc(sizeof(REAL)*WIDTHP*HEIGHT); REAL *fb = (REAL *)malloc(sizeof(REAL)*WIDTHP*HEIGHT); REAL time = 0.0; int count = 1000; REAL stendiag, stennext, stenctr; fin = fa; fout = fb; printf("Initializing..%d Threads, %d x %d, PAD=%d..\n\n", omp_get_num_threads(),WIDTH, HEIGHT, WIDTHP); initbuf(fin, width, height); initbuf(fout, width, height); #if DBG dbgprint(fin, WIDTHP, height); #endif #if SAVEFILES savetofile("stencil9pt_init.dat", fin, WIDTHP, HEIGHT); #endif // stencil params: slowly blurring... stendiag = 0.00125; stennext = 0.00125; stenctr = 0.99; printf("Running stencil kernel %d times\n", count); t_begin = dtime(); stencil9pt_base(fin, fout, width, height, stenctr, stennext, stendiag,count); t_end = dtime(); #if DBG dbgprint(fout, WIDTHP, height); #endif #if SAVEFILES savetofile("stencil9pt_result.dat",fb, WIDTHP, HEIGHT); #endif double elapsed_time = t_end - t_begin; REAL mflops = (width*height)*17.0*count/elapsed_time * 1.0e-06; printf("Elapsed time : %.3f (s)\n", elapsed_time); printf("FLOPS : %.3f (MFlops)\n", mflops); free(fa); free(fb); return 0; }