Exemple #1
0
static void test_init_direction(CuTest *tc) {
    struct locale *lang;
    test_cleanup();

    lang = get_or_create_locale("de");
    init_direction(lang, D_NORTHWEST, "NW");
    init_direction(lang, D_EAST, "OST");
    CuAssertIntEquals(tc, D_NORTHWEST, get_direction("nw", lang));
    CuAssertIntEquals(tc, D_EAST, get_direction("ost", lang));
    CuAssertIntEquals(tc, NODIRECTION, get_direction("east", lang));
    test_cleanup();
}
Exemple #2
0
static void json_direction(cJSON *json, struct locale *lang) {
    cJSON *child;
    if (json->type!=cJSON_Object) {
        log_error("directions for locale `%s` not a json object: %d", locale_name(lang), json->type);
        return;
    }
    for (child=json->child;child;child=child->next) {
        direction_t dir = finddirection(child->string);
        if (dir!=NODIRECTION) {
            if (child->type==cJSON_String) {
                init_direction(lang, dir, child->valuestring);
            }
            else if (child->type==cJSON_Array) {
                cJSON *entry;
                for (entry=child->child;entry;entry=entry->next) {
                    init_direction(lang, dir, entry->valuestring);
                }
            } else {
                log_error("invalid type %d for direction `%s`", child->type, child->string);
            }
        }
    }
}
Exemple #3
0
int initSolver()
{
	int i, j, _tmp;

	/* initialise global counters */

	current_node_stamp = 1;
	lookDead 	   = 0;
	mainDead 	   = 0;
#ifdef COUNT_SAT
	count_sat	   = 0;
#endif
       solution_bin = 0;
       solution_bits = 63;
#ifdef DISTRIBUTION
       first_time = 0;
       skip_flag = 0;
       first_depth = 20;
#endif
       currentNodeNumber = 1;
       UNSATflag = 0;

	/* allocate recursion stack */
	/* tree is max. nrofvars deep and we thus have max. nrofvars STACK_BLOCKS
		 -> 2 * nrofvars should be enough for everyone :)
	*/
	INIT_ARRAY( r       , 3 * nrofvars + 1   );

	INIT_ARRAY( imp     , INITIAL_ARRAY_SIZE );
	INIT_ARRAY( subsume , INITIAL_ARRAY_SIZE );
	INIT_ARRAY( bieq    , INITIAL_ARRAY_SIZE );
	INIT_ARRAY( newbi   , INITIAL_ARRAY_SIZE );
	INIT_ARRAY( sub     , INITIAL_ARRAY_SIZE );

	MALLOC_OFFSET( bImp_satisfied, int, nrofvars, 2 );
	MALLOC_OFFSET( bImp_start,     int, nrofvars, 2 );
	MALLOC_OFFSET( bImp_stamps,    int, nrofvars, 0 );
	MALLOC_OFFSET( node_stamps, tstamp, nrofvars, 0 );

	tmpEqImpSize  = (int*) malloc( sizeof(int) * (nrofvars+1) );

	init_lookahead();
	init_preselection();
#ifdef DISTRIBUTION
	init_direction();
#endif
	tmpTernaryImpSize = (int* ) malloc( sizeof(int ) * ( 2*nrofvars+1 ) );
#ifdef TERNARYLOOK
        TernaryImp 	  = (int**) malloc( sizeof(int*) * ( 2*nrofvars+1 ) );
        TernaryImpSize 	  = (int* ) malloc( sizeof(int ) * ( 2*nrofvars+1 ) );

        for( i = 0; i <= 2 * nrofvars; i++ )
	{
	    tmpTernaryImpSize[ i ] = 0;
	    TernaryImpSize   [ i ] = 0;
	}

	for( i = 0; i < nrofclauses; i++ )
	    if( Clength[ i ] == 3 )
		for( j = 0; j < 3; j++ )
		    TernaryImpSize[ Cv[ i ][ j ] + nrofvars ]++;

        for( i = 0; i <= 2 * nrofvars; i++ )
	    TernaryImp[ i ] = (int*) malloc(sizeof(int)*(4*TernaryImpSize[i]+4));

        tmpTernaryImpSize 	+= nrofvars;
        TernaryImp 		+= nrofvars;
	TernaryImpSize 		+= nrofvars;

	fill_ternary_implication_arrays();

        for( i = -nrofvars; i <= nrofvars; i++ )
//	    tmpTernaryImpSize[ i ] = 2 * tmpTernaryImpSize[ i ] + 2;	
	    tmpTernaryImpSize[ i ] = 4 * TernaryImpSize[ i ] + 2;	

//	branch_on_dummies_from_long_clauses();

	while( AddTernaryResolvents() );

        for( i = -nrofvars; i <= nrofvars; i++ )
	    free( TernaryImp[ i ] );

	FREE_OFFSET( TernaryImp     );
	FREE_OFFSET( TernaryImpSize );
#else
        tmpTernaryImpSize 	+= nrofvars;
#endif
	/* initialise global datastructures */

#ifdef GLOBAL_AUTARKY
	MALLOC_OFFSET( TernaryImpReduction, int, nrofvars, 0 );

	if( kSAT_flag )
	{
	    int _nrofliterals = 0;

	    for( i = 0; i < nrofbigclauses; ++i )
		_nrofliterals += clause_length[ i ];

	    clause_reduction = (int*)  malloc( sizeof(int ) * nrofbigclauses );
	    clause_red_depth = (int*)  malloc( sizeof(int ) * nrofbigclauses );
	    big_global_table = (int*)  malloc( sizeof(int ) * _nrofliterals );
	    clause_SAT_flag  = (int*)  malloc( sizeof(int ) * nrofbigclauses );

	    MALLOC_OFFSET( big_to_binary, int*, nrofvars, NULL );
	    MALLOC_OFFSET( btb_size,      int , nrofvars,    0 );

	    for( i = 0; i < nrofbigclauses; ++i )
	    {
		clause_reduction[ i ] =  0;
		clause_red_depth[ i ] =  nrofvars;
		clause_SAT_flag [ i ] =  0;
	    }

	    int tmp = 0;
            for( i = 1; i <= nrofvars; i++ )
            {
                big_to_binary[  i ] = (int*) &big_global_table[ tmp ];
                tmp += big_occ[  i ];

                big_to_binary[ -i ] = (int*) &big_global_table[ tmp ];
                tmp += big_occ[ -i ];

            }
	    assert( tmp == _nrofliterals );
	}
#endif
        TernaryImp 	= (int**) malloc( sizeof(int*) * ( 2*nrofvars+1 ) );
        TernaryImpSize 	= (int* ) malloc( sizeof(int ) * ( 2*nrofvars+1 ) );
        TernaryImpLast 	= (int* ) malloc( sizeof(int ) * ( 2*nrofvars+1 ) );
        TernaryImpTable	= (int* ) malloc( sizeof(int ) * ( 6*nrofclauses+1 ) );

	TernaryImp	       += nrofvars;
	TernaryImpSize	       += nrofvars;
	TernaryImpLast	       += nrofvars;

	if( simplify_formula() == UNSAT ) return UNSAT;

	for( i = -nrofvars; i <= nrofvars; i++ )
	{
	    tmpTernaryImpSize[ i ] = 0;
	    TernaryImpSize   [ i ] = 0;
	    bImp_satisfied   [ i ] = 2;	//waarom staat dit hier?
	}

	for( i = 0; i < nrofclauses; i++ )
	    if( Clength[ i ] == 3 )
		for( j = 0; j < 3; j++ )
		    TernaryImpSize[ Cv[ i ][ j ] ]++;

	_tmp = 0;
        for( i = -nrofvars; i <= nrofvars; i++ )
        {
	    TernaryImp[ i ]     = TernaryImpTable + 2 * _tmp;
            _tmp               += TernaryImpSize[ i ];
	    TernaryImpLast[ i ] = TernaryImpSize[ i ];
        }

	fill_ternary_implication_arrays();

	rebuild_BinaryImp();

	init_freevars();

	for( i = 0; i < nrofceq ; i++ )
	    assert( CeqSizes[ i ] != 1 );
#ifdef EQ
	for( i = 0; i < nrofceq ; i++ )	
	    if( CeqSizes[ i ] == 2 )
            	DPLL_propagate_binary_equivalence( i );
#endif
#ifdef DETECT_COMPONENTS
	init_localbranching();
#endif
#ifdef CUT_OFF
	solution_bits = CUT_OFF - 1;
#endif

	push_stack_blocks();

	return 1;
}
Exemple #4
0
int main(int argc, char* argv[]) {
  char *device1 = NULL, *device2 = NULL, *bind_mask = NULL, c;
  int cluster_id = -1;
  u_int numCPU = sysconf( _SC_NPROCESSORS_ONLN );

  dir[0].bind_core = dir[1].bind_core = -1;

  startTime.tv_sec = 0;

  while((c = getopt(argc,argv,"abc:g:hi:o:fv")) != '?') {
    if((c == 255) || (c == -1)) break;

    switch(c) {
    case 'h':
      printHelp();
      break;
    case 'a':
      wait_for_packet = 0;
      break;
    case 'f':
      flush_packet = 1;
      break;
    case 'v':
      verbose = 1;
      break;
    case 'b':
      bidirectional = 1;
      break;
    case 'c':
      cluster_id = atoi(optarg);
      break;
    case 'i':
      device1 = strdup(optarg);
      break;
    case 'o':
      device2 = strdup(optarg);
      break;
    case 'g':
      bind_mask = strdup(optarg);
      break;
    }
  }
  
  if (device1 == NULL) printHelp();
  if (device2 == NULL) printHelp();
  if (cluster_id < 0)  printHelp();

  if(bind_mask != NULL) {
    char *id;
    if ((id = strtok(bind_mask, ":")) != NULL)
      dir[0].bind_core = atoi(id) % numCPU;
    if ((id = strtok(NULL, ":")) != NULL)
      dir[1].bind_core = atoi(id) % numCPU;
  }

  zc = pfring_zc_create_cluster(
    cluster_id, 
    1536, 
    0, 
    (2 * MAX_CARD_SLOTS) + 1 + bidirectional,
    numa_node_of_cpu(dir[0].bind_core), 
    NULL /* auto hugetlb mountpoint */ 
  );

  if(zc == NULL) {
    fprintf(stderr, "pfring_zc_create_cluster error [%s] Please check your hugetlb configuration\n",
	    strerror(errno));
    return -1;
  }

  if (init_direction(0, device1, device2) < 0) 
    return -1;

  if (bidirectional)
    if (init_direction(1, device2, device1) < 0) 
      return -1;

  signal(SIGINT,  sigproc);
  signal(SIGTERM, sigproc);
  signal(SIGINT,  sigproc);

  if (!verbose) { /* periodic stats */
    signal(SIGALRM, my_sigalarm);
    alarm(ALARM_SLEEP);
  }

  pthread_create(&dir[0].thread, NULL, packet_consumer_thread, (void *) &dir[0]);
  if (bidirectional) pthread_create(&dir[1].thread, NULL, packet_consumer_thread, (void *) &dir[1]);

  pthread_join(dir[0].thread, NULL);
  if (bidirectional) pthread_join(dir[1].thread, NULL);

  sleep(1);

  pfring_zc_destroy_cluster(zc);

  return 0;
}