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 571 - (download) (as text) (annotate)
Mon Feb 28 21:36:12 2011 UTC (9 years, 8 months ago) by jhr
File size: 1580 byte(s)
  Working on vr-MIP example
/*! \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 <Diderot/diderot.h>

int main (int argc, const char **argv)
{
  // 
    Diderot_InitGlobals ();

  // FIXME: we need to figure out how initialization should be handled.
    void *strands1[NR*NC], *strands2[NR*NC];
    bool active[NR*NC];
    for (int r = 0;  r <= 199;  r++) {
	for (int c = 0;  c <= 199;  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);
	}
    }

  // iterate until all strands are stable
    int nActive = NR*NC;
    void **in = &(strands1[0]);
    void **out = &(strands2[0]);
    while (nActive > 0) {
      // update strands
	for (int i = 0;  i < NR*NC;  i++) {
	    if (active[i]) {
	        StrandStatus_t sts = Diderot_Strands[0].update(in[i], out[i]);
		if (sts == DIDEROT_STABILIZE) {
		  // copy out to in so that final state is correct
		    memcpy (in[i], out[i], Diderot_Strands[0].stateSzb);
		    active[i] = false;
		    nActive--;
		}
	    }
	}
      // swap in and out
	void **tmp = in;
	in = out;
	out = tmp;
    }

  // here we have the final state of all of the strands in the "in" buffer

    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