コード例 #1
0
ファイル: traffic.cpp プロジェクト: DINKIN/booksim2
void RandomPermutationTrafficPattern::randomize(int seed)
{
  vector<long> save_x;
  vector<double> save_u;
  SaveRandomState(save_x, save_u);
  RandomSeed(seed);

  _dest.assign(_nodes, -1);

  for(int i = 0; i < _nodes; ++i) {
    int ind = RandomInt(_nodes - 1 - i);

    int j = 0;
    int cnt = 0;
    while((cnt < ind) || (_dest[j] != -1)) {
      if(_dest[j] == -1) {
	++cnt;
      }
      ++j;
      assert(j < _nodes);
    }

    _dest[j] = i;
  }

  RestoreRandomState(save_x, save_u); 
}
コード例 #2
0
ファイル: kncube.cpp プロジェクト: hudsontek/booksim2
/*legacy, not sure how this fits into the own scheme of things*/
void KNCube::InsertRandomFaults( const Configuration &config )
{
  int num_fails = config.GetInt( "link_failures" );
  
  if ( _size && num_fails ) {
    vector<long> save_x;
    vector<double> save_u;
    SaveRandomState( save_x, save_u );
    int fail_seed;
    if ( config.GetStr( "fail_seed" ) == "time" ) {
      fail_seed = int( time( NULL ) );
      cout << "SEED: fail_seed=" << fail_seed << endl;
    } else {
      fail_seed = config.GetInt( "fail_seed" );
    }
    RandomSeed( fail_seed );

    vector<bool> fail_nodes(_size);

    for ( int i = 0; i < _size; ++i ) {
      int node = i;

      // edge test
      bool edge = false;
      for ( int n = 0; n < _n; ++n ) {
	if ( ( ( node % _k ) == 0 ) ||
	     ( ( node % _k ) == _k - 1 ) ) {
	  edge = true;
	}
	node /= _k;
      }

      if ( edge ) {
	fail_nodes[i] = true;
      } else {
	fail_nodes[i] = false;
      }
    }

    for ( int i = 0; i < num_fails; ++i ) {
      int j = RandomInt( _size - 1 );
      bool available = false;
      int node, chan;
      int t;

      for ( t = 0; ( t < _size ) && (!available); ++t ) {
		node = ( j + t ) % _size;
	       
		if ( !fail_nodes[node] ) {
		  // check neighbors
		  int c = RandomInt( 2*_n - 1 );

		  for ( int n = 0; ( n < 2*_n ) && (!available); ++n ) {
		    chan = ( n + c ) % 2*_n;

		    if ( chan % 1 ) {
		      available = fail_nodes[_LeftNode( node, chan/2 )];
		    } else {
		      available = fail_nodes[_RightNode( node, chan/2 )];
		    }
		  }
		}
		
		if ( !available ) {
		  cout << "skipping " << node << endl;
		}
      }

      if ( t == _size ) {
		Error( "Could not find another possible fault channel" );
      }

      
      OutChannelFault( node, chan );
      fail_nodes[node] = true;

      for ( int n = 0; ( n < _n ) && available ; ++n ) {
		fail_nodes[_LeftNode( node, n )]  = true;
		fail_nodes[_RightNode( node, n )] = true;
      }

      cout << "failure at node " << node << ", channel " 
	   << chan << endl;
    }

    RestoreRandomState( save_x, save_u );
  }
}