static void DNAT_print(const void *ip, const struct xt_entry_target *target,
                       int numeric)
{
	const struct ipt_natinfo *info = (const void *)target;
	unsigned int i = 0;

	printf("to:");
	for (i = 0; i < info->mr.rangesize; i++) {
		print_range(&info->mr.range[i]);
		printf(" ");
		if (info->mr.range[i].flags & IP_NAT_RANGE_PROTO_RANDOM)
			printf("random ");
		if (info->mr.range[i].flags & IP_NAT_RANGE_PERSISTENT)
			printf("persistent ");
	}
}
Exemplo n.º 2
0
static void
print_range_type (struct type *raw_type, struct ui_file *stream)
{
    const char *name;
    struct type *base_type;
    const char *subtype_info;

    gdb_assert (raw_type != NULL);
    name = TYPE_NAME (raw_type);
    gdb_assert (name != NULL);

    if (TYPE_CODE (raw_type) == TYPE_CODE_RANGE)
        base_type = TYPE_TARGET_TYPE (raw_type);
    else
        base_type = raw_type;

    subtype_info = strstr (name, "___XD");
    if (subtype_info == NULL)
        print_range (raw_type, stream);
    else
    {
        int prefix_len = subtype_info - name;
        char *bounds_str;
        int n;

        subtype_info += 5;
        bounds_str = strchr (subtype_info, '_');
        n = 1;

        if (*subtype_info == 'L')
        {
            print_range_bound (base_type, bounds_str, &n, stream);
            subtype_info += 1;
        }
        else
            print_dynamic_range_bound (base_type, name, prefix_len, "___L",
                                       stream);

        fprintf_filtered (stream, " .. ");

        if (*subtype_info == 'U')
            print_range_bound (base_type, bounds_str, &n, stream);
        else
            print_dynamic_range_bound (base_type, name, prefix_len, "___U",
                                       stream);
    }
}
Exemplo n.º 3
0
/* Print the range type named NAME: */
static void
print_range_type_named(char *name, struct ui_file *stream)
{
  struct type *raw_type = ada_find_any_type(name);
  struct type *base_type;
  char *subtype_info;

  if (raw_type == NULL)
    base_type = builtin_type_int;
  else if (TYPE_CODE (raw_type) == TYPE_CODE_RANGE)
    base_type = TYPE_TARGET_TYPE (raw_type);
  else
    base_type = raw_type;

  subtype_info = strstr (name, "___XD");
  if (subtype_info == NULL && raw_type == NULL)
    fprintf_filtered (stream, "? .. ?");
  else if (subtype_info == NULL)
    print_range (raw_type, stream);
  else
    {
      int prefix_len = subtype_info - name;
      char *bounds_str;
      int n;

      subtype_info += 5;
      bounds_str = strchr (subtype_info, '_');
      n = 1;

      if (*subtype_info == 'L')
	{
	  print_range_bound (base_type, bounds_str, &n, stream);
	  subtype_info += 1;
	}
      else
	print_dynamic_range_bound (base_type, name, prefix_len, "___L",
				   stream);

      fprintf_filtered (stream, " .. ");

      if (*subtype_info == 'U')
	print_range_bound (base_type, bounds_str, &n, stream);
      else
	print_dynamic_range_bound (base_type, name, prefix_len, "___U",
				   stream);
    }
}
Exemplo n.º 4
0
IpRange* find_range_for_ip(IPDB *db, char *ip) {
  IpRange* search;
  IpRange* result;
  search = (IpRange *)malloc(sizeof(IpRange));

  if(db == NULL)
  {
    printf("ERROR: DB ist NULL! ");
    return NULL;
  }

  if(db->ranges_count == 0)
  {
    printf("ERROR: DB has no Ranges Data. Can not search!\n");
    return NULL;
  }

  search->from = ip_to_int(ip);
  search->to=0;
  search->city_index = 0;
  if(DEBUG)
    printf("Searching for: ip=%s, ipnum=%lu \n", ip, search->from);
  result = (IpRange*)bsearch(search, db->ranges, db->ranges_count, sizeof(IpRange), compare_ranges);
  if(search != NULL)
    free(search);

  if(result == NULL)
  {
    if(DEBUG)
      printf("ERROR: Could not find the IP: %s! THIS SHOULD NOT HAPPEN!\n", ip);
    return NULL;
  } else {
    if(DEBUG) {
      printf("Found Range: \t");
      print_range(result);
    }
    return (IpRange*)result;
  }
}
Exemplo n.º 5
0
 std::ostream& operator<<(std::ostream& out, const std::set<T>& s) {
   return print_range(out, s, "{", ", ", "}");
 }
Exemplo n.º 6
0
static void list_desc (ext2_filsys fs)
{
	unsigned long i;
	blk_t	first_block, last_block;
	blk_t	super_blk, old_desc_blk, new_desc_blk;
	char *block_bitmap=NULL, *inode_bitmap=NULL;
	int inode_blocks_per_group, old_desc_blocks, reserved_gdt;
	int		block_nbytes, inode_nbytes;
	int has_super;
	blk_t		blk_itr = fs->super->s_first_data_block;
	ext2_ino_t	ino_itr = 1;

	block_nbytes = EXT2_BLOCKS_PER_GROUP(fs->super) / 8;
	inode_nbytes = EXT2_INODES_PER_GROUP(fs->super) / 8;

	if (fs->block_map)
		block_bitmap = malloc(block_nbytes);
	if (fs->inode_map)
		inode_bitmap = malloc(inode_nbytes);

	inode_blocks_per_group = ((fs->super->s_inodes_per_group *
				   EXT2_INODE_SIZE(fs->super)) +
				  EXT2_BLOCK_SIZE(fs->super) - 1) /
				 EXT2_BLOCK_SIZE(fs->super);
	reserved_gdt = fs->super->s_reserved_gdt_blocks;
	fputc('\n', stdout);
	first_block = fs->super->s_first_data_block;
	if (fs->super->s_feature_incompat & EXT2_FEATURE_INCOMPAT_META_BG)
		old_desc_blocks = fs->super->s_first_meta_bg;
	else
		old_desc_blocks = fs->desc_blocks;
	for (i = 0; i < fs->group_desc_count; i++) {
		first_block = ext2fs_group_first_block(fs, i);
		last_block = ext2fs_group_last_block(fs, i);

		ext2fs_super_and_bgd_loc(fs, i, &super_blk,
					 &old_desc_blk, &new_desc_blk, 0);

		printf (_("Group %lu: (Blocks "), i);
		print_range(first_block, last_block);
		fputs(")", stdout);
		print_bg_opts(fs, i);
		if (fs->super->s_feature_ro_compat & EXT4_FEATURE_RO_COMPAT_GDT_CSUM)
			printf(_("  Checksum 0x%04x, unused inodes %d\n"),
			       fs->group_desc[i].bg_checksum,
			       fs->group_desc[i].bg_itable_unused);
		has_super = ((i==0) || super_blk);
		if (has_super) {
			printf (_("  %s superblock at "),
				i == 0 ? _("Primary") : _("Backup"));
			print_number(super_blk);
		}
		if (old_desc_blk) {
			printf(_(", Group descriptors at "));
			print_range(old_desc_blk,
				    old_desc_blk + old_desc_blocks - 1);
			if (reserved_gdt) {
				printf(_("\n  Reserved GDT blocks at "));
				print_range(old_desc_blk + old_desc_blocks,
					    old_desc_blk + old_desc_blocks +
					    reserved_gdt - 1);
			}
		} else if (new_desc_blk) {
			fputc(has_super ? ',' : ' ', stdout);
			printf(_(" Group descriptor at "));
			print_number(new_desc_blk);
			has_super++;
		}
		if (has_super)
			fputc('\n', stdout);
		fputs(_("  Block bitmap at "), stdout);
		print_number(fs->group_desc[i].bg_block_bitmap);
		print_bg_rel_offset(fs, fs->group_desc[i].bg_block_bitmap, 0,
				    first_block, last_block);

		fputs(_(", Inode bitmap at "), stdout);
		print_number(fs->group_desc[i].bg_inode_bitmap);
		print_bg_rel_offset(fs, fs->group_desc[i].bg_inode_bitmap, 0,
				    first_block, last_block);

		fputs(_("\n  Inode table at "), stdout);
		print_range(fs->group_desc[i].bg_inode_table,
			    fs->group_desc[i].bg_inode_table +
			    inode_blocks_per_group - 1);
		print_bg_rel_offset(fs, fs->group_desc[i].bg_inode_table, 1,
				    first_block, last_block);

		printf (_("\n  %u free blocks, %u free inodes, "
			  "%u directories%s"),
			fs->group_desc[i].bg_free_blocks_count,
			fs->group_desc[i].bg_free_inodes_count,
			fs->group_desc[i].bg_used_dirs_count,
			fs->group_desc[i].bg_itable_unused ? "" : "\n");
		if (fs->group_desc[i].bg_itable_unused)
			printf (_(", %u unused inodes\n"),
				fs->group_desc[i].bg_itable_unused);
		if (block_bitmap) {
			fputs(_("  Free blocks: "), stdout);
			ext2fs_get_block_bitmap_range(fs->block_map,
				 blk_itr, block_nbytes << 3, block_bitmap);
			print_free (i, block_bitmap,
				    fs->super->s_blocks_per_group,
				    fs->super->s_first_data_block);
			fputc('\n', stdout);
			blk_itr += fs->super->s_blocks_per_group;
		}
		if (inode_bitmap) {
			fputs(_("  Free inodes: "), stdout);
			ext2fs_get_inode_bitmap_range(fs->inode_map,
				 ino_itr, inode_nbytes << 3, inode_bitmap);
			print_free (i, inode_bitmap,
				    fs->super->s_inodes_per_group, 1);
			fputc('\n', stdout);
			ino_itr += fs->super->s_inodes_per_group;
		}
	}
	if (block_bitmap)
		free(block_bitmap);
	if (inode_bitmap)
		free(inode_bitmap);
}
Exemplo n.º 7
0
int main (int argc, char **argv)
{
        char *pattern;
        char *file;
	FileReader *reader = NULL;
	PatternSearch *search = NULL;
        bool success;
        AppArgument arguments[] = {
                ARGUMENT_ORDINAL_STRING (NULL, true, &pattern, "Pattern."),
                ARGUMENT_ORDINAL_STRING (NULL, true, &file, "File."),
                ARGUMENT_DEFAULT,
                ARGUMENT_END
        };
        
        if (!app_arguments (argc, argv, arguments)) {
                app_arguments_usage (argc, argv, arguments);
                return EXIT_FAILURE;
        }
        success = try (&reader, &search, pattern, file);
        if (reader) {
                file_reader_destroy (reader);
        }
        if (search) {
                pattern_search_destroy (search);
        }
        if (!success || error_count () != 0) {
                return EXIT_FAILURE;
        }
	return EXIT_SUCCESS;
}

static bool try (FileReader **reader, PatternSearch **search, const char *pattern, const char *file)
{
        size_t from, to;

        if (!(*reader = file_reader_create (file))) {
		error_code (FunctionCall, 1);
		return false;
	}
	if (!(*search = pattern_search_create ((*reader)->map, (size_t)(*reader)->size, pattern, false))) {
                error_code (FunctionCall, 2);
		return false;
	}
	while (pattern_search_next (*search, &from, &to)) {
                if (!print_range ((const char *)(*reader)->map, from, to)) {
                        error_code (FunctionCall, 3);
                        return false;
                }
                if (putc ((int)'\n', stdout) == EOF) {
                        error (SystemCall);
                        return false;
                }
	}
	return true;
}

static bool print_range (const char *buffer, size_t from, size_t to)
{
        if (to - from == 0) {
                return true;
        }
        if (fwrite (buffer + from, 1, to - from, stdout) != to - from) {
                error (SystemCall);
                return false;
        }
        return true;
}
Exemplo n.º 8
0
int main() {
  auto ints = {0, 1, 2, 3, 4, 5, 6};
  print_range(ints);
  return 0;
}
Exemplo n.º 9
0
int print_pages(void)
{
    return print_range(1, N);
}
Exemplo n.º 10
0
/*
 * expand: given an input string specifiying ranges of digits and letters
 * 	expand it into the full string and store the result in output. leading and trailing '-' are treated
 * 	literally.
 * 	for example:
 * 	a-z will give abc...xyz
 * 	0-9 will give 012...789
 * 	-a-d- will give -abcd-
 * 	-a-d7-9 will give -abcd789
 * 	etc.
 */
void expand(char input[], char output[]) {
    int digit_range = 0, letter_range = 0;
    int start = 0, end = 0;
    int length;
    int index = 0;
    
    length = string_length(input);
    while (index < length) {
        int current_char = input[index];
        if (!digit_range && !letter_range) { // not in a range
            if (current_char == '-') {
                printf("-");
                ++index;
            } else if (is_alphabetic(current_char)) { // start of a letter range
                letter_range = 1;
                start = current_char;
                end = start;
            } else if (is_digit(current_char)) { // start of a digit range
                digit_range = 1;
                start = current_char;
                end = start;
            } else {
                printf("Error in input!");
                break;
            }
        } else if (letter_range && !digit_range) {
            // Depending on the input there are now several cases while being in a letter range
            // (a) the next char is a '-' and immediately following is a letter:
            //      this is just a vanilla range, so we update the end value of the range
            // (b) the next char is a '-' and immediately following is a digit:
            //      in this case we complete the existing range and signal that we are not
            //      in a letter_range anymore
            // (c) the next char is alphabetic
            //      just expand the range-so-far and set the start point to next char
            // (d) the next char is a digit
            //      end of the letter range-so-far -> expand range and indicate end of letter_range
            // (e) the last char is a '-'
            //      put the value in 'start' into output and indicate end of letter_range
            // (f) still in a letter range and at the end of the string
            //      just expand the current range
            if (index < (length - 2)) { // we still have at least 2 chars to examine
                // cases (a), (b), (c), (d)
                int next = input[index + 1];
                int next_next = input[index + 2];
                if (next == '-' && is_alphabetic(next_next)) {
                    // (a)
                    if (next_next > end) {
                    end = next_next;
                    }
                    index += 2;
                } else if (next == '-' && is_digit(next_next)) {
                    // (b)
                    print_range(start, end);
                    letter_range = 0;
                    ++index;
                } else if (is_alphabetic(next)) {
                    // (c)
                    print_range(start, end);
                    start = next;
                    end = start;
                    ++index;
                } else if (is_digit(next)) {
                    // (d)
                    print_range(start, end);
                    letter_range = 0;
                    ++index;
                }
            } else if (index < length - 1) {    // there is at least 1 char remaining
                // (e)
                int next = input[index + 1];
                if (next == '-') {
                    print_range(start, end);
                    letter_range = 0;
                    ++index;
                }
            } else {    // we are at the end of the string
                // (f)
                print_range(start, end);
                break;
            }
        } else if (digit_range) { // we are in a digit range now
            // Look above for the reasoning behind the cases - apply them analogously
            if (index < (length - 2)) {
                // cases (a), (b), (c), (d)
                int next = input[index + 1];
                int next_next = input[index + 2];
                if (next == '-' && is_digit(next_next)) {
                    // (a)
                    if (next_next > end) {
                    end = next_next;
                    }
                    index += 2;
                } else if (next == '-' && is_alphabetic(next_next)) {
                    // (b)
                    print_range(start, end);
                    digit_range = 0;
                    ++index;
                } else if (is_digit(next)) {
                    // (c)
                    print_range(start, end);
                    start = next;
                    end = start;
                    ++index;
                } else if (is_alphabetic(next)) {
                    // (d)
                    print_range(start, end);
                    digit_range = 0;
                    ++index;
                }
            } else if (index < length - 1) {    // there is at least 1 char remaining
                // (e)
                int next = input[index + 1];
                if (next == '-') {
                    print_range(start, end);
                    letter_range = 0;
                    ++index;
                }
            } else {    // we are at the end of the string
                // (f)
                print_range(start, end);
                break;
            }
        }
    }	
}
Exemplo n.º 11
0
void Garnet::Drivers::executeTrees(StringMap& args)
{
	Garnet::Configuration conf;

    //-----------------------------------------------------
	// Determine project location and name.
    //-----------------------------------------------------
	resolveProjectInformation(args, &conf);

    //-----------------------------------------------------
	// 0. Load arguments
    //-----------------------------------------------------
	std::string infilename;
	{
		// Load from configuration file.
		std::ifstream fin;
        fin.open(conf.prj.c_str());
	    if ( fin.fail() ) {
		    throw std::string("[" __FUNCTION__ "] E2: Failed to open a project file '") + conf.prj + "'.";
	    }
        conf.load(fin, 0);
	}
	if ( args.find("_Input") != args.end() ) {
		infilename = args["_Input"];
	}

	// Override if parameters are specified by command line agruments.
	if ( args.find("_RandomSeed") != args.end() ) {
		conf.randomSeed = strtoul(args["_RandomSeed"].c_str(), 0, 0);
	}
	if ( args.find("_SizeX") != args.end() ) {
		conf.imageWidth = strtol(args["_SizeX"].c_str(), 0, 0);
	}
	if ( args.find("_SizeY") != args.end() ) {
		conf.imageHeight = strtol(args["_SizeY"].c_str(), 0, 0);
	}
	if ( args.find("_Dictionaries") != args.end() ) {
		strings dics = Text::split(args["_Dictionaries"], ';');
		for (auto it = dics.begin(); it != dics.end(); it++) {
			std::ifstream fin;
			fin.open(it->c_str());
			if ( fin.fail() ) {
				throw std::string("[" __FUNCTION__ "] E2: Failed to open an alias dictionary file '") + *it + "'.";
			}
			conf.load(fin, 0);
		}
	}
	{
		conf.numThreads.clear();
		conf.numThreads.push_back(1);
	}
	{
		std::cout << boost::format("Image size: %d x %d\n") % conf.imageWidth % conf.imageHeight << std::endl;
		std::cout << "----- ----- ----- -----" << std::endl;
	}

    //-----------------------------------------------------
	// 1. Create GA Engine
    //-----------------------------------------------------
    Garnet::GPEnginePtr  ga;
	{
		std::ofstream ftrace("trace.------.txt");
		setTraceStream(&ftrace);

		ga = Garnet::GPEngine::create(conf);
		if ( !ga ) {
			throw "Invalid GA Engine Type.";
		}

		setTraceStream(0);
		ftrace.close();
	}

    //-----------------------------------------------------
    // 2. Prepare trees as a generation.
    //-----------------------------------------------------
	Garnet::Generation generation;

	if ( !infilename.empty() ) {
		std::ifstream fin(infilename.c_str());
		generation = Generation::createFromFile(fin);
	}
	else {
		std::vector<std::string> treeExps;
		treeExps = Text::split(args["_Trees"], ';');

		for (auto it = treeExps.cbegin(); it != treeExps.cend(); it++) {
			Individual ind;
			ind.chromosome.push_back(Tree(*it));
			generation.individuals.push_back(ind);
		}
	}

    //-----------------------------------------------------
    // 3. Evaluate.
    //-----------------------------------------------------
    ga->evaluate(generation);

    //-----------------------------------------------------
	// 4. Show result.
    //-----------------------------------------------------
	// 4.1 Show numbers.
	if ( args.find("_Number") != args.end() ) {
		std::cout << "\nResults:";
		for (auto i = 0u; i < generation.individuals.size(); i++) {
			std::cout << "\n  Tree " << i << " " << print_range(
				generation.individuals[i].fitness.cbegin(), 
				generation.individuals[i].fitness.cend(), 
				", ",
				double_digit_putter(9, 6));
		}
		std::cout << "\n----- ----- ----- -----" << std::endl;
	}

	// 4.2 Save tree images.
	if ( args.find("_TreeImage") != args.end() ) {
		std::vector<size_t> targets;
		targets.push_back(0);

		std::cout << "\nSave Tree Images.";
		ga->saveLastImages("", generation.individuals, targets);
		std::cout << "\n----- ----- ----- -----" << std::endl;
	}

	// 4.2 Display images.
#if 0
	if ( args.find("_Window") != args.end() ) {
		for (auto i = 0u; i < generation.individuals.size(); i++) {
			for (auto f = 0u; f < generation.individuals[i].fitness.size(); f++) {
				std::string key = (boost::format("Tree#%d, Fitness#%d") % i).str();
				cv::namedWindow(key, CV_WINDOW_AUTOSIZE);
				cv::imshow(key, ga->saveLastImages());
			}
		}
		cv::waitKey();
		std::cout << "----- ----- ----- -----" << std::endl;
	}

	// A. Show information.
	{
		std::cout << boost::format("[%s] Trees to IVGraph    %.6fs\n") % __FUNCTION__ % watches[0].get();
		std::cout << boost::format("[%s] IVGraph to PPEGraph %.6fs\n") % __FUNCTION__ % watches[1].get();
		std::cout << boost::format("[%s] PPEGraph to Script  %.6fs\n") % __FUNCTION__ % watches[2].get();
		std::cout << boost::format("[%s] Compilation         %.6fs\n") % __FUNCTION__ % watches[3].get();
		std::cout << boost::format("[%s] Execution           %.6fs\n") % __FUNCTION__ % watches[4].get();
		std::cout << boost::format("[%s] Number of Operators %.6u\n") % __FUNCTION__ % executable->getNumberOfOperators();
		std::cout << boost::format("[%s] Number of Data      %.6u\n") % __FUNCTION__ % executable->getNumberOfData();
		std::cout << std::flush;
	}
#endif
}
Exemplo n.º 12
0
static void
print_virt_range(void)
{
    ofmem_t *ofmem = ofmem_arch_get_private();
    print_range( ofmem->virt_range, "virt" );
}
Exemplo n.º 13
0
static void
print_phys_range(void)
{
    ofmem_t *ofmem = ofmem_arch_get_private();
    print_range( ofmem->phys_range, "phys" );
}
Exemplo n.º 14
0
void
karatsuba_rec (unit_vec_type & dest,
    const_iterator const a_begin, const_iterator const a_end,
    const_iterator const b_begin, const_iterator const b_end)
{
    std::cout << "karatsuba_rec(" << print_range (a_begin, a_end) << ", "
        << print_range (b_begin, b_end) << ")" << std::endl;

    unsigned const a_size = a_end - a_begin;
    unsigned const b_size = b_end - b_begin;

    std::cout << "a_size: " << a_size << "  b_size: " << b_size << std::endl;

    if (a_size == 1 && *a_begin == 0
        || b_size == 1 && *b_begin == 0)
    {
        dest = zero_value;
        std::cout << "dest: " << print_vec (dest) << std::endl;
        return;
    }
    else if (a_size == 1 && b_size == 1)
    {
        accum_type prod = static_cast<accum_type>(*a_begin) * *b_begin;
        dest[0] = static_cast<unit_type>(prod % modulus);

        unit_type high = static_cast<unit_type>(prod / modulus);
        if (high != 0)
        {
            dest.resize (2);
            dest[1] = high;
        }

        remove_leading_zeroes (dest);

        std::cout << "dest: " << print_vec (dest) << std::endl;
        return;
    }

    unsigned split_size;
    if (a_size > b_size && b_size != 1)
        split_size = b_size / 2;
    else
        split_size = a_size / 2;

    std::cout << "split_size: " << split_size << std::endl;

    const_iterator const & a0_begin = a_begin;
    const_iterator const a1_begin = a_begin + split_size;
    const_iterator const a0_end = a1_begin;
    const_iterator const & a1_end = a_end;
    unsigned a0_size = a0_end - a0_begin;
    unsigned a1_size = a1_end - a1_begin;

    const_iterator const & b0_begin = b_begin;
    const_iterator const b1_begin = b_begin + split_size;
    const_iterator const b0_end = b1_begin;
    const_iterator const & b1_end = b_end;
    unsigned b0_size = b0_end - b0_begin;
    unsigned b1_size = b1_end - b1_begin;

    // z2 = x1 * y1
    unit_vec_type z2 (zero_value);
    if (a1_size != 0 && b1_size != 0)
        karatsuba_rec (z2, a1_begin, a1_end, b1_begin, b1_end);

    // z0 = x0 * y0
    unit_vec_type z0 (zero_value);
    if (a0_size != 0 && b1_size != 0)
        karatsuba_rec (z0, a0_begin, a0_end, b0_begin, b0_end);
    
    // z1 = (x1 + x0)(y1 + y0) - (z2 + z0)
    unit_vec_type z1, a01_sum, b01_sum, z02_sum;

    resize_for_add (a01_sum, a0_begin, a0_end, a1_begin, a1_end);
    add (a01_sum, a0_begin, a0_end, a1_begin, a1_end);
    
    resize_for_add (b01_sum, b0_begin, b0_end, b1_begin, b1_end);
    add (b01_sum, b0_begin, b0_end, b1_begin, b1_end);

    add (z02_sum, z0, z2);
    
    unit_vec_type z1_ab_prod;
    resize_for_mul (z1_ab_prod, a01_sum.begin (), a01_sum.end (),
        b01_sum.begin (), b01_sum.end ());
    karatsuba_rec (z1_ab_prod, a01_sum.begin (), a01_sum.end (),
        b01_sum.begin (), b01_sum.end ());

    sub (z1, z1_ab_prod, z02_sum);

    modulus_power (z2, split_size * 2);
    modulus_power (z1, split_size);
    
    dest = zero_value;
    add (dest, dest, z2);
    add (dest, dest, z1);
    add (dest, dest, z0);

    std::cout << "dest: " << print_vec (dest) << std::endl;
}
Exemplo n.º 15
0
void Garnet::Configuration::save(std::ostream& fout) const
{
    // Common
    fout << "ImageWidth               " << imageWidth;
    fout << "\nImageHeight              " << imageHeight;
    fout << "\n";

    // Control
    fout << "\nReportInterval           " << reportInterval;
    fout << "\nReportWhenImproved       " << reportWhenImproved;
    fout << "\nReportTimeInterval       " << reportTimeInterval;
    fout << "\nImageSavingInterval      " << imageSavingInterval;
    fout << "\nDebug                    " << debug;
    fout << "\nTrace                    " << trace;
    fout << "\nNumThreads               " << print_range(numThreads.begin(), numThreads.end(), ", ");
    fout << "\nCPUAffinity              " << print_range(cpuAffinity.begin(), cpuAffinity.end(), ", ");
    fout << "\nEnableOpenCL             " << enableOpenCL;
    fout << "\nNumVerticesLimit         " << numVerticesLimit;
    fout << "\nMaxInitialDepth          " << maxInitialDepth;
    fout << "\nMinInitialSize           " << minInitialSize;
    fout << "\nGroupingMethod           " << groupingMethod;
    fout << "\nShouldRemoveIntrons      " << shouldRemoveIntrons;
    fout << "\nTopologicalSortMethod    " << topologicalSortMethod;
    fout << "\n";

	// GP Framework
	if (!engine.empty()) fout << "\nEngine                   " << engine;
	if (!initializationMethod.empty()) fout << "\nInitializationMethod     " << initializationMethod;
	if (!evaluationMethod.empty()) fout << "\nEvaluationMethod         " << evaluationMethod;
	if (!sortingMethod.empty()) fout << "\nSortingMethod            " << sortingMethod;
	if (!selectionMethod.empty()) fout << "\nSelectionMethod          " << selectionMethod;
	if (!terminationMethod.empty()) fout << "\nTerminationMethod        " << terminationMethod;
	if (!pairMakingMethod.empty()) fout << "\nPairMakingMethod         " << pairMakingMethod;
	if (!crossoverMethod.empty()) fout << "\nCrossoverMethod          " << crossoverMethod;
	if (!mutationMethod.empty()) fout << "\nMutationMethod           " << mutationMethod;

    // GA Parameters
    fout << "\nEvaluator                " << print_range(evaluator.begin(), evaluator.end(), ",");
	fout << "\nFitness                  " << print_range(fitness.begin(), fitness.end(), ", ");
    fout << "\nMaxGeneration            " << maxGeneration;
    fout << "\nPopulationSize           " << populationSize;
    fout << "\nPreserveElite            " << preserveElite;
    fout << "\nCrossoverRate            " << std::setprecision(16) << crossoverRate;
    fout << "\nMutationRate             " << std::setprecision(16) << mutationRate;
    fout << "\nRandomSeed               " << randomSeed;
    fout << "\nRandomAlgorithm          " << randomAlgorithm;
    fout << "\nNumChromosomes           " << numChromosomes;
    fout << "\nFilterCountPenaltyWeight " << std::setprecision(16) << filterCountPenaltyWeight;
    fout << "\n";

    // Evaluators
    fout << "\nScoringMethod            " << scoringMethod;
    fout << "\nSimpleComparator         " << simpleComparator;
    fout << "\n";

    // Evaluators
	std::vector<int> keys = units.getKeys();
	if ( keys.size() == 1 ) {
		for (auto it = units[0].begin(); it != units[0].end(); it++) {
			fout << "Unit  " << *it << "\n";
		}
	}
	else {
		for (auto jt = keys.begin(); jt != keys.end(); jt++) {
			for (auto it = units[*jt].begin(); it != units[*jt].end(); it++) {
				fout << "UnitM  " << *jt << ", " << *it << "\n";
			}
		}
	}
    for (StringMap::const_iterator it = aliases.begin(); it != aliases.end(); it++) {
        fout << "Alias " << it->first << ", " << it->second << "\n";
    }
    fout << "\n";

    // Tasks and Tests
	auto saveTask = [] (std::ostream& os, const std::string& type, TaskList::const_iterator& first, TaskList::const_iterator& last) {
		for (auto it = first; it != last; it++) {
			const Task& task = *it;
			os << type << " " << std::setprecision(16) << task.a 
				 << ", " << std::setprecision(16) << task.b;
			for (std::vector<std::string>::size_type j = 0; j < task.images.size(); j++) {
				os << ", \"" << task.images[j]
					 << "\", " << std::setprecision(16) << task.properties[j];
			}
			os << "\n";
		}
	};
#if 1
	saveTask(fout, "Task", tasks.begin(), tasks.end());
	saveTask(fout, "Test", tests.begin(), tests.end());
#else
    for (TaskList::size_type i = 0; i < tasks.size(); i++) {
        const Task& task = tasks[i];
        fout << "Task " << std::setprecision(16) << task.a 
             << ", " << std::setprecision(16) << task.b;
        for (std::vector<std::string>::size_type j = 0; j < task.images.size(); j++) {
            fout << ", \"" << task.images[j]
                 << "\", " << std::setprecision(16) << task.properties[j];
        }
        fout << "\n";
    }
    for (TaskList::size_type i = 0; i < tests.size(); i++) {
        const Task& test = tests[i];
        fout << "Test " << std::setprecision(16) << test.a 
             << ", " << std::setprecision(16) << test.b;
        for (std::vector<std::string>::size_type j = 0; j < test.images.size(); j++) {
            fout << ", \"" << test.images[j]
                 << "\", " << std::setprecision(16) << test.properties[j];
        }
        fout << "\n";
    }
#endif
    fout << std::endl;
}
Exemplo n.º 16
0
 std::ostream& operator<<(std::ostream& out, const std::vector<T>& v) {
   return print_range(out, v, "[", ", ", "]");
 }
Exemplo n.º 17
0
void test_dim(int ndim)
{
	int dim,elems;
	int i,j, proc;
	/* double a[DIM4][DIM3][DIM2][DIM1], b[EDIM4][EDIM3][EDIM2][EDIM1];*/
        double *b;
        double *a, *a1, *a2, *c;
        int ridx;
        MPI_Datatype typeA, typeB;
        int rstrideB[MAXDIMS];
        int rcount[MAXDIMS];
        int pidx1 = -1, pidx2 = -1, pidx3 = -1;

	elems = 1;   
        strideA[0]=sizeof(double); 
        strideB[0]=sizeof(double);
	for(i=0;i<ndim;i++){
		strideA[i] *= dimsA[i];
		strideB[i] *= dimsB[i];
                if(i<ndim-1){
                     strideA[i+1] = strideA[i];
                     strideB[i+1] = strideB[i];
                }
		elems *= dimsA[i];
	}

        /* create shared and local arrays */
        create_safe_array((void**)&b, sizeof(double),ndim,dimsB);
        a1 = (double *)malloc(sizeof(double)*elems);
        assert(a1);
        a2 = (double *)malloc(sizeof(double)*elems);
        assert(a2);
        c = (double *)malloc(sizeof(double)*elems);
        assert(c);

	init(a1, ndim, elems, dimsA, me!=0, 0);
	init(a2, ndim, elems, dimsA, me!=0, 1);
	
	if(me==0){
            printf("--------array[%d",dimsA[0]);
	    for(dim=1;dim<ndim;dim++)printf(",%d",dimsA[dim]);
	    printf("]--------\n");
        }
        sleep(1);

        MP_BARRIER();
	for(i=0;i<LOOP;i++){
	    int idx1, idx2, idx3, ridx;
            MPI_Request request;
            if (i%2) {
               a = a2;
            } else {
               a = a1;
            }
	    get_range(ndim, dimsA, loA, hiA);
	    new_range(ndim, dimsB, loA, hiA, loB, hiB);
	    new_range(ndim, dimsA, loA, hiA, loC, hiC);

            proc=nproc-1-me;

            if(me==0){
	       print_range("local",ndim,loA, hiA,"-> ");
	       print_range("remote",ndim,loB, hiB,"-> ");
	       print_range("local",ndim,loC, hiC,"\n");
            }

	    idx1 = Index(ndim, loA, dimsA);
	    idx2 = Index(ndim, loB, dimsB);
	    idx3 = Index(ndim, loC, dimsA);

            MPI_Sendrecv(&idx2, 1, MPI_INT, proc, 666, &ridx, 1, MPI_INT, proc, 666, MPI_COMM_WORLD, MPI_STATUS_IGNORE);

	    for(j=0;j<ndim;j++)count[j]=hiA[j]-loA[j]+1;

	    count[0]   *= sizeof(double); /* convert range to bytes at stride level zero */

            Strided_to_dtype(strideA, count, ndim-1, MPI_BYTE, &typeA);
            MPI_Type_commit(&typeA);
            Strided_to_dtype(strideB, count, ndim-1, MPI_BYTE, &typeB);
            MPI_Type_commit(&typeB);

            MPI_Accumulate(a + idx1, 1, typeA, proc, (MPI_Aint)(idx2*sizeof(double)), 1, typeB, MPI_REPLACE, win);
            MP_FLUSH(proc);

            /* note that we do not need Fence here since
             * consectutive operations targeting the same process are ordered */

            MPI_Get_accumulate(NULL, 0, MPI_BYTE, c + idx3, 1, typeA, proc,
                         (MPI_Aint)(idx2*sizeof(double)), 1, typeB, MPI_NO_OP, win);
            MP_FLUSH(proc);

            
            compare_patches(0., ndim, a+idx1, loA, hiA, dimsA, c+idx3, loC, hiC, dimsA);

            pidx1 = idx1;
            pidx2 = idx2;
            pidx3 = idx3; 

            MPI_Type_free(&typeA);
            MPI_Type_free(&typeB);
        }

        free(c);
        destroy_safe_array();
        free(a);
}
Exemplo n.º 18
0
static void
print_array_type (struct type *type, struct ui_file *stream, int show,
                  int level, const struct type_print_options *flags)
{
    int bitsize;
    int n_indices;

    if (ada_is_constrained_packed_array_type (type))
        type = ada_coerce_to_simple_array_type (type);

    bitsize = 0;
    fprintf_filtered (stream, "array (");

    if (type == NULL)
    {
        fprintf_filtered (stream, _("<undecipherable array type>"));
        return;
    }

    n_indices = -1;
    if (ada_is_simple_array_type (type))
    {
        struct type *range_desc_type;
        struct type *arr_type;

        range_desc_type = ada_find_parallel_type (type, "___XA");
        ada_fixup_array_indexes_type (range_desc_type);

        bitsize = 0;
        if (range_desc_type == NULL)
        {
            for (arr_type = type; TYPE_CODE (arr_type) == TYPE_CODE_ARRAY;
                    arr_type = TYPE_TARGET_TYPE (arr_type))
            {
                if (arr_type != type)
                    fprintf_filtered (stream, ", ");
                print_range (TYPE_INDEX_TYPE (arr_type), stream);
                if (TYPE_FIELD_BITSIZE (arr_type, 0) > 0)
                    bitsize = TYPE_FIELD_BITSIZE (arr_type, 0);
            }
        }
        else
        {
            int k;

            n_indices = TYPE_NFIELDS (range_desc_type);
            for (k = 0, arr_type = type;
                    k < n_indices;
                    k += 1, arr_type = TYPE_TARGET_TYPE (arr_type))
            {
                if (k > 0)
                    fprintf_filtered (stream, ", ");
                print_range_type (TYPE_FIELD_TYPE (range_desc_type, k),
                                  stream);
                if (TYPE_FIELD_BITSIZE (arr_type, 0) > 0)
                    bitsize = TYPE_FIELD_BITSIZE (arr_type, 0);
            }
        }
    }
    else
    {
        int i, i0;

        for (i = i0 = ada_array_arity (type); i > 0; i -= 1)
            fprintf_filtered (stream, "%s<>", i == i0 ? "" : ", ");
    }

    fprintf_filtered (stream, ") of ");
    wrap_here ("");
    ada_print_type (ada_array_element_type (type, n_indices), "", stream,
                    show == 0 ? 0 : show - 1, level + 1, flags);
    if (bitsize > 0)
        fprintf_filtered (stream, " <packed: %d-bit elements>", bitsize);
}
Exemplo n.º 19
0
static void list_desc (ext2_filsys fs)
{
	unsigned long i;
	blk64_t	first_block, last_block;
	blk64_t	super_blk, old_desc_blk, new_desc_blk;
	char *block_bitmap=NULL, *inode_bitmap=NULL;
	const char *units = _("blocks");
	int inode_blocks_per_group, old_desc_blocks, reserved_gdt;
	int		block_nbytes, inode_nbytes;
	int has_super;
	blk64_t		blk_itr = EXT2FS_B2C(fs, fs->super->s_first_data_block);
	ext2_ino_t	ino_itr = 1;
	errcode_t	retval;

	if (EXT2_HAS_RO_COMPAT_FEATURE(fs->super,
				       EXT4_FEATURE_RO_COMPAT_BIGALLOC))
		units = _("clusters");

	block_nbytes = EXT2_CLUSTERS_PER_GROUP(fs->super) / 8;
	inode_nbytes = EXT2_INODES_PER_GROUP(fs->super) / 8;

	if (fs->block_map)
		block_bitmap = malloc(block_nbytes);
	if (fs->inode_map)
		inode_bitmap = malloc(inode_nbytes);

	inode_blocks_per_group = ((fs->super->s_inodes_per_group *
				   EXT2_INODE_SIZE(fs->super)) +
				  EXT2_BLOCK_SIZE(fs->super) - 1) /
				 EXT2_BLOCK_SIZE(fs->super);
	reserved_gdt = fs->super->s_reserved_gdt_blocks;
	fputc('\n', stdout);
	first_block = fs->super->s_first_data_block;
	if (fs->super->s_feature_incompat & EXT2_FEATURE_INCOMPAT_META_BG)
		old_desc_blocks = fs->super->s_first_meta_bg;
	else
		old_desc_blocks = fs->desc_blocks;
	for (i = 0; i < fs->group_desc_count; i++) {
		first_block = ext2fs_group_first_block2(fs, i);
		last_block = ext2fs_group_last_block2(fs, i);

		ext2fs_super_and_bgd_loc2(fs, i, &super_blk,
					  &old_desc_blk, &new_desc_blk, 0);

		printf (_("Group %lu: (Blocks "), i);
		print_range(first_block, last_block);
		fputs(")", stdout);
		print_bg_opts(fs, i);
		if (ext2fs_has_group_desc_csum(fs)) {
			unsigned csum = ext2fs_bg_checksum(fs, i);
			unsigned exp_csum = ext2fs_group_desc_csum(fs, i);

			printf(_("  Checksum 0x%04x"), csum);
			if (csum != exp_csum)
				printf(_(" (EXPECTED 0x%04x)"), exp_csum);
			printf(_(", unused inodes %u\n"),
			       ext2fs_bg_itable_unused(fs, i));
		}
		has_super = ((i==0) || super_blk);
		if (has_super) {
			printf (_("  %s superblock at "),
				i == 0 ? _("Primary") : _("Backup"));
			print_number(super_blk);
		}
		if (old_desc_blk) {
			printf("%s", _(", Group descriptors at "));
			print_range(old_desc_blk,
				    old_desc_blk + old_desc_blocks - 1);
			if (reserved_gdt) {
				printf("%s", _("\n  Reserved GDT blocks at "));
				print_range(old_desc_blk + old_desc_blocks,
					    old_desc_blk + old_desc_blocks +
					    reserved_gdt - 1);
			}
		} else if (new_desc_blk) {
			fputc(has_super ? ',' : ' ', stdout);
			printf("%s", _(" Group descriptor at "));
			print_number(new_desc_blk);
			has_super++;
		}
		if (has_super)
			fputc('\n', stdout);
		fputs(_("  Block bitmap at "), stdout);
		print_number(ext2fs_block_bitmap_loc(fs, i));
		print_bg_rel_offset(fs, ext2fs_block_bitmap_loc(fs, i), 0,
				    first_block, last_block);
		if (fs->super->s_feature_ro_compat &
		    EXT4_FEATURE_RO_COMPAT_METADATA_CSUM)
			printf(_(", csum 0x%08x"),
			       ext2fs_block_bitmap_checksum(fs, i));
		fputs(_(", Inode bitmap at "), stdout);
		print_number(ext2fs_inode_bitmap_loc(fs, i));
		print_bg_rel_offset(fs, ext2fs_inode_bitmap_loc(fs, i), 0,
				    first_block, last_block);
		if (fs->super->s_feature_ro_compat &
		    EXT4_FEATURE_RO_COMPAT_METADATA_CSUM)
			printf(_(", csum 0x%08x"),
			       ext2fs_inode_bitmap_checksum(fs, i));
		fputs(_("\n  Inode table at "), stdout);
		print_range(ext2fs_inode_table_loc(fs, i),
			    ext2fs_inode_table_loc(fs, i) +
			    inode_blocks_per_group - 1);
		print_bg_rel_offset(fs, ext2fs_inode_table_loc(fs, i), 1,
				    first_block, last_block);
		printf (_("\n  %u free %s, %u free inodes, "
			  "%u directories%s"),
			ext2fs_bg_free_blocks_count(fs, i), units,
			ext2fs_bg_free_inodes_count(fs, i),
			ext2fs_bg_used_dirs_count(fs, i),
			ext2fs_bg_itable_unused(fs, i) ? "" : "\n");
		if (ext2fs_bg_itable_unused(fs, i))
			printf (_(", %u unused inodes\n"),
				ext2fs_bg_itable_unused(fs, i));
		if (block_bitmap) {
			fputs(_("  Free blocks: "), stdout);
			retval = ext2fs_get_block_bitmap_range2(fs->block_map,
				 blk_itr, block_nbytes << 3, block_bitmap);
			if (retval)
				com_err("list_desc", retval,
					"while reading block bitmap");
			else
				print_free(i, block_bitmap,
					   fs->super->s_clusters_per_group,
					   fs->super->s_first_data_block,
					   EXT2FS_CLUSTER_RATIO(fs));
			fputc('\n', stdout);
			blk_itr += fs->super->s_clusters_per_group;
		}
		if (inode_bitmap) {
			fputs(_("  Free inodes: "), stdout);
			retval = ext2fs_get_inode_bitmap_range2(fs->inode_map,
				 ino_itr, inode_nbytes << 3, inode_bitmap);
			if (retval)
				com_err("list_desc", retval,
					"while reading inode bitmap");
			else
				print_free(i, inode_bitmap,
					   fs->super->s_inodes_per_group,
					   1, 1);
			fputc('\n', stdout);
			ino_itr += fs->super->s_inodes_per_group;
		}
	}
	if (block_bitmap)
		free(block_bitmap);
	if (inode_bitmap)
		free(inode_bitmap);
}
Exemplo n.º 20
0
void
ada_print_type (struct type *type0, const char *varstring,
                struct ui_file *stream, int show, int level,
                const struct type_print_options *flags)
{
    struct type *type = ada_check_typedef (ada_get_base_type (type0));
    char *type_name = decoded_type_name (type0);
    int is_var_decl = (varstring != NULL && varstring[0] != '\0');

    if (type == NULL)
    {
        if (is_var_decl)
            fprintf_filtered (stream, "%.*s: ",
                              ada_name_prefix_len (varstring), varstring);
        fprintf_filtered (stream, "<null type?>");
        return;
    }

    if (show > 0)
        type = ada_check_typedef (type);

    if (is_var_decl && TYPE_CODE (type) != TYPE_CODE_FUNC)
        fprintf_filtered (stream, "%.*s: ",
                          ada_name_prefix_len (varstring), varstring);

    if (type_name != NULL && show <= 0 && !ada_is_aligner_type (type))
    {
        fprintf_filtered (stream, "%.*s",
                          ada_name_prefix_len (type_name), type_name);
        return;
    }

    if (ada_is_aligner_type (type))
        ada_print_type (ada_aligned_type (type), "", stream, show, level, flags);
    else if (ada_is_constrained_packed_array_type (type)
             && TYPE_CODE (type) != TYPE_CODE_PTR)
        print_array_type (type, stream, show, level, flags);
    else
        switch (TYPE_CODE (type))
        {
        default:
            fprintf_filtered (stream, "<");
            c_print_type (type, "", stream, show, level, flags);
            fprintf_filtered (stream, ">");
            break;
        case TYPE_CODE_PTR:
        case TYPE_CODE_TYPEDEF:
            fprintf_filtered (stream, "access ");
            ada_print_type (TYPE_TARGET_TYPE (type), "", stream, show, level,
                            flags);
            break;
        case TYPE_CODE_REF:
            fprintf_filtered (stream, "<ref> ");
            ada_print_type (TYPE_TARGET_TYPE (type), "", stream, show, level,
                            flags);
            break;
        case TYPE_CODE_ARRAY:
            print_array_type (type, stream, show, level, flags);
            break;
        case TYPE_CODE_BOOL:
            fprintf_filtered (stream, "(false, true)");
            break;
        case TYPE_CODE_INT:
            if (ada_is_fixed_point_type (type))
                print_fixed_point_type (type, stream);
            else
            {
                const char *name = ada_type_name (type);

                if (!ada_is_range_type_name (name))
                    fprintf_filtered (stream, _("<%d-byte integer>"),
                                      TYPE_LENGTH (type));
                else
                {
                    fprintf_filtered (stream, "range ");
                    print_range_type (type, stream);
                }
            }
            break;
        case TYPE_CODE_RANGE:
            if (ada_is_fixed_point_type (type))
                print_fixed_point_type (type, stream);
            else if (ada_is_modular_type (type))
                fprintf_filtered (stream, "mod %s",
                                  int_string (ada_modulus (type), 10, 0, 0, 1));
            else
            {
                fprintf_filtered (stream, "range ");
                print_range (type, stream);
            }
            break;
        case TYPE_CODE_FLT:
            fprintf_filtered (stream, _("<%d-byte float>"), TYPE_LENGTH (type));
            break;
        case TYPE_CODE_ENUM:
            if (show < 0)
                fprintf_filtered (stream, "(...)");
            else
                print_enum_type (type, stream);
            break;
        case TYPE_CODE_STRUCT:
            if (ada_is_array_descriptor_type (type))
                print_array_type (type, stream, show, level, flags);
            else if (ada_is_bogus_array_descriptor (type))
                fprintf_filtered (stream,
                                  _("array (?) of ? (<mal-formed descriptor>)"));
            else
                print_record_type (type, stream, show, level, flags);
            break;
        case TYPE_CODE_UNION:
            print_unchecked_union_type (type, stream, show, level, flags);
            break;
        case TYPE_CODE_FUNC:
            print_func_type (type, stream, varstring, flags);
            break;
        }
}