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 3924 - (download) (annotate)
Fri Jun 3 17:30:27 2016 UTC (3 years, 4 months ago) by jhr
File size: 3475 byte(s)
  Working on merge: code generation
// Allocate the program's world
//
world::world ()
    : diderot::world_base (ProgramName, @IS_ARRAY@, @NUM_AXES@)
{
#ifndef DIDEROT_NO_GLOBALS
    this->_globals = new globals;
#endif

#ifdef DIDEROT_TARGET_PARALLEL
    this->_sched = new diderot::sched_info;
    diderot::get_num_cpus (this->_sched->_cpuInfo));
    this->_sched->_numWorkers = this->_sched->_cpuInfo.numHWCores;
#endif

} // world constructor

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

  // free state arrays
#ifdef DIDEROT_DUAL_STATE
    delete[] this->_inState;
    delete[] this->_outState;
#else
    delete[] this->_state;
#endif
    delete[] this->_status;

} // 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;
    }
    this->_sched->_nactive = 0;
#else /* DIDEROT_TARGET_C */
    this->_nactive = 0;
#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 (uint32_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;
    }

  // allocate the strand state pointers
    this->_nstrands = numStrands;
#ifdef DIDEROT_TARGET_PARALLEL
    this->_sched->_nactive = numStrands;
#else /* DIDEROT_TARGET_C */
    this->_nactive = numStrands;
#endif
    this->_status = new (std::nothrow) uint8_t[numStrands];
#ifdef DIDEROT_DUAL_STATE
    this->_inState = new (std::nothrow) @STRANDTY@[numStrands];
    this->_outState = new (std::nothrow) @STRANDTY@[numStrands];
    if ((this->_inState == 0) || (this->_outState == 0) || (this->_status == 0)) {
        biffMsgAdd (this->_errors, "unable to allocate strand states\n");
        return true;
    }
#else
    this->_state = new (std::nothrow) @STRANDTY@[numStrands];
    if ((this->_state == 0) || (this->_status == 0)) {
        biffMsgAdd (this->_errors, "unable to allocate strand states\n");
        return true;
    }
#endif

  // initialize strand state pointers etc.
    for (size_t i = 0;  i < numStrands;  i++) {
        this->_status[i] = diderot::kActive;
    }

    return false;

} // world::alloc

// swap input and output states
//
inline void world::swap_state ()
{
#ifdef DIDEROT_DUAL_STATE
  // swap in and out
    strand_state **tmp = this->_inState;
    this->_inState = this->_outState;
    this->_outState = tmp;
#endif
}

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