float jacobi(int nn) { int i,j,k,n; float gosa,wgosa,s0,ss; double s, cpu, com; for(n=0 ; n<nn ; ++n){ gosa = 0.0; wgosa= 0.0; // if (id == 0)fprintf(stderr, "%d: nn:%d, imax:%d, jmax:%d, kmax:%d\n", n, nn, imax, jmax, kmax); // if (id == 128)fprintf(stderr, "%d: nn:%d, imax:%d, jmax:%d, kmax:%d\n", n, nn, imax, jmax, kmax); s = MPI_Wtime(); for(i=1 ; i<imax-1 ; ++i) for(j=1 ; j<jmax-1 ; ++j) for(k=1 ; k<kmax-1 ; ++k){ s0 = a[0][i][j][k] * p[i+1][j ][k ] + a[1][i][j][k] * p[i ][j+1][k ] + a[2][i][j][k] * p[i ][j ][k+1] + b[0][i][j][k] * ( p[i+1][j+1][k ] - p[i+1][j-1][k ] - p[i-1][j+1][k ] + p[i-1][j-1][k ] ) + b[1][i][j][k] * ( p[i ][j+1][k+1] - p[i ][j-1][k+1] - p[i ][j+1][k-1] + p[i ][j-1][k-1] ) + b[2][i][j][k] * ( p[i+1][j ][k+1] - p[i-1][j ][k+1] - p[i+1][j ][k-1] + p[i-1][j ][k-1] ) + c[0][i][j][k] * p[i-1][j ][k ] + c[1][i][j][k] * p[i ][j-1][k ] + c[2][i][j][k] * p[i ][j ][k-1] + wrk1[i][j][k]; ss = ( s0 * a[3][i][j][k] - p[i][j][k] ) * bnd[i][j][k]; wgosa += ss*ss; wrk2[i][j][k] = p[i][j][k] + omega * ss; } for(i=1 ; i<imax-1 ; ++i) for(j=1 ; j<jmax-1 ; ++j) for(k=1 ; k<kmax-1 ; ++k) p[i][j][k] = wrk2[i][j][k]; cpu = MPI_Wtime() - s; s = MPI_Wtime(); sendp(ndx,ndy,ndz); com = MPI_Wtime() - s; s = MPI_Wtime(); if (id == 0) { fprintf(stderr, "%d: time: %f cpu: %f com: %f nn:%d, imax:%d, jmax:%d, kmax:%d\n", cpu + com, cpu, com, n, nn, imax, jmax, kmax); } // if (n % 10 == 0 ) fprintf(stdout, "LLLL %d %f\n", n, s); #ifdef SCR_ENABLE int flag; char SCR_testFileName[SCR_MAX_FILENAME]; char testFileName[SCR_MAX_FILENAME]; double gs, ge, start, end, dump, encoding; gs = start = MPI_Wtime(); SCR_Need_checkpoint(&flag); if(flag){ SCR_Start_checkpoint(); sprintf(testFileName, "testfile.%d", id); strcpy(SCR_testFileName, testFileName); SCR_Route_file(testFileName, SCR_testFileName); if(id == 0) printf(" ***** SCR_ROUTE_FILE %s\n", SCR_testFileName); file_dump(SCR_testFileName, p, MIMAX * MJMAX * MKMAX * sizeof(float)); end = MPI_Wtime(); dump = end - start; start = MPI_Wtime(); SCR_Complete_checkpoint(1); ge = end = MPI_Wtime(); encoding = end - start; //printf(" ***** SCR_START_CHECKPOINT\n"); if (id == 0) fprintf(stderr, "time: %f (write: %f , enco: %f)\n", ge - gs, dump, encoding); } // SCR #endif MPI_Allreduce(&wgosa, &gosa, 1, MPI_FLOAT, MPI_SUM, MPI_COMM_WORLD); } /* end n loop */ return(gosa); }
static Xfid* fsysread(Xfid *x, Fid *f) { Fcall t; uchar *b; int i, id, n, o, e, j, k, *ids, nids; Dirtab *d, dt; Column *c; uint clock, len; char buf[16]; if(f->qid.type & QTDIR){ if(FILE(f->qid) == Qacme){ /* empty dir */ t.data = nil; t.count = 0; respond(x, &t, nil); return x; } o = x->offset; e = x->offset+x->count; clock = getclock(); b = emalloc(messagesize); id = WIN(f->qid); n = 0; if(id > 0) d = dirtabw; else d = dirtab; d++; /* first entry is '.' */ for(i=0; d->name!=nil && i<e; i+=len){ len = dostat(WIN(x->f->qid), d, b+n, x->count-n, clock); if(len <= BIT16SZ) break; if(i >= o) n += len; d++; } if(id == 0){ qlock(&row); nids = 0; ids = nil; for(j=0; j<row.ncol; j++){ c = row.col[j]; for(k=0; k<c->nw; k++){ ids = erealloc(ids, (nids+1)*sizeof(int)); ids[nids++] = c->w[k]->id; } } qunlock(&row); qsort(ids, nids, sizeof ids[0], idcmp); j = 0; dt.name = buf; for(; j<nids && i<e; i+=len){ k = ids[j]; sprint(dt.name, "%d", k); dt.qid = QID(k, Qdir); dt.type = QTDIR; dt.perm = DMDIR|0700; len = dostat(k, &dt, b+n, x->count-n, clock); if(len == 0) break; if(i >= o) n += len; j++; } free(ids); } t.data = (char*)b; t.count = n; respond(x, &t, nil); free(b); return x; } sendp(x->c, xfidread); return nil; }
void reader(void *v) { int cfd, tfd, forking = 0, exiting, pid; uintptr_t newpid; char *ctl, *truss; Str *s; static char start[] = "start"; static char waitstop[] = "waitstop"; pid = (int)(uintptr)v; if (debug) fprint(2, "DEBUG: -------------> reader starts with pid %d\n", pid); ctl = smprint("/proc/%d/ctl", pid); if ((cfd = open(ctl, OWRITE)) < 0) die(smprint("%s: %r", ctl)); truss = smprint("/proc/%d/syscall", pid); if ((tfd = open(truss, OREAD)) < 0) die(smprint("%s: %r", truss)); if (debug) fprint(2, "DEBUG: Send %s to pid %d ...", waitstop, pid); /* child was stopped by hang msg earlier */ cwrite(cfd, ctl, waitstop, sizeof waitstop - 1); if (debug) fprint(2, "DEBUG: back for %d\n", pid); if (debug) fprint(2, "DEBUG: Send %s to pid %d\n", "startsyscall", pid); cwrite(cfd, ctl, "startsyscall", 12); if (debug) fprint(2, "DEBUG: back for %d\n", pid); s = newstr(); exiting = 0; while((s->len = pread(tfd, s->buf, Bufsize - 1, 0)) >= 0){ if (s->buf[0] == 'F') { char *val = strstr(s->buf, "= "); if (val) { newpid = strtol(&val[2], 0, 0); sendp(forkc, (void*)newpid); procrfork(reader, (void*)newpid, Stacksize, 0); } } if (strstr(s->buf, " Exits") != nil) exiting = 1; sendp(out, s); /* print line from /proc/$child/syscall */ if (exiting) { s = newstr(); strcpy(s->buf, "\n"); sendp(out, s); break; } /* flush syscall trace buffer */ if (debug) fprint(2, "DEBUG: Send %s to pid %d\n", "startsyscall", pid); cwrite(cfd, ctl, "startsyscall", 12); if (debug) fprint(2, "DEBUG: back for %d\n", pid); s = newstr(); } sendp(quit, nil); threadexitsall(nil); }
static Xfid* fsyswalk(Xfid *x, Fid *f) { Fcall t; int c, i, j, id; Qid q; uchar type; ulong path; Fid *nf; Dirtab *d, *dir; Window *w; char *err; nf = nil; w = nil; if(f->open) return respond(x, &t, "walk of open file"); if(x->fid != x->newfid){ nf = newfid(x->newfid); if(nf->busy) return respond(x, &t, "newfid already in use"); nf->busy = TRUE; nf->open = FALSE; nf->mntdir = f->mntdir; if(f->mntdir) f->mntdir->ref++; nf->dir = f->dir; nf->qid = f->qid; nf->w = f->w; nf->nrpart = 0; /* not open, so must be zero */ if(nf->w) incref(nf->w); f = nf; /* walk f */ } t.nwqid = 0; err = nil; dir = nil; id = WIN(f->qid); q = f->qid; if(x->nwname > 0){ for(i=0; i<x->nwname; i++){ if((q.type & QTDIR) == 0){ err = Enotdir; break; } if(strcmp(x->wname[i], "..") == 0){ type = QTDIR; path = Qdir; id = 0; if(w){ winclose(w); w = nil; } Accept: if(i == MAXWELEM){ err = "name too long"; break; } q.type = type; q.vers = 0; q.path = QID(id, path); t.wqid[t.nwqid++] = q; continue; } /* is it a numeric name? */ for(j=0; (c=x->wname[i][j]); j++) if(c<'0' || '9'<c) goto Regular; /* yes: it's a directory */ if(w) /* name has form 27/23; get out before losing w */ break; id = atoi(x->wname[i]); qlock(&row); w = lookid(id, FALSE); if(w == nil){ qunlock(&row); break; } incref(w); /* we'll drop reference at end if there's an error */ path = Qdir; type = QTDIR; qunlock(&row); dir = dirtabw; goto Accept; Regular: // if(FILE(f->qid) == Qacme) /* empty directory */ // break; if(strcmp(x->wname[i], "new") == 0){ if(w) error("w set in walk to new"); sendp(cnewwindow, nil); /* signal newwindowthread */ w = recvp(cnewwindow); /* receive new window */ incref(w); type = QTDIR; path = QID(w->id, Qdir); id = w->id; dir = dirtabw; goto Accept; } if(id == 0) d = dirtab; else d = dirtabw; d++; /* skip '.' */ for(; d->name; d++) if(strcmp(x->wname[i], d->name) == 0){ path = d->qid; type = d->type; dir = d; goto Accept; } break; /* file not found */ } if(i==0 && err == nil) err = Eexist; } if(err!=nil || t.nwqid<x->nwname){ if(nf){ nf->busy = FALSE; fsysdelid(nf->mntdir); } }else if(t.nwqid == x->nwname){ if(w){ f->w = w; w = nil; /* don't drop the reference */ } if(dir) f->dir = dir; f->qid = q; } if(w != nil) winclose(w); return respond(x, &t, err); }
void mainctl(void *v) { Window *w; Event *e; int delta, pendingS, pendingK; ulong hostpt, endpt; char tmp[32]; w = v; proccreate(wineventproc, w, STACK); hostpt = 0; endpt = 0; winsetaddr(w, "0", 0); pendingS = 0; pendingK = 0; for(;;){ if(debug) fprint(2, "input range %lud-%lud\n", hostpt, endpt); e = recvp(w->cevent); if(debug) fprint(2, "msg: %C %C %d %d %d %d %q\n", e->c1 ? e->c1 : ' ', e->c2 ? e->c2 : ' ', e->q0, e->q1, e->flag, e->nb, e->b); switch(e->c1){ default: Unknown: fprint(2, "unknown message %c%c\n", e->c1, e->c2); break; case 'C': /* input needed for /dev/cons */ if(pendingS) pendingK = 1; else hostpt += sendinput(w, hostpt, &endpt); break; case 'S': /* output to stdout */ sprint(tmp, "#%lud", hostpt); winsetaddr(w, tmp, 0); write(w->data, e->b, e->nb); pendingS += e->nr; break; case 'E': /* write to tag or body; body happens due to sendit */ delta = e->q1-e->q0; if(e->c2=='I'){ endpt += delta; if(e->q0 < hostpt) hostpt += delta; else hostpt += sendinput(w, hostpt, &endpt); break; } if(!islower(e->c2)) fprint(2, "win msg: %C %C %d %d %d %d %q\n", e->c1, e->c2, e->q0, e->q1, e->flag, e->nb, e->b); break; case 'F': /* generated by our actions (specifically case 'S' above) */ delta = e->q1-e->q0; if(e->c2=='D'){ /* we know about the delete by _sendinput */ break; } if(e->c2=='I'){ pendingS -= e->q1 - e->q0; if(pendingS < 0) fprint(2, "win: pendingS = %d\n", pendingS); if(e->q0 != hostpt) fprint(2, "win: insert at %d expected %lud\n", e->q0, hostpt); endpt += delta; hostpt += delta; sendp(writechan, nil); if(pendingS == 0 && pendingK){ pendingK = 0; hostpt += sendinput(w, hostpt, &endpt); } break; } if(!islower(e->c2)) fprint(2, "win msg: %C %C %d %d %d %d %q\n", e->c1, e->c2, e->q0, e->q1, e->flag, e->nb, e->b); break; case 'K': delta = e->q1-e->q0; switch(e->c2){ case 'D': endpt -= delta; if(e->q1 < hostpt) hostpt -= delta; else if(e->q0 < hostpt) hostpt = e->q0; break; case 'I': delta = e->q1 - e->q0; endpt += delta; if(endpt < e->q1) /* just in case */ endpt = e->q1; if(e->q0 < hostpt) hostpt += delta; if(e->nr>0 && e->r[e->nr-1]==0x7F){ write(notepg, "interrupt", 9); hostpt = endpt; break; } if(e->q0 >= hostpt && hasboundary(e->r, e->nr)){ /* * If we are between the S message (which * we processed by inserting text in the * window) and the F message notifying us * that the text has been inserted, then our * impression of the hostpt and acme's * may be different. This could be seen if you * hit enter a bunch of times in a con * session. To work around the unreliability, * only send input if we don't have an S pending. * The same race occurs between when a character * is typed and when we get notice of it, but * since characters tend to be typed at the end * of the buffer, we don't run into it. There's * no workaround possible for this typing race, * since we can't tell when the user has typed * something but we just haven't been notified. */ if(pendingS) pendingK = 1; else hostpt += sendinput(w, hostpt, &endpt); } break; } break; case 'M': /* mouse */ delta = e->q1-e->q0; switch(e->c2){ case 'x': case 'X': execevent(w, e, command); break; case 'l': /* reflect all searches back to acme */ case 'L': if(e->flag & 2) recvp(w->cevent); winwriteevent(w, e); break; case 'I': endpt += delta; if(e->q0 < hostpt) hostpt += delta; else hostpt += sendinput(w, hostpt, &endpt); break; case 'D': endpt -= delta; if(e->q1 < hostpt) hostpt -= delta; else if(e->q0 < hostpt) hostpt = e->q0; break; case 'd': /* modify away; we don't care */ case 'i': break; default: goto Unknown; } } } }