Example #1
0
void HostMatrix::updateSize(int numberOfRows, int numberOfColumns) {
#ifdef DEBUG
  if(numberOfRows > numberOfRealRows){
    throw DimensionMismatch("Number of rows for HostMatrix can't be larger than the real number of rows.");
  }
  if(numberOfColumns > numberOfRealColumns){
    throw DimensionMismatch("Number of columns for HostMatrix can't be larger than the real number of columns.");
  }
#endif

  this->numberOfRows = numberOfRows;
  this->numberOfColumns = numberOfColumns;
}
Example #2
0
  void cg_connect(ConnectionGeneratorDatum& cg, RangeSet& sources, std::vector<long>& source_gids, RangeSet& targets, std::vector<long>& target_gids, DictionaryDatum params_map, index syn)
  {
    cg_set_masks(cg, sources, targets);
    cg->start();

    int source, target, num_parameters = cg->arity();
    if (num_parameters == 0)
    {
      while (cg->next(source, target, NULL))
        ConnectionGeneratorModule::get_network().connect(source_gids.at(source), target_gids.at(target), syn);
    }
    else if (num_parameters == 2)
    {
      if (!params_map->known(names::weight) || !params_map->known(names::delay))
        throw BadProperty("The parameter map has to contain the indices of weight and delay.");  

      long w_idx = (*params_map)[names::weight];
      long d_idx = (*params_map)[names::delay];
      std::vector<double> params(2);

      while (cg->next(source, target, &params[0]))
        ConnectionGeneratorModule::get_network().connect(source_gids.at(source), target_gids.at(target), params[w_idx], params[d_idx], syn);
    }
    else
    {
      ConnectionGeneratorModule::get_network().message(SLIInterpreter::M_ERROR, "Connect", "Either two or no parameters in the Connection Set expected.");
      throw DimensionMismatch();  
    }
  }
Example #3
0
HostMatrix::HostMatrix(int numberOfRealRows, int numberOfRealColumns, int numberOfRows, int numberOfColumns,
    PRECISION* hostMatrix) :
    numberOfRealRows(numberOfRealRows), numberOfRealColumns(numberOfRealColumns), numberOfRows(numberOfRows), numberOfColumns(
        numberOfColumns), hostMatrix(hostMatrix) {
  if(numberOfRows <= 0 || numberOfColumns <= 0 || numberOfRealRows <= 0 || numberOfRealColumns <= 0){
    throw DimensionMismatch("Number of rows and columns for HostMatrix must be > 0");
  }
}
Example #4
0
void
cg_connect( ConnectionGeneratorDatum& cg,
  RangeSet& sources,
  std::vector< long >& source_gids,
  RangeSet& targets,
  std::vector< long >& target_gids,
  DictionaryDatum params_map,
  index syn )
{
  cg_set_masks( cg, sources, targets );
  cg->start();

  int source, target, num_parameters = cg->arity();
  if ( num_parameters == 0 )
  {
    // connect source to target
    while ( cg->next( source, target, NULL ) )
    {
      if ( kernel().node_manager.is_local_gid( target_gids.at( target ) ) )
      {
        Node* const target_node = kernel().node_manager.get_node( target_gids.at( target ) );
        const thread target_thread = target_node->get_thread();
        kernel().connection_builder_manager.connect(
          source_gids.at( source ), target_node, target_thread, syn );
      }
    }
  }
  else if ( num_parameters == 2 )
  {
    if ( !params_map->known( names::weight ) || !params_map->known( names::delay ) )
      throw BadProperty( "The parameter map has to contain the indices of weight and delay." );

    long w_idx = ( *params_map )[ names::weight ];
    long d_idx = ( *params_map )[ names::delay ];
    std::vector< double > params( 2 );

    // connect source to target with weight and delay
    while ( cg->next( source, target, &params[ 0 ] ) )
    {
      if ( kernel().node_manager.is_local_gid( target_gids.at( target ) ) )
      {
        Node* const target_node = kernel().node_manager.get_node( target_gids.at( target ) );
        const thread target_thread = target_node->get_thread();
        kernel().connection_builder_manager.connect( source_gids.at( source ),
          target_node,
          target_thread,
          syn,
          params[ d_idx ],
          params[ w_idx ] );
      }
    }
  }
  else
  {
    LOG( M_ERROR, "Connect", "Either two or no parameters in the Connection Set expected." );
    throw DimensionMismatch();
  }
}
Example #5
0
/**
 * Solves the disconnection of two nodes on a OneToOne basis without
 * structural plasticity. This means this method can be manually called
 * by the user to delete existing synapses.
 */
void
nest::OneToOneBuilder::disconnect_()
{
  // make sure that target and source population have the same size
  if ( sources_->size() != targets_->size() )
  {
    LOG( M_ERROR,
      "Disconnect",
      "Source and Target population must be of the same size." );
    throw DimensionMismatch();
  }

#pragma omp parallel
  {
    // get thread id
    const int tid = kernel().vp_manager.get_thread_id();

    try
    {
      for ( GIDCollection::const_iterator tgid = targets_->begin(),
                                          sgid = sources_->begin();
            tgid != targets_->end();
            ++tgid, ++sgid )
      {

        assert( sgid != sources_->end() );

        // check whether the target is on this mpi machine
        if ( not kernel().node_manager.is_local_gid( *tgid ) )
        {
          skip_conn_parameter_( tid );
          continue;
        }

        Node* const target = kernel().node_manager.get_node( *tgid );
        const thread target_thread = target->get_thread();

        // check whether the target is on our thread
        if ( tid != target_thread )
        {
          skip_conn_parameter_( tid );
          continue;
        }
        single_disconnect_( *sgid, *target, target_thread );
      }
    }
    catch ( std::exception& err )
    {
      // We must create a new exception here, err's lifetime ends at
      // the end of the catch block.
      exceptions_raised_.at( tid ) =
        lockPTR< WrappedThreadException >( new WrappedThreadException( err ) );
    }
  }
}
Example #6
0
/**
 * In charge of dynamically creating the new synapses
 * @param sources nodes from which synapses can be created
 * @param targets target nodes for the newly created synapses
 */
void
nest::SPBuilder::connect_( GIDCollection sources, GIDCollection targets )
{
  // Code copied and adapted from OneToOneBuilder::connect_()
  // make sure that target and source population have the same size
  if ( sources.size() != targets.size() )
  {
    LOG( M_ERROR,
      "Connect",
      "Source and Target population must be of the same size." );
    throw DimensionMismatch();
  }

#pragma omp parallel
  {
    // get thread id
    const int tid = kernel().vp_manager.get_thread_id();

    try
    {
      // allocate pointer to thread specific random generator
      librandom::RngPtr rng = kernel().rng_manager.get_rng( tid );

      for ( GIDCollection::const_iterator tgid = targets.begin(),
                                          sgid = sources.begin();
            tgid != targets.end();
            ++tgid, ++sgid )
      {
        assert( sgid != sources.end() );

        if ( *sgid == *tgid and not autapses_ )
          continue;

        if ( !change_connected_synaptic_elements( *sgid, *tgid, tid, 1 ) )
        {
          skip_conn_parameter_( tid );
          continue;
        }
        Node* const target = kernel().node_manager.get_node( *tgid );
        const thread target_thread = target->get_thread();

        single_connect_( *sgid, *target, target_thread, rng );
      }
    }
    catch ( std::exception& err )
    {
      // We must create a new exception here, err's lifetime ends at
      // the end of the catch block.
      exceptions_raised_.at( tid ) =
        lockPTR< WrappedThreadException >( new WrappedThreadException( err ) );
    }
  }
}
Example #7
0
void nest::ac_poisson_generator::init_buffers_()
{ 
  device_.init_buffers();
  B_.rates_.clear_data();

  B_.N_osc_ = P_.om_.size();
  if ( ! ( P_.ac_.size() == B_.N_osc_ && P_.phi_.size() == B_.N_osc_ ) )
  {
    network()->message(SLIInterpreter::M_ERROR,
		       "ac_poisson_generator::calibrate",
		       "Frequency, AC amplitude, and phase arrays "
		       "must have equal size!");
    throw DimensionMismatch();
  }

  /* state vector:
     - dc component is constant and not included
     - rate is accumulated directly in update
     - vector contains two elements for each oscillator
  */
  B_.state_oscillators_.resize(2*B_.N_osc_, 0);

  // remaining elements, see Rotter & Diesmann, 3.1.3
  // phi = pi/2 is stable, since tan(phi)^2 appears in denominator only
  // assumes IEEE arithmetic with 1/Inf = 0
  // sign is handled below when assigning to S_
  const std::valarray<double_t> q = 
    P_.ac_ / std::sqrt(1.0 + std::pow(std::tan(P_.phi_), 2.0));

  // valarray slices do not appear to be reliable under Tru64 CXX,
  // so one better uses for loops.
  for ( size_t n = 0 ; n < B_.N_osc_ ; ++n )
    {
    B_.state_oscillators_[2 * n    ] = 
      std::cos(P_.phi_[n]) >= 0 ? q[n] : -q[n];
    B_.state_oscillators_[2 * n + 1] = std::sin(P_.phi_[n]) >= 0 
      ?  std::sqrt(std::pow(P_.ac_[n],2.0)-std::pow(q[n],2.0))
      : -std::sqrt(std::pow(P_.ac_[n],2.0)-std::pow(q[n],2.0));
  }

}
Example #8
0
DataLocation<Matrix, Vector>::DataLocation(Vector* snpVector, Vector* environmentVector, Vector* interactionVector,
    Vector* phenotypeVector, Matrix* covariatesMatrix) :
    snpVector(snpVector), environmentVector(environmentVector), interactionVector(interactionVector), phenotypeVector(
        phenotypeVector), covariatesMatrix(covariatesMatrix){
#ifdef DEBUG
  int sLength = snpVector.getRealNumberOfRows();
  int eLength = environmentVector.getRealNumberOfRows();
  int iLength = interactionVector.getRealNumberOfRows();
  int pLength = phenotypeVector.getRealNumberOfRows();
  int cLength = covariatesMatrix.getRealNumberOfRows();

  if(sLength != eLength || sLength != iLength || sLength != pLength || sLength != cLength){
    std::ostringstream os;
    os << "DataLocation number of rows of containers does not match" << std::endl;
    const std::string& tmp = os.str();
    throw DimensionMismatch(tmp.c_str());
  }


#endif
}
void
nest::RNGManager::set_status( const DictionaryDatum& d )
{
  // have those two for later asking, whether threads have changed:
  long n_threads;
  bool n_threads_updated =
    updateValue< long >( d, "local_num_threads", n_threads );

  // set RNGs --- MUST come after n_threads_ is updated
  if ( d->known( "rngs" ) )
  {
    // this array contains pre-seeded RNGs, so they can be used
    // directly, no seeding required
    ArrayDatum* ad = dynamic_cast< ArrayDatum* >( ( *d )[ "rngs" ].datum() );
    if ( ad == 0 )
      throw BadProperty();

    // n_threads_ is the new value after a change of the number of
    // threads
    if ( ad->size()
      != ( size_t )( kernel().vp_manager.get_num_virtual_processes() ) )
    {
      LOG( M_ERROR,
        "RNGManager::set_status",
        "Number of RNGs must equal number of virtual processes "
        "(threads*processes). RNGs "
        "unchanged." );
      throw DimensionMismatch(
        ( size_t )( kernel().vp_manager.get_num_virtual_processes() ),
        ad->size() );
    }

    // delete old generators, insert new generators this code is
    // robust under change of thread number in this call to
    // set_status, as long as it comes AFTER n_threads_ has been
    // upated
    rng_.clear();
    for ( index i = 0; i < ad->size(); ++i )
      if ( kernel().vp_manager.is_local_vp( i ) )
        rng_.push_back( getValue< librandom::RngDatum >(
          ( *ad )[ kernel().vp_manager.suggest_vp( i ) ] ) );
  }
  else if ( n_threads_updated && kernel().node_manager.size() == 0 )
  {
    LOG( M_WARNING,
      "RNGManager::set_status",
      "Equipping threads with new default RNGs" );
    create_rngs_();
  }

  if ( d->known( "rng_seeds" ) )
  {
    ArrayDatum* ad =
      dynamic_cast< ArrayDatum* >( ( *d )[ "rng_seeds" ].datum() );
    if ( ad == 0 )
      throw BadProperty();

    if ( ad->size()
      != ( size_t )( kernel().vp_manager.get_num_virtual_processes() ) )
    {
      LOG( M_ERROR,
        "RNGManager::set_status",
        "Number of seeds must equal number of virtual processes "
        "(threads*processes). RNGs unchanged." );
      throw DimensionMismatch(
        ( size_t )( kernel().vp_manager.get_num_virtual_processes() ),
        ad->size() );
    }

    // check if seeds are unique
    std::set< ulong_t > seedset;
    for ( index i = 0; i < ad->size(); ++i )
    {
      long s = ( *ad )[ i ]; // SLI has no ulong tokens
      if ( !seedset.insert( s ).second )
      {
        LOG( M_WARNING,
          "RNGManager::set_status",
          "Seeds are not unique across threads!" );
        break;
      }
    }

    // now apply seeds, resets generators automatically
    for ( index i = 0; i < ad->size(); ++i )
    {
      long s = ( *ad )[ i ];

      if ( kernel().vp_manager.is_local_vp( i ) )
        rng_[ kernel().vp_manager.vp_to_thread(
                kernel().vp_manager.suggest_vp( i ) ) ]->seed( s );

      rng_seeds_[ i ] = s;
    }
  } // if rng_seeds

  // set GRNG
  if ( d->known( "grng" ) )
  {
    // pre-seeded grng that can be used directly, no seeding required
    updateValue< librandom::RngDatum >( d, "grng", grng_ );
  }
  else if ( n_threads_updated && kernel().node_manager.size() == 0 )
  {
    LOG( M_WARNING,
      "RNGManager::set_status",
      "Equipping threads with new default GRNG" );
    create_grng_();
  }

  if ( d->known( "grng_seed" ) )
  {
    const long gseed = getValue< long >( d, "grng_seed" );

    // check if grng seed is unique with respect to rng seeds
    // if grng_seed and rng_seeds given in one SetStatus call
    std::set< ulong_t > seedset;
    seedset.insert( gseed );
    if ( d->known( "rng_seeds" ) )
    {
      ArrayDatum* ad_rngseeds =
        dynamic_cast< ArrayDatum* >( ( *d )[ "rng_seeds" ].datum() );
      if ( ad_rngseeds == 0 )
        throw BadProperty();
      for ( index i = 0; i < ad_rngseeds->size(); ++i )
      {
        const long vpseed = ( *ad_rngseeds )[ i ]; // SLI has no ulong tokens
        if ( !seedset.insert( vpseed ).second )
        {
          LOG( M_WARNING,
            "RNGManager::set_status",
            "Seeds are not unique across threads!" );
          break;
        }
      }
    }
    // now apply seed, resets generator automatically
    grng_seed_ = gseed;
    grng_->seed( gseed );

  } // if grng_seed
}
Example #10
0
void
cg_connect( ConnectionGeneratorDatum& cg,
  RangeSet& sources,
  index source_offset,
  RangeSet& targets,
  index target_offset,
  DictionaryDatum params_map,
  index syn )
{
  cg_set_masks( cg, sources, targets );
  cg->start();

  int source, target, num_parameters = cg->arity();
  if ( num_parameters == 0 )
  {
    // connect source to target
    while ( cg->next( source, target, NULL ) )
    {
      if ( ConnectionGeneratorModule::get_network().is_local_gid( target + target_offset ) )
      {
        Node* const target_node =
          ConnectionGeneratorModule::get_network().get_node( target + target_offset );
        const thread target_thread = target_node->get_thread();
        ConnectionGeneratorModule::get_network().connect(
          source + source_offset, target_node, target_thread, syn );
      }
    }
  }
  else if ( num_parameters == 2 )
  {
    if ( !params_map->known( names::weight ) || !params_map->known( names::delay ) )
      throw BadProperty( "The parameter map has to contain the indices of weight and delay." );

    long w_idx = ( *params_map )[ names::weight ];
    long d_idx = ( *params_map )[ names::delay ];
    std::vector< double > params( 2 );

    // connect source to target with weight and delay
    while ( cg->next( source, target, &params[ 0 ] ) )
    {
      if ( ConnectionGeneratorModule::get_network().is_local_gid( target + target_offset ) )
      {
        Node* const target_node =
          ConnectionGeneratorModule::get_network().get_node( target + target_offset );
        const thread target_thread = target_node->get_thread();
        ConnectionGeneratorModule::get_network().connect( source + source_offset,
          target_node,
          target_thread,
          syn,
          params[ d_idx ],
          params[ w_idx ] );
      }
    }
  }
  else
  {
    ConnectionGeneratorModule::get_network().message( SLIInterpreter::M_ERROR,
      "Connect",
      "Either two or no parameters in the Connection Set expected." );
    throw DimensionMismatch();
  }
}