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

SCM Repository

[diderot] View of /branches/vis15/src/compiler/target-cpu/fragments/world-methods.in
ViewVC logotype

View of /branches/vis15/src/compiler/target-cpu/fragments/world-methods.in

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4489 - (download) (annotate)
Sat Sep 3 00:32:03 2016 UTC (3 years, 1 month ago) by jhr
File size: 2992 byte(s)
working on merge: changing initially to start
// Allocate the program's world
//
world::world ()
    : diderot::world_base (ProgramName, @IS_GRID@, @NUM_AXES@)
{
#ifndef DIDEROT_NO_GLOBALS
    this->_globals = new globals;
#endif

#ifdef DIDEROT_TARGET_PARALLEL
    this->_sched = new diderot::scheduler();
    this->_sched->get_cpu_info (this);
    this->_sched->_numWorkers = this->_sched->_numHWCores;
#endif

#ifdef DIDEROT_HAS_STRAND_COMMUNICATION
    this->_tree = nullptr;
#endif
} // world constructor

// shutdown and deallocate the world
//
world::~world ()
{
#ifndef DIDEROT_NO_GLOBALS
    delete this->_globals;
#endif

#ifdef DIDEROT_HAS_STRAND_COMMUNICATION
    delete this->_tree;
#endif

} // world destructor

// Initialize the program's world
//
bool world::init ()
{
    if (this->_stage != diderot::POST_NEW) {
        biffMsgAdd (this->_errors, "multiple calls to world::init");
        return true;
    }

#ifdef DIDEROT_TARGET_PARALLEL
  // initialize synchronization structures
    if ((pthread_mutex_init (&(this->_sched->_lock), 0) != 0)
    || (pthread_cond_init (&(this->_sched->_barrier), 0) != 0)
    || (pthread_cond_init (&(this->_sched->_runWait), 0) != 0)) {
        biffMsgAdd (this->_errors, "unable to initialize scheduler structures");
        return true;
    }
#endif

#if !defined(DIDEROT_STANDALONE_EXEC) && !defined(DIDEROT_NO_INPUTS)
  // initialize the defined flags for the input globals
    init_defined_inputs (this);
#endif

    this->_stage = diderot::POST_INIT;

    return false;

}

// allocate the initial strands and initialize the rest of the world structure.
//
bool world::alloc (int32_t base[@NUM_AXES@], uint32_t size[@NUM_AXES@])
{
    size_t numStrands = 1;
    for (uint32_t i = 0;  i < @NUM_AXES@;  i++) {
        numStrands *= size[i];
        this->_base[i] = base[i];
        this->_size[i] = size[i];
    }

    if (this->_verbose) {
        std::cerr << "world::alloc: " << size[0];
        for (uint32_t i = 1;  i < @NUM_AXES@;  i++) {
            std::cerr << " x " << size[i];
        }
        std::cerr << std::endl;
    }

#ifdef DIDEROT_HAS_STRAND_COMMUNICATION
    this->_tree = new diderot::kdtree<@SPATIAL_DIM@, @REALTY@, strand_array> (numStrands);
#endif

  // allocate the strand array
    if (this->_strands.alloc (numStrands)) {
        biffMsgAdd (this->_errors, "unable to allocate strand-state array\n");
        return true;
    }

  // initialize strand state pointers etc.
    this->_strands.create_strands (numStrands);

    return false;

} // world::alloc

// swap input and output states
//
inline void world::swap_state ()
{
    this->_strands.swap ();
}

#ifdef DIDEROT_HAS_STABILIZE_ALL
void world::stabilize_all ()
{
#ifndef DIDEROT_NO_GLOBALS
    globals *glob = this->_globals;
#endif

    if (this->_strands.num_active() > 0) {
        for (auto ix = this->_strands.begin_active();
	    ix != this->_strands.end_active();
	    ix = this->_strands.next_active(ix))
	{
	    this->_strands.stabilize (@STABILIZE_ARGS@ix);
	}
    }
}
#endif

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0