示例#1
0
 void collectable::phantomize_ref(
     unsigned int w, hpx::id_type parent, hpx::id_type cid)
 {
     if (cd == nullptr)
     {
         cd = new collector_data;
         cd->cid = cid;
         cd->parent = parent;
     }
     else if (cid > cd->cid)
     {
         cd->cid = cid;
         cd->parent = parent;
     }
     generate_output("Phantomized ref");
     state();
     if (w < weight)
     {
         strong_count--;
         HPX_ASSERT(strong_count >= 0);
     }
     else
     {
         weak_count--;
         HPX_ASSERT(weak_count >= 0);
     }
     cd->phantom_count++;
     state();
     spread(weight);
     hpx::apply<collectable::done_action>(parent, this->get_id());
 }
示例#2
0
int hpx_main()
{
    generate_output("Here1");
    {
        auto loc = hpx::find_here();
        gc::collectable c1(hpx::components::new_<gc::server::collectable>(loc));
        {
            gc::collectable c2(
                hpx::components::new_<gc::server::collectable>(loc));
            int index = c1.add_ref(c2.get_id()).get();
            c2.add_ref(c1.get_id()).wait();
        }
    }
    generate_output("Here2");
    return hpx::finalize();
}
示例#3
0
int exomizer(unsigned char *srcbuf, int len, int load, int start, unsigned char *destbuf)
{
    int destlen;
    int max_offset = 65536;
    int max_passes = 65536;
    static match_ctx ctx;
    encode_match_data emd;
    encode_match_priv optimal_priv;
    search_nodep snp;

    match_ctx_init(ctx, srcbuf, len, max_offset);

    emd->out = NULL;
    emd->priv = optimal_priv;

    optimal_init(emd);

    snp = do_compress(ctx, emd, max_passes);

    destlen = generate_output(ctx, snp, sfx_c64ne, optimal_encode, emd,
                              load, len, start, destbuf);
    optimal_free(emd);

#if 0 /* RH */
    search_node_free(snp);
#endif /* RH */
    match_ctx_free(ctx);

    return destlen;
}
void NeuralNetwork::action()
{

    get_input_table();
    read_chromosome();
    get_nodes_values();
    generate_output();

//    print_chromosome();
//    print_input_table();
//    print_nodes_table();
//    print_output_table();

    if(output_table[0]==1)
        game->player_right();
    if(output_table[1]==1)
        game->player_up();
    if(output_table[2]==1)
        game->player_left();
    if(game->get_r_flag() == 1)
    {
        game->set_r_flag(0);
//        generate_random_chromosome();
    }

    //    game->player_right();
    //    get_input_table();
}
示例#5
0
int main(){
	int rank;
	int nprocs;
	mpi_initialize(rank, nprocs);

	generate_output(rank, nprocs);

	mpi_finalize();
}
示例#6
0
 void collectable::clean()
 {
     generate_output("Definitely garbage ", id);
     int n = out_refs.size();
     for (int i = 0; i < n; i++)
     {
         set_ref(i, hpx::naming::invalid_id);
     }
 }
示例#7
0
event_type JackProcessor::fill_output_buffer(int sequence_number)
{
  if (m_sequence_number == sequence_number)
    return 0;
  m_sequence_number = sequence_number;
  event_type events = fill_input_buffer(sequence_number);
  generate_output();
  events |= handle_memcpys();
  return events;
}
示例#8
0
 void collectable::state()
 {
     generate_output_no_endl("id=", id, " wt=", weight, " sc=", strong_count,
         " wc=", weak_count);
     if (cd != nullptr)
     {
         generate_output_no_endl(" pc=", cd->phantom_count);
     }
     generate_output();
 }
示例#9
0
int main(){
  int output_list[50];
  for(int i=0; i< 50; i++){
    output_list[i] = 0;
  }
  char str[] ="- This, a sample string! what + about? and now: this|that \"doublequoted\" and; 'quoted'";
  extract_words(str,output_list);
  generate_output("test.txt",output_list);

}
示例#10
0
 void collectable::phantom_wait_complete()
 {
     generate_output("Waiting complete ", id);
     if (strong_count > 0)
     {
         // we can build
         HPX_ASSERT("build not handled" == nullptr);
     }
     else
     {
         // we need to recover
         recover(cd->cid);
     }
 }
示例#11
0
文件: main.cpp 项目: CCJY/coliru
int main (int, char**)
{
  std::string generated;
  std::back_insert_iterator<std::string> sink(generated);

  std::vector<double> data{1.5, 0.0, -2.5,
                           std::numeric_limits<float>::quiet_NaN(),
                           std::numeric_limits<float>::infinity()};

  generate_output(sink, data);

  std::cout << generated << std::endl;

  return 0;
}
示例#12
0
 void collectable::check_recover_done()
 {
     if (cd->wc == 0)
     {
         hpx::id_type this_id = get_id();
         if (cd->cid == this_id)
         {
             if (strong_count == 0)
             {
                 generate_output("Delete!");
             }
         }
         else
         {
             hpx::apply<collectable::recover_done_action>(cd->parent);
         }
     }
 }
示例#13
0
 void collectable::decref(unsigned int w)
 {
     if (w < weight)
     {
         strong_count--;
         if (strong_count == 0)
         {
             if (weak_count == 0)
             {
                 if (cd == nullptr || cd->phantom_count == 0)
                 {
                     clean();
                 }
             }
             else
             {
                 generate_output("Maybe garbage ", id);
                 unsigned int ow = weight;
                 weight = max_weight + 1;
                 strong_count = weak_count;
                 weak_count = 0;
                 if (cd == nullptr)
                 {
                     cd = new collector_data;
                     cd->cid = this->get_id();
                 }
                 spread(ow);
             }
         }
     }
     else
     {
         weak_count--;
         HPX_ASSERT(weak_count >= 0);
         if (weak_count == 0 && strong_count == 0)
         {
             if (cd == nullptr || cd->phantom_count == 0)
             {
                 clean();
             }
         }
     }
     state();
 }
int main(int argc, char **argv){
	/*****************       declare functions    ************************/
	void generate_div(int num, char division[]);
	void generate_charArray(int num, char array[], int length);
	void generate_grade(int num, char grade[]);
	void generate_credit(int num, char credit[]);
	void generate_output(char division[], char department[], char course[], char grade[], char credit[], char output_string[]);
	/***************         declare char arrays   **********************/
	char division[3];
	char department[4];
	char course[3];
	char grade[2];
	char credit[3];
	char output_string[16];
	/*****************      main function      ****************/
	FILE* f_out;
	f_out = fopen(argv[1],"w");
	printf("Please input number of course strings you want to generate: \n");
	int num_strings;
	scanf("%d", &num_strings);
	while (num_strings > 0){
		num_strings--;
		int div_num = rand() % 8;
		int dep_num = (rand() % 9+1) *(int) pow(10,2) + (rand() % 10) * (int) pow(10,1) + rand() % 10;
		int course_num = (rand() % 9+1) *(int) pow(10,2) + (rand() % 10) * (int) pow(10,1) + rand() % 10;
		int grade_num = (rand() % 9 + 1) * (int) pow(10,1) + rand() % 3;
		int credit_num = (rand() % 6 + 1) * (int) pow(10,1) + rand() %2;
		printf("division: %d\n", div_num);
		printf("department: %d\n", dep_num);
		printf("course_num: %d\n", course_num);
		printf("grade: %d\n", grade_num);
		printf("credit: %d\n", credit_num);
		printf("-----------******************------------\n");
		generate_div(div_num,division);
		generate_charArray(dep_num,department,4);
		generate_charArray(course_num,course,3);
		generate_grade(grade_num,grade);
		generate_credit(credit_num, credit);
		generate_output(division,department,course,grade,credit,output_string);
		fprintf(f_out, "%s\n",output_string);
	}
	fclose(f_out);
}
示例#15
0
int main(int argc,char *argv[])
{
  //Handles user input, to get file names and command
  if(argc<4 || argc>6)
  {
    printf("Incorrect number of arguments\n");
    printf("Number of arguments: %d\n",argc);
    exit(1);
  }

  const char *input_filename=argv[1];
  printf("Inputfile: %s\n",input_filename);
  const char *output_filename=argv[2];
  printf("Outputfile: %s\n",output_filename);
  char garbage[2];
  int command;
  int radius=3;

  if(1!=sscanf(argv[3],"%d%1s",&command,garbage) || command<0 || command>10)
  {
    printf("Incorrect command\n");
    exit(1);
  }

  if(((command==0) && argc==5 && 1!=sscanf(argv[4],"%d%1s",&radius,garbage)) || radius<1)
  {
    printf("Incorrect radius value\n");
    exit(1);
  }
  
  //Create filters and images
  Filter *filters=initialize_filters(radius);
  Image *input_image=decode(input_filename);
  printf("Width: %d, height: %d\n",input_image->width,input_image->height);
  Image *output_image=generate_output(input_image);

  uint8_t *in_red=input_image->red_channel;
  uint8_t *in_blue=input_image->blue_channel;
  uint8_t *in_green=input_image->green_channel;
  uint8_t *in_alpha=input_image->alpha_channel;
  uint8_t *out_red=output_image->red_channel;
  uint8_t *out_blue=output_image->blue_channel;
  uint8_t *out_green=output_image->green_channel;
  uint8_t *out_alpha=output_image->alpha_channel;
  int height=input_image->height;
  int width=input_image->width;


  //Run chosen command to call functions from functions.c
  switch(command)
  {
    case(0):
    {
      convolve_image(in_red,in_green,in_blue,in_alpha,out_red,out_green,out_blue,
                    out_alpha,filters[0].filter,filters[0].radius,width,height);
      encode(output_filename,output_image);
      break;
    }
    case(1):
    {
      convolve_image(in_red,in_green,in_blue,in_alpha,out_red,out_green,out_blue,
                    out_alpha,filters[1].filter,filters[1].radius,width,height);
      encode(output_filename,output_image);
      break;
    }
    case(2):
    {
      convolve_image(in_red,in_green,in_blue,in_alpha,out_red,out_green,out_blue,
                    out_alpha,filters[2].filter,filters[2].radius,width,height);
      encode(output_filename,output_image);
      break;
    }
    case(3):
    {
      convolve_image(in_red,in_green,in_blue,in_alpha,out_red,out_green,out_blue,
                    out_alpha,filters[3].filter,filters[3].radius,width,height);
      encode(output_filename,output_image);
      break;
    }
    case(4):
    {
      convolve_image(in_red,in_green,in_blue,in_alpha,out_red,out_green,out_blue,
                    out_alpha,filters[4].filter,filters[4].radius,width,height);
      encode(output_filename,output_image);
      break;
    }
    case(5):
    {
      convolve_image(in_red,in_green,in_blue,in_alpha,out_red,out_green,out_blue,
                    out_alpha,filters[5].filter,filters[5].radius,width,height);
      encode(output_filename,output_image);
      break;
    }
    case(6):
    {
      convert_to_gray(in_red,in_green,in_blue,in_alpha,out_red,out_green,out_blue,
                    out_alpha,gmonomult,width,height);
      encode(output_filename,output_image);
      break;
     }
    case(7):
    {
      flip_vertical(in_red,in_green,in_blue,in_alpha,out_red,out_green,out_blue,
                  out_alpha,width,height);
      encode(output_filename,output_image);
      break;
    }
    case(8):
    {
      color_threshold(in_red,in_green,in_blue,in_alpha,out_red,out_green,out_blue,
                  out_alpha,width,height,10,150,10);
      encode(output_filename,output_image);
      break;
    }
    default:
      exit(1);
  }

 
  free((double*)filters[0].filter);
  free(filters);
  free_image(input_image);
  free_image(output_image);
  return 0;
}
示例#16
0
int main(int argc, char *argv[])
{
	char *optstr = NULL;
	char *name = NULL;
	int opt;
	int compatible = 0;

	/* Stop scanning as soon as a non-option argument is found! */
	static const char *shortopts = "+ao:l:n:qQs:TuhV";
	static const struct option longopts[] = {
		{"options", required_argument, NULL, 'o'},
		{"longoptions", required_argument, NULL, 'l'},
		{"quiet", no_argument, NULL, 'q'},
		{"quiet-output", no_argument, NULL, 'Q'},
		{"shell", required_argument, NULL, 's'},
		{"test", no_argument, NULL, 'T'},
		{"unquoted", no_argument, NULL, 'u'},
		{"help", no_argument, NULL, 'h'},
		{"alternative", no_argument, NULL, 'a'},
		{"name", required_argument, NULL, 'n'},
		{"version", no_argument, NULL, 'V'},
		{NULL, 0, NULL, 0}
	};

	setlocale(LC_ALL, "");
	bindtextdomain(PACKAGE, LOCALEDIR);
	textdomain(PACKAGE);
	atexit(close_stdout);

	init_longopt();
	getopt_long_fp = getopt_long;

	if (getenv("GETOPT_COMPATIBLE"))
		compatible = 1;

	if (argc == 1) {
		if (compatible) {
			/*
			 * For some reason, the original getopt gave no
			 * error when there were no arguments.
			 */
			printf(" --\n");
			return EXIT_SUCCESS;
		} else
			parse_error(_("missing optstring argument"));
	}

	if (argv[1][0] != '-' || compatible) {
		quote = 0;
		optstr = xmalloc(strlen(argv[1]) + 1);
		strcpy(optstr, argv[1] + strspn(argv[1], "-+"));
		argv[1] = argv[0];
		return generate_output(argv + 1, argc - 1, optstr,
				       long_options);
	}

	while ((opt =
		getopt_long(argc, argv, shortopts, longopts, NULL)) != EOF)
		switch (opt) {
		case 'a':
			getopt_long_fp = getopt_long_only;
			break;
		case 'h':
			print_help();
		case 'o':
			free(optstr);
			optstr = xmalloc(strlen(optarg) + 1);
			strcpy(optstr, optarg);
			break;
		case 'l':
			add_long_options(optarg);
			break;
		case 'n':
			free(name);
			name = xmalloc(strlen(optarg) + 1);
			strcpy(name, optarg);
			break;
		case 'q':
			quiet_errors = 1;
			break;
		case 'Q':
			quiet_output = 1;
			break;
		case 's':
			set_shell(optarg);
			break;
		case 'T':
			return TEST_EXIT_CODE;
		case 'u':
			quote = 0;
			break;
		case 'V':
			printf(UTIL_LINUX_VERSION);
			return EXIT_SUCCESS;
		case '?':
		case ':':
			parse_error(NULL);
		default:
			parse_error(_("internal error, contact the author."));
		}

	if (!optstr) {
		if (optind >= argc)
			parse_error(_("missing optstring argument"));
		else {
			optstr = xmalloc(strlen(argv[optind]) + 1);
			strcpy(optstr, argv[optind]);
			optind++;
		}
	}
	if (name)
		argv[optind - 1] = name;
	else
		argv[optind - 1] = argv[0];

	return generate_output(argv + optind - 1, argc-optind + 1,
			       optstr, long_options);
}
示例#17
0
int main(int argc, char *argv[])
{
	char *optstr=NULL;
	char *name=NULL;
	int opt;
	int compatible=0;

#if WITHOUT_GETTEXT
#else
	setlocale(LC_ALL,"");
	bindtextdomain(PACKAGE, LOCALEDIR);
	textdomain(PACKAGE);
#endif

	init_longopt();

	if (getenv("GETOPT_COMPATIBLE")) 
		compatible=1;

	if (argc == 1) 
	{
		if (compatible) {
			/* For some reason, the original getopt gave no error
                           when there were no arguments. */
			printf(" --\n");
			exit(0);
		}
		else
			parse_error(_("missing optstring argument"));
	}
	
	if (argv[1][0] != '-' || compatible) {
		quote=0;
		optstr=our_malloc(strlen(argv[1])+1);
		strcpy(optstr,argv[1]+strspn(argv[1],"-+"));
		argv[1]=argv[0];
		exit(generate_output(argv+1,argc-1,optstr,long_options));
	}
	
	while ((opt=getopt_long(argc,argv,shortopts,longopts,NULL)) != EOF) 
		switch (opt) {
		case 'a':
			alternative=1;
			break;
		case 'h':
			print_help();
			exit(0);
		case 'o':
			if (optstr)
				free(optstr);
			optstr=our_malloc(strlen(optarg)+1);
			strcpy(optstr,optarg);
			break;
		case 'l':
			add_long_options(optarg);
			break;
		case 'n':
			if (name)
				free(name);
			name=our_malloc(strlen(optarg)+1);
			strcpy(name,optarg);
			break;
		case 'q':
			quiet_errors=1;
			break;
		case 'Q':
			quiet_output=1;
			break;
		case 's':
			set_shell(optarg);
			break;
		case 'T':
			exit(4);
		case 'u':
			quote=0;
			break;
		case 'V':
			printf(_("getopt (enhanced) 1.1.3\n"));
			exit(0);
		case '?':
		case ':':
			parse_error(NULL);
		default:
			parse_error(_("internal error, contact the author."));
		}
	
	if (!optstr) 
	{
		if (optind >= argc)
			parse_error(_("missing optstring argument"));
		else {
			optstr=our_malloc(strlen(argv[optind])+1);
			strcpy(optstr,argv[optind]);
			optind++;
		}
	}
	if (name)
		argv[optind-1]=name;
	else
		argv[optind-1]=argv[0];
	exit(generate_output(argv+optind-1,argc-optind+1,optstr,long_options));
}
示例#18
0
static crypto::key_image generate_key_image()
{
  return crypto::rand<crypto::key_image>();
}

static crypto::public_key generate_output()
{
  return crypto::rand<crypto::public_key>();
}


static const crypto::chacha_key KEY_1 = generate_chacha_key();
static const crypto::chacha_key KEY_2 = generate_chacha_key();
static const crypto::key_image KEY_IMAGE_1 = generate_key_image();
static const crypto::public_key OUTPUT_1 = generate_output();
static const crypto::public_key OUTPUT_2 = generate_output();

class RingDB: public tools::ringdb
{
public:
  RingDB(const char *genesis = ""): tools::ringdb(make_filename(), genesis) { }
  ~RingDB() { close(); boost::filesystem::remove_all(filename); free(filename); }

private:
  std::string make_filename()
  {
    boost::filesystem::path path = tools::get_default_data_dir();
    path /= "fake";
#if defined(__MINGW32__) || defined(__MINGW__)
    filename = tempnam(path.string().c_str(), "ringdb-test-");
示例#19
0
int main(int argc, const char* argv[])
{
	int n = 0, i = 0, shortest_dist;
	double search_array[9], border_sector[4], sharpness = 0.000001;
	
	/*there it'll get console option, 1 is for Euclidis metric, 2 is for NY, 3 is for custom affin NY, 4 is for l_inf*/
	if ( argc > 1 && atoi(argv[1]) > 0 && atoi(argv[1]) < 5) 
    	runmode = atoi( argv[1] );
	else runmode = 1;
	
	std::ifstream myfile("input.txt");
	
	std::string linecounterline;
	while (std::getline(myfile, linecounterline)) //count rows with input points
		n++;
	double points[n*2];
	
	//printf("%d rows found\n\n", n);
	
	myfile.clear();                 // clear fail and eof bits
	myfile.seekg(0, std::ios::beg); // back to start
	for (i = 0; i < n*2; i++)
		myfile >> points[i];
	
	/*printf("001 Input coordinates:\n"); //debug
	for(i=0; i < n; i++)
	{
		printf("%f ", points[i*2]);
		printf("%f \n", points[i*2+1]);
	}
	printf("\n");*/
	
	/*finding first sector corners*/
	double min_x = points[0], min_y = points[1], max_x = points[0], max_y = points[1];
	for(i = 1; i < n; i++)
	{
		if (points[i*2] < min_x) min_x=points[i*2];
		if (points[i*2] > max_x) max_x=points[i*2];
		
		if (points[i*2+1] < min_y) min_y=points[i*2+1];
		if (points[i*2+1] > max_y) max_y=points[i*2+1];
	}
	
	/*printf("002 min_x = %f, min_y = %f\n", min_x, min_y);*/	/*debug*/
	/*printf("003 max_x = %f, max_y = %f\n\n", max_x, max_y);*/
	
	double * test_array;
	test_array = list_of_sectors(min_x, min_y, max_x, max_y);
	
	/*printf("004 min_x = %f, min_y = %f\n", min_x, min_y);*/	/*debug*/
	/*printf("005 max_x = %f, max_y = %f\n\n", max_x, max_y);*/
	
	/*printf("006 It got min and max coordinates and sliced to sectors:\n");
	for (i = 0; i < 20; i = i+2)
	printf("%f %f\n", test_array[i], test_array[i+1]);
	printf("\n");*/
	
	border_sector[0] = min_x; border_sector[1] = min_y;
	border_sector[2] = max_x; border_sector[3] = max_y;
	
	/*printf("007 min_x = %f, min_y = %f\n", min_x, min_y);*/	/*debug*/
	/*printf("008 max_x = %f, max_y = %f\n\n", max_x, max_y);*/
	
	double * sector_to_narrow = border_sector; i = 0;
	//for(i = 0; i < 16; i++)
	i = 0;
	do
	{
		sector_to_narrow = narrow_sector(sector_to_narrow, points, n, runmode);
		i++;
		
		/*printf("_%d sector narrowed:", i);*/  //uncomment this to demonstrate current step
		/*printf("\n%f %f\n%f %f\n\n", 
				sector_to_narrow[0], 			//uncomment this to demonstrate current sector
				sector_to_narrow[1], 
				sector_to_narrow[2], 
				sector_to_narrow[3]      );*/
		/*printf("%f %f\n", sector_to_narrow[2] - sector_to_narrow[0],		//uncomment this to demonstrate current sector size
							sector_to_narrow[3] - sector_to_narrow[1]);*/ 

	}	while ( sector_to_narrow[2] - sector_to_narrow[0] > sharpness ||
				sector_to_narrow[3] - sector_to_narrow[1] > sharpness    ); 
	
	generate_output (n, points, sector_to_narrow[0], sector_to_narrow[1], runmode);
	      
	/*printf("000 Finished");*/  /*debug*/
	//scanf("%d", i);
	return 0;
}
示例#20
0
int tardiffmerge(int argc, char *argv[], char *flags)
{
    int n, num_diffs;
    struct File *files, *file;
    bool input_ok, output_ok, order_files;

    num_diffs = argc - 1;
    input_ok = output_ok = false;
    order_files = (strchr(flags, 'f') == NULL);

    /* Verify arguments are all diff files: */
    input_ok = identify_files((const char**)argv, num_diffs, NULL, &files);
    for (file = files; file != NULL; file = file->next)
    {
        if (file->type == FILE_INVALID)
        {
            fprintf(stderr, "%s: %s\n", file->path, file->invalid.error);
        }
        else
        if (file->type != FILE_DIFF)
        {
            fprintf(stderr, "%s: not a differences file\n", file->path);
            input_ok = false;
        }
        else  /* file->type == FILE_DIFF */
        {
            static uint8_t zero_digest[DS];
            if (order_files &&
                memcmp(file->diff.digest1, zero_digest, DS) == 0)
            {
                fprintf(stderr, "Input contains version 1.0 difference files; "
                                "merge order cannot be determined.\n");
                input_ok = false;
            }
        }
    }

    if (input_ok && order_files)
    {
        mark_usable(files);
        if (!order_input(&files))
        {
            fprintf(stderr, "Input files could not be ordered!\n");
            input_ok = false;
        }
    }

    if (input_ok)
    {
        /* Redirect output (if necessary) */
        if (strcmp(argv[argc - 1], "-") != 0) redirect_stdout(argv[argc - 1]);

        n = 0;
        for (file = files; file != NULL; file = file->next)
        {
            InputStream *is;
            char magic[MAGIC_LEN];

            /* Try to open again */
            is = OpenFileInputStream(file->path);
            if (is == NULL)
            {
                fprintf(stderr, "%s: could not be opened.\n", file->path);
                break;
            }

            /* Save pointer here, so we can close it later. */
            is_diff[n++] = is;

            /* Verify magic again */
            read_data(is, magic, MAGIC_LEN);
            if (memcmp(magic, MAGIC_STR, MAGIC_LEN) != 0)
            {
                fprintf(stderr, "%s: not a differences file\n", file->path);
                break;
            }

            /* Process entire file */
            process_input(is);
        }

        if (file == NULL)
        {
            output_ok = generate_output();
        }

        /* Close open streams: */
        while (n-- > 0) is_diff[n]->close(is_diff[n]);

        munmap(last_blocks, last_num_blocks*sizeof(BlockRef));
    }
    free_files(files);

    return (input_ok && output_ok) ? EXIT_SUCCESS : EXIT_FAILURE;
}
int getopt_main(int argc, char *argv[])
{
        char *optstr=NULL;
        char *name=NULL;
        int opt;
        int compatible=0;

        init_longopt();

        if (getenv("GETOPT_COMPATIBLE"))
                compatible=1;

        if (argc == 1) {
                if (compatible) {
                        /* For some reason, the original getopt gave no error
                           when there were no arguments. */
                        printf(" --\n");
                        exit(0);
                } else
                        error_msg_and_die("missing optstring argument");
        }

        if (argv[1][0] != '-' || compatible) {
                quote=0;
                optstr=xmalloc(strlen(argv[1])+1);
                strcpy(optstr,argv[1]+strspn(argv[1],"-+"));
                argv[1]=argv[0];
                exit(generate_output(argv+1,argc-1,optstr,long_options));
        }

        while ((opt=getopt_long(argc,argv,shortopts,longopts,NULL)) != EOF)
                switch (opt) {
                case 'a':
                        alternative=1;
                        break;
                case 'o':
                        if (optstr)
                                free(optstr);
                        optstr=xmalloc(strlen(optarg)+1);
                        strcpy(optstr,optarg);
                        break;
                case 'l':
                        add_long_options(optarg);
                        break;
                case 'n':
                        if (name)
                                free(name);
                        name=xmalloc(strlen(optarg)+1);
                        strcpy(name,optarg);
                        break;
                case 'q':
                        quiet_errors=1;
                        break;
                case 'Q':
                        quiet_output=1;
                        break;
                case 's':
                        set_shell(optarg);
                        break;
                case 'T':
                        exit(4);
                case 'u':
                        quote=0;
                        break;
                default:
                        show_usage();
                }

        if (!optstr) {
                if (optind >= argc)
                        error_msg_and_die("missing optstring argument");
                else {
                        optstr=xmalloc(strlen(argv[optind])+1);
                        strcpy(optstr,argv[optind]);
                        optind++;
                }
        }
        if (name)
                argv[optind-1]=name;
        else
                argv[optind-1]=argv[0];
        exit(generate_output(argv+optind-1,argc-optind+1,optstr,long_options));
}
示例#22
0
int main(int argc, char **argv)
{
  int node_num;
  int grid_size = 10000;
  int degree_one = 0;
  int placement = 0;
  int expansion = 0;
  int seed = 0;
  int ch;
  int print_version = 0;
  float frac = 0.0;
 
  node_type *node;

  my_stderr = stderr;

  /**************************************/
  /* getopt the command line arguments */
  /**************************************/

  if (argc == 1)
  {
    usage();
    exit(-1);
  }

  while ((ch = getopt(argc, argv, "d:f:p:n:s:Vvh")) != -1)
  {
    switch (ch)
    {
      case 'd':
        frac = atof(optarg);
        break;
      case 'f':
        my_stderr = fopen(optarg, "w");
        if (!my_stderr)
        {
          fprintf(stderr, "unable to open \"%s\" to output debugging info!\n", optarg);
          exit(-1);
        }
        break;
      case 'p':
        grid_size = atoi(optarg);
        break;
      case 'n':
        node_num = atoi(optarg);
        break;
      case 's':
        seed = atoi(optarg) % 64;
        break;
      case 'V':
      case 'v':
        print_version = 1;
        break;
      case 'h':
      default:
        usage();
	exit(-1);
    }
  }
    
  if ( print_version )
  {
    printf("Inet %s\n", VERSION);
    exit(0);
  }
 
  //if ( node_num < 3037 )
  if ( node_num < 10 )
  {
    //fprintf(stderr, "Error! the number of nodes must be no less than 3037!\n");
    fprintf(stderr, "Error! the number of nodes must be no less than 10!\n");
    exit(-1);
  }

  /****************************************************/
  /* the default is computed by a linear relationship */
  /****************************************************/
  degree_one = (int)((float)node_num * frac);
    fprintf(stderr, "1 degree_one : %d\n", degree_one);
  if (degree_one == 0)
    degree_one = DEGREE_1_SLOPE * node_num + DEGREE_1_INTERCEPT;
 
    fprintf(stderr, "2 degree_one : %d\n", degree_one);
  /*******************************************/
  /* initializes the random number generator */
  /*******************************************/
  random_reset();  
  

  /*******************/
  /* allocate memory */
  /*******************/
  node = (node_type *)malloc(sizeof(node_type) * node_num);
  if (!node)
  {
    fprintf(stderr, "no enough memory for node array (%d bytes needed)!\n", sizeof(node_type) * node_num);
    exit(-1);
  }

  /*****************************/
  /* go ahead, make a topology */
  /*****************************/
  generate_degrees(node, node_num, degree_one, seed);
  place_nodes(node, node_num, grid_size, placement, seed);
  connect_nodes(node, node_num, seed);

  generate_output(node, node_num);

  if (my_stderr != stderr)
  {
    fclose(my_stderr);
  }
}
示例#23
0
文件: SFC_DBC.hpp 项目: sslattery/SFC
    /*! 
     * \brief DBC constructor.
     *
     * \param cond A string containing the assertion condition that failed.
     *
     * \param field A string containing the file name in which the assertion
     * failed. 
     *
     * \param line The line number at which the assertion failed.
     */
    Assertion( const std::string& cond, const std::string& file, 
	       const int line )
	: std::logic_error( generate_output( cond, file, line ) )
    { /* ... */ }
示例#24
0
 void run_performance_test()
 {
     time_algorithm();
     generate_output();
 }
示例#25
0
int getopt_main(int argc, char **argv)
{
    int n;
    char *optstr = NULL;
    char *name = NULL;
    unsigned opt;
    const char *compatible;
    char *s_arg;
#if ENABLE_FEATURE_GETOPT_LONG
    struct option *long_options = NULL;
    llist_t *l_arg = NULL;
#endif

    compatible = getenv("GETOPT_COMPATIBLE"); /* used as yes/no flag */

    if (!argv[1]) {
        if (compatible) {
            /* For some reason, the original getopt gave no error
               when there were no arguments. */
            printf(" --\n");
            return 0;
        }
        bb_error_msg_and_die("missing optstring argument");
    }

    if (argv[1][0] != '-' || compatible) {
        char *s = argv[1];

        option_mask32 |= OPT_u; /* quoting off */
        s = xstrdup(s + strspn(s, "-+"));
        argv[1] = argv[0];
        return generate_output(argv+1, argc-1, s, long_options);
    }

#if !ENABLE_FEATURE_GETOPT_LONG
    opt = getopt32(argv, "+o:n:qQs:Tu", &optstr, &name, &s_arg);
#else
    applet_long_options = getopt_longopts;
    opt_complementary = "l::";
    opt = getopt32(argv, "+o:n:qQs:Tual:",
                   &optstr, &name, &s_arg, &l_arg);
    /* Effectuate the read options for the applet itself */
    while (l_arg) {
        long_options = add_long_options(long_options, llist_pop(&l_arg));
    }
#endif

    if (opt & OPT_s) {
        set_shell(s_arg);
    }

    if (opt & OPT_T) {
        return 4;
    }

    /* All options controlling the applet have now been parsed */
    n = optind - 1;
    if (!optstr) {
        optstr = argv[++n];
        if (!optstr)
            bb_error_msg_and_die("missing optstring argument");
    }

    argv[n] = name ? name : argv[0];
    return generate_output(argv + n, argc - n, optstr, long_options);
}
示例#26
0
int main (int argc, char** argv)
{
  StackDescription_t stkd ;
  Analysis_t         analysis ;
  Output_t           output ;
  ThermalData_t      tdata ;

  Error_t error ;

  struct timespec t1,t2;
  struct timespec res;
  res.tv_sec=0;
  res.tv_nsec=0;
  Quantity_t server_port ;

  Socket_t server_socket, client_socket ;

  NetworkMessage_t request, reply , tmapReply;

  bool headers = false ;

    /* Checks if all arguments are there **************************************/

  if (argc != 3)
  {
    fprintf (stderr, "Usage: \"%s file.stk server_port\n", argv[0]) ;

    return EXIT_FAILURE ;
  }

  server_port = atoi (argv[2]) ;

  /* Parses stack file (fills stack descrition and analysis) ****************/

  fprintf (stdout, "Preparing stk data ... ") ; fflush (stdout) ;

  stack_description_init (&stkd) ;
  analysis_init          (&analysis) ;
  output_init            (&output) ;
  
    error = parse_stack_description_file (argv[1], &stkd, &analysis, &output) ;

  /* Initialise the compression related data ********************************/

  Quantity_t nflpel_ = get_total_number_of_floorplan_elements (&stkd) ;

  float hist_table_d[nflpel_][HIST_TABLE_SIZE];
  
  int tail_d[nflpel_];
  
  for (unsigned int i = 0; i < nflpel_; i++)
  {
    tail_d[i] = 0;
  
    for (int j = 0; j < HIST_TABLE_SIZE; j++)
      hist_table_d[i][j] = -1.0;
  }

  for(int i=0;i<MAXRES;i++)
    for(int j=0;j<MAXROWS;j++)
      for(int k=0;k<MAXCOLS;k++)
        for(int l=0;l<HIST_TABLE_SIZE;l++)
          histTableMap[i][j][k][l] = -1.0;
  int compressionUsed;



  if (error != TDICE_SUCCESS)    return EXIT_FAILURE ;

  if (analysis.AnalysisType != TDICE_ANALYSIS_TYPE_TRANSIENT)
  {
    fprintf (stderr, "only transient analysis!\n") ;

    goto wrong_analysis_error ;
  }

  fprintf (stdout, "done !\n") ;

  /* Prepares thermal data **************************************************/

  fprintf (stdout, "Preparing thermal data ... ") ; fflush (stdout) ;

  thermal_data_init (&tdata) ;

  error = thermal_data_build

    (&tdata, &stkd.StackElements, stkd.Dimensions, &analysis) ;


  if (error != TDICE_SUCCESS)    goto ftd_error ;

  fprintf (stdout, "done !\n") ;

  /* Creates socket *********************************************************/

  fprintf (stdout, "Creating socket ... ") ; fflush (stdout) ;

  socket_init (&server_socket) ;

  error = open_server_socket (&server_socket, server_port) ;



  if (error != TDICE_SUCCESS)    goto socket_error ;

  fprintf (stdout, "done !\n") ;

  /* Waits for a client to connect ******************************************/

  fprintf (stdout, "Waiting for client ... ") ; fflush (stdout) ;

  socket_init (&client_socket) ;

  error = wait_for_client (&server_socket, &client_socket) ;

  if (error != TDICE_SUCCESS)    goto wait_error ;

  fprintf (stdout, "done !\n") ;

  //float timeForTmap = 0.0;
  /* Runs the simlation *****************************************************/

  do
  {
    network_message_init (&request) ;

    receive_message_from_socket (&client_socket, &request) ;

    switch (*request.Type)
    {

      /**********************************************************************/
      case TDICE_COMPRESSION_USED :
        {
          extract_message_word (&request, &compressionUsed,0);
          break;
        }
      case TDICE_EXIT_SIMULATION :
        {
          network_message_destroy (&request) ;

          goto quit ;
        }

        /**********************************************************************/

      case TDICE_RESET_THERMAL_STATE :
        {
          reset_thermal_state (&tdata, &analysis) ;

          break ;
        }

        /**********************************************************************/

      case TDICE_TOTAL_NUMBER_OF_FLOORPLAN_ELEMENTS :
        {
          network_message_init (&reply) ;

          build_message_head   (&reply, TDICE_TOTAL_NUMBER_OF_FLOORPLAN_ELEMENTS) ;

          Quantity_t nflpel = get_total_number_of_floorplan_elements (&stkd) ;

          insert_message_word (&reply, &nflpel) ;

          send_message_to_socket (&client_socket, &reply) ;

          network_message_destroy (&reply) ;

          break ;
        }

        /**********************************************************************/

      case TDICE_INSERT_POWERS_AND_SIMULATE_SLOT :
        {
          Quantity_t nflpel, index ;

          PowersQueue_t queue ;

          powers_queue_init (&queue) ;

          extract_message_word (&request, &nflpel, 0) ;

          powers_queue_build (&queue, nflpel) ;
          if(compressionUsed)
          {
            unsigned int tmp[3];
            int ret=-1;
            unsigned int compressedWord;
            float power=0.0;
            int readIndex=1;
            index=1;
            initTmp(tmp);
            extract_message_word (&request, &compressedWord,readIndex);
            while(index<=nflpel)
            {
              ret=getNextDecompressedWord(compressedWord,tmp,0);
              switch(ret)
              {
                case WI_DC:
                case WC_DC: 
                  switch(tmp[0])
                  {
                    case 0:
                      power=(int)hist_table_d[index-1][tmp[1]]+(hist_table_d[index-1][tmp[2]]-(int)hist_table_d[index-1][tmp[2]]);
                      break; 
                    case 1:
                      power=tmp[1]+(hist_table_d[index-1][tmp[2]]-(int)hist_table_d[index-1][tmp[2]]);
                      hist_table_d[index-1][tail_d[index-1]]=power;
                      tail_d[index-1]=(tail_d[index-1]+1)%HIST_TABLE_SIZE;
                      break;
                    case 2:
                      power=(int)hist_table_d[index-1][tmp[1]]+((float)tmp[2])/(pow(10,DECIMAL_DIGITS));
                      hist_table_d[index-1][tail_d[index-1]]=power;
                      tail_d[index-1]=(tail_d[index-1]+1)%HIST_TABLE_SIZE;
                      break;
                    case 3:
                      power=tmp[1]+((float)tmp[2])/(pow(10,DECIMAL_DIGITS));
                      hist_table_d[index-1][tail_d[index-1]]=power;
                      tail_d[index-1]=(tail_d[index-1]+1)%HIST_TABLE_SIZE;
                      break;
                  }
                  put_into_powers_queue(&queue,power);
                  index++;
                  initTmp(tmp);
                  if(ret==WC_DC)
                  {
                    readIndex++;
                    extract_message_word (&request, &compressedWord,readIndex);
                  }
                  break;
                case WC_DI:
                  readIndex++;
                  extract_message_word (&request, &compressedWord,readIndex);
                  break;
                default:
                  break;
              }
            }
            ret=getNextDecompressedWord(compressedWord,tmp,1);
          }
          /* NO COMPRESSION *************************************/
          else 
          {
            for (index = 1, nflpel++ ; index != nflpel ; index++)
            {
              float power_value ;

              extract_message_word (&request, &power_value, index) ;

              put_into_powers_queue (&queue, power_value) ;
            }

          }
          error = insert_power_values (&tdata.PowerGrid, &queue) ;

          if (error != TDICE_SUCCESS)
          {
            fprintf (stderr, "error: insert power values\n") ;

            powers_queue_destroy (&queue) ;

            goto sim_error ;
          }

          powers_queue_destroy (&queue) ;

          network_message_init (&reply) ;
          build_message_head   (&reply, TDICE_INSERT_POWERS_AND_SIMULATE_SLOT) ;

          SimResult_t result = emulate_slot

            (&tdata, stkd.Dimensions, &analysis) ;

          insert_message_word (&reply, &result) ;

          send_message_to_socket (&client_socket, &reply) ;

          network_message_destroy (&reply) ;

          if (result != TDICE_SLOT_DONE)
          {
            fprintf (stderr, "error %d: emulate slot\n", result) ;

            goto sim_error ;
          }

          break ;
        }

        /**********************************************************************/

      case TDICE_SEND_OUTPUT :
        {
          OutputInstant_t  instant ;
          OutputType_t     type ;
          OutputQuantity_t quantity ;
          //clock_t Time;          

          extract_message_word (&request, &instant,  0) ;
          extract_message_word (&request, &type,     1) ;
          extract_message_word (&request, &quantity, 2) ;

          network_message_init (&reply) ;
          build_message_head   (&reply, TDICE_SEND_OUTPUT) ;

          float   time = get_simulated_time (&analysis) ;
          Quantity_t n = get_number_of_inspection_points (&output, instant, type, quantity) ;

          insert_message_word (&reply, &time) ;
          insert_message_word (&reply, &n) ;

          if (n > 0)
          {
            error = fill_output_message

              (&output, stkd.Dimensions,
               tdata.Temperatures, tdata.PowerGrid.Sources,
               instant, type, quantity, &reply) ;

            if (error != TDICE_SUCCESS)
            {
              fprintf (stderr, "error: generate message content\n") ;

              network_message_destroy (&reply) ;

              goto sim_error ;
            }
          }
          if(type == TDICE_OUTPUT_TYPE_TMAP && compressionUsed)
          {
            //init histTableMap tailMap for compression
            //New packet tmapReply is being initialised /
            //clock_gettime (CLOCK_PROCESS_CPUTIME_ID, &t1);
            network_message_init (&tmapReply);
            build_message_head (&tmapReply, TDICE_SEND_OUTPUT);

            insert_message_word (&tmapReply, &time);
            insert_message_word (&tmapReply, &n);

            CellIndex_t nrows, ncols;

            int readIndex = 4;

            //get the no of rows and cols from reply packet
            extract_message_word (&reply, &nrows, 2);
            extract_message_word (&reply, &ncols, 3);

            //insert nrows and ncols into my packet
            insert_message_word (&tmapReply, &nrows);
            insert_message_word (&tmapReply, &ncols);

            int ret=-1, f1, f2;
            unsigned int compressedWord, i, j, k, l;
            unsigned int flag=0, intPart, decPart;

            unsigned int tmp[3];
            float temper;

            for(i=0; i<n; i++)
              for(j=0; j<nrows; j++)
                for(k=0; k<ncols; k++)
                {
                  f1 = -1;f2 = -1;

                  extract_message_word (&reply, &temper, readIndex);
                  readIndex++;
                  unsigned int intPartTemper, decPartTemper;
                  getParts (temper, &intPartTemper, &decPartTemper);
                  for (l=0;l<HIST_TABLE_SIZE;l++)
                  {
                    if(histTableMap[i][j][k][l] != -1.0)
                    {
                      getParts (histTableMap[i][j][k][l], &intPart, &decPart);
                      if(intPart == intPartTemper)f1 = l;
                      float val=((float)decPart-decPartTemper);
                      val=val/(float)pow(10,DECIMAL_DIGITS);
                      val=abs (val);
                      if(val <= TOLERANCE)
                        f2=l;
                    }
                  }
                  flag = getFlag (f1,f2);

                  switch (flag)
                  {
                    case 1:
                      histTableMap[i][j][k][tailMap[i][j][k]] = intPartTemper + 
                        (histTableMap[i][j][k][f2] - (int)histTableMap[i][j][k][f2]);
                      tailMap[i][j][k] = (tailMap[i][j][k] + 1)%HIST_TABLE_SIZE;
                      break;

                    case 2:
                      histTableMap[i][j][k][tailMap[i][j][k]] = (int)histTableMap[i][j][k][f1] + 
                        ((float)decPartTemper)/(pow(10,DECIMAL_DIGITS));
                      tailMap[i][j][k] = (tailMap[i][j][k] + 1)%HIST_TABLE_SIZE;
                      break;

                    case 3:
                      histTableMap[i][j][k][tailMap[i][j][k]] = intPartTemper + 
                        ((float)decPartTemper)/(pow(10,DECIMAL_DIGITS));
                      tailMap[i][j][k] = (tailMap[i][j][k] + 1)%HIST_TABLE_SIZE;
                      break;

                    default:
                      break;
                  }
                  getArgsInArray (f1, f2, flag, intPartTemper, decPartTemper, tmp);
                  ret = getNextCompressedWord (tmp[1], tmp[2], flag, &compressedWord, !WRAP_UP);
                  if(ret != WORD_INCOMPLETE)
                    insert_message_word (&tmapReply, &compressedWord);
                }
            switch(ret)
            {
              case WORD_INCOMPLETE:
              case WORD_IN_TEMP:
                getNextCompressedWord (tmp[1], tmp[2], flag, &compressedWord, WRAP_UP);
                insert_message_word (&tmapReply, &compressedWord);
                break;
              default:
                break;
            }
            clock_gettime (CLOCK_PROCESS_CPUTIME_ID, &t1);
            send_message_to_socket (&client_socket, &tmapReply);
            clock_gettime (CLOCK_PROCESS_CPUTIME_ID, &t2);
            diff(t1,t2,&res); 
            network_message_destroy (&reply);
            network_message_destroy (&tmapReply);
          }
          else
          {
            if(type == TDICE_OUTPUT_TYPE_TMAP)
            {
            //Time = clock();            
            clock_gettime (CLOCK_PROCESS_CPUTIME_ID, &t1);
            send_message_to_socket (&client_socket, &reply);
            //timeForTmap +=  ((double)clock() - Time) / CLOCKS_PER_SEC  ;
            clock_gettime (CLOCK_PROCESS_CPUTIME_ID, &t2);
            diff(t1,t2,&res); 
            }
            else
            send_message_to_socket (&client_socket, &reply) ;

            network_message_destroy (&reply) ;
          }
          break ;
        }

        /**********************************************************************/

      case TDICE_PRINT_OUTPUT :
        {
          OutputInstant_t  instant ;

          extract_message_word (&request, &instant,  0) ;

          if (headers == false)
          {
            Error_t error = generate_output_headers

              (&output, stkd.Dimensions, (String_t)"% ") ;

            if (error != TDICE_SUCCESS)
            {
              fprintf (stderr, "error in initializing output files \n ");

              goto sim_error ;
            }

            headers = true ;
          }

          generate_output

            (&output, stkd.Dimensions,
             tdata.Temperatures, tdata.PowerGrid.Sources,
             get_simulated_time (&analysis), instant) ;

          break ;
        }

        /**********************************************************************/

      case TDICE_SIMULATE_SLOT :
        {
          network_message_init (&reply) ;
          build_message_head   (&reply, TDICE_SIMULATE_SLOT) ;

          SimResult_t result = emulate_slot (&tdata, stkd.Dimensions, &analysis) ;

          insert_message_word (&reply, &result) ;

          send_message_to_socket (&client_socket, &reply) ;

          network_message_destroy (&reply) ;

          if (result == TDICE_END_OF_SIMULATION)
          {
            network_message_destroy (&request) ;

            goto quit ;
          }
          else if (result != TDICE_SLOT_DONE)
          {
            fprintf (stderr, "error %d: emulate slot\n", result) ;

            goto sim_error ;
          }

          break ;
        }

        /**********************************************************************/

      case TDICE_SIMULATE_STEP :
        {
          network_message_init (&reply) ;
          build_message_head   (&reply, TDICE_SIMULATE_STEP) ;

          SimResult_t result = emulate_step (&tdata, stkd.Dimensions, &analysis) ;

          insert_message_word (&reply, &result) ;

          send_message_to_socket (&client_socket, &reply) ;

          network_message_destroy (&reply) ;

          if (result == TDICE_END_OF_SIMULATION)
          {
            network_message_destroy (&request) ;

            goto quit ;
          }
          else if (result != TDICE_STEP_DONE && result != TDICE_SLOT_DONE)
          {
            fprintf (stderr, "error %d: emulate step\n", result) ;

            goto sim_error ;
          }

          break ;
        }

        /**********************************************************************/

      default :

        fprintf (stderr, "ERROR :: received unknown message type") ;
    }

    network_message_destroy (&request) ;

  } while (1) ;

  /**************************************************************************/

quit :

  socket_close              (&client_socket) ;
  socket_close              (&server_socket) ;
  thermal_data_destroy      (&tdata) ;
  stack_description_destroy (&stkd) ;
  output_destroy            (&output) ;

  printf("Time taken %d sec %d nsec \n",(int)res.tv_sec,(int)res.tv_nsec);
  return EXIT_SUCCESS ;

sim_error :
  network_message_destroy   (&request) ;
  socket_close              (&client_socket) ;
wait_error :
  socket_close              (&server_socket) ;
socket_error :
  thermal_data_destroy      (&tdata) ;
ftd_error :
wrong_analysis_error :
  stack_description_destroy (&stkd) ;
  output_destroy            (&output) ;

  return EXIT_FAILURE ;
}