Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] View of /branches/pure-cfg/src/lib/main.c
ViewVC logotype

View of /branches/pure-cfg/src/lib/main.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 589 - (download) (as text) (annotate)
Wed Mar 9 21:46:16 2011 UTC (9 years, 6 months ago) by jhr
File size: 2379 byte(s)
  Minor code cleanup/fixes
/*! \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]);
	    if (outV < 0)
		fprintf (outS, "%.4f\n", 0.0f); 
	    else
		fprintf (outS, "%.4f\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