SCM Repository
View of /branches/pure-cfg/src/lib/main.c
Parent Directory
|
Revision Log
Revision 619 -
(download)
(as text)
(annotate)
Mon Mar 14 13:22:43 2011 UTC (9 years, 10 months ago) by jhr
File size: 2316 byte(s)
Mon Mar 14 13:22:43 2011 UTC (9 years, 10 months ago) by jhr
File size: 2316 byte(s)
Don't map negative values to 0
/*! \file main.c * * \author John Reppy */ /* * COPYRIGHT (c) 2011 The Diderot Project (http://diderot-language.cs.uchicago.edu) * All rights reserved. */ #define NR 200 #define NC 200 #include <string.h> #include <stdio.h> #include <Diderot/diderot.h> extern float getOutf (void *self); int main (int argc, const char **argv) { // printf("initializing globals ...\n"); Diderot_InitGlobals (); // FIXME: we need to figure out how initialization should be handled. printf("initializing strands ...\n"); void *strands1[NR*NC], *strands2[NR*NC]; bool active[NR*NC]; for (int r = 0; r < NR; r++) { for (int c = 0; c < NC; c++) { int i = NC*r + c; strands1[i] = Diderot_AllocStrand (&(Diderot_Strands[0])); strands2[i] = Diderot_AllocStrand (&(Diderot_Strands[0])); active[i] = true; Diderot_Strands[0].init(strands1[i], r, c); // copy so that static fields are initialized memcpy (strands2[i], strands1[i], Diderot_Strands[0].stateSzb); } } // iterate until all strands are stable printf("run ...\n"); int nSteps = 0, nUpdates = 0; int nActive = NR*NC; void **in = &(strands1[0]); void **out = &(strands2[0]); while (nActive > 0) { nSteps++; // update strands for (int i = 0; i < NR*NC; i++) { if (active[i]) { nUpdates++; StrandStatus_t sts = Diderot_Strands[0].update(in[i], out[i]); if (sts == DIDEROT_STABILIZE) { // copy out to in so that both copies are the stable state memcpy (in[i], out[i], Diderot_Strands[0].stateSzb); active[i] = false; nActive--; } } } // swap in and out void **tmp = in; in = out; out = tmp; } printf("done: %d updates, %d steps\n", nUpdates, nSteps); // here we have the final state of all of the strands in the "in" buffer FILE *outS = fopen("mip.txt", "w"); if (outS == NULL) { fprintf (stderr, "Cannot open output file\n"); exit (8); } for (int r = 0; r <= 199; r++) { for (int c = 0; c <= 199; c++) { int i = NC*r + c; float outV = getOutf (in[i]); fprintf (outS, "%f\n", outV); } } fclose (outS); return 0; } // this should be the part of the scheduler void *Diderot_AllocStrand (Strand_t *strand) { return malloc(strand->stateSzb); }
root@smlnj-gforge.cs.uchicago.edu | ViewVC Help |
Powered by ViewVC 1.0.0 |