Ejemplo n.º 1
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();  
    }
  }
Ejemplo n.º 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 )
  {
    // 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();
  }
}
Ejemplo n.º 3
0
  void cg_set_masks(ConnectionGeneratorDatum& cg, RangeSet& sources, RangeSet& targets)
  {
    std::vector<ConnectionGenerator::Mask> masks(Communicator::get_num_processes());
    cg_create_masks(&masks, sources, targets);

    cg->setMask(masks, Communicator::get_rank());
  }
Ejemplo n.º 4
0
/**
 * Set the masks on the ConnectionGenerator cg. This function also
 * creates the masks from the given RangeSets sources and targets.
 *
 * \param cg The ConnectionGenerator to set the masks on
 * \param sources The source ranges to create the source masks from
 * \param targets The target ranges to create the target masks from
 */
void
cg_set_masks( ConnectionGeneratorDatum& cg, RangeSet& sources, RangeSet& targets )
{
  long np = kernel().mpi_manager.get_num_processes();
  std::vector< ConnectionGenerator::Mask > masks( np, ConnectionGenerator::Mask( 1, np ) );

  cg_create_masks( &masks, sources, targets );
  cg->setMask( masks, kernel().mpi_manager.get_rank() );
}
Ejemplo n.º 5
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();
  }
}