Esempio n. 1
0
vector<char>
ucs4_to_eightbit(char_type const * ucs4str, size_t ls, string const & encoding)
{
	map<string, IconvProcessor> & processors(ucs4To8bitProcessors());
	if (processors.find(encoding) == processors.end()) {
		IconvProcessor processor(encoding.c_str(), ucs4_codeset);
		processors.insert(make_pair(encoding, processor));
	}
	return iconv_convert<char>(processors[encoding], ucs4str, ls);
}
Esempio n. 2
0
char ucs4_to_eightbit(char_type ucs4, string const & encoding)
{
	map<string, IconvProcessor> & processors(ucs4To8bitProcessors());
	map<string, IconvProcessor>::iterator it = processors.find(encoding);
	if (it == processors.end()) {
		IconvProcessor processor(encoding.c_str(), ucs4_codeset);
		it = processors.insert(make_pair(encoding, processor)).first;
	}

	char out;
	int const bytes = it->second.convert((char *)(&ucs4), 4, &out, 1);
	if (bytes > 0)
		return out;
	return 0;
}
Esempio n. 3
0
void restrictive_coarsening::prepare_data_to_send(
    int n_local_hyperedges, int n_local_pins,
    dynamic_array<int> local_hyperedge_weights,
    dynamic_array<int> local_hyperedge_offsets,
    dynamic_array<int> local_pins, MPI_Comm comm) {

  ds::dynamic_array<int> processors(processors_);
  for (int i = 0; i < processors_; ++i) {
    processors[i] = i;
  }

  ds::dynamic_array<int> min_local_indices(processors_);
  ds::dynamic_array<int> max_local_indices(processors_);

  // Prepare data structures
  MPI_Allgather(&minimum_vertex_index_, 1, MPI_INT, min_local_indices.data(), 1,
                MPI_INT, comm);
  MPI_Allgather(&maximum_vertex_index_, 1, MPI_INT, max_local_indices.data(), 1,
                MPI_INT, comm);

  ds::complete_binary_tree<int> vertex_to_processor(processors.data(),
                                                    min_local_indices.data(),
                                                    processors_);

  ds::dynamic_array<int> vertices_per_processor(processors_);
  utility::set_to_zero<int>(vertices_per_processor.data(), processors_);
  utility::set_to_zero<int>(send_lens_.data(), processors_);

  ds::bit_field to_load(n_local_hyperedges);
  if (percentile_ == 100) {
    to_load.set();
  } else {
    compute_hyperedges_to_load(to_load, n_local_hyperedges,
                               n_local_pins, local_hyperedge_weights,
                               local_hyperedge_offsets, comm);
  }

  ds::dynamic_array<bool> sent_to_processor(processors_, false);
  utility::set_to_zero<int>(send_lens_.data(), processors_);

  for (int i = 0; i < n_local_hyperedges; ++i) {
    if (to_load.test(i)) {
      int start_offset = local_hyperedge_offsets[i];
      int end_offset = local_hyperedge_offsets[i + 1];
      for (int j = start_offset; j < end_offset; ++j) {
        int proc = vertex_to_processor.root_value(local_pins[j]);
        ++vertices_per_processor[proc];
      }

      for (int j = 0; j < processors_; ++j) {
        if (vertices_per_processor[j] > 1) {
          if (j == rank_) {
            hyperedge_weights_[number_of_hyperedges_] = local_hyperedge_weights[i];
            hyperedge_offsets_[number_of_hyperedges_] = number_of_local_pins_;
            ++number_of_hyperedges_;

            for (int l = start_offset; l < end_offset; ++l) {
              int local_vertex = local_pins[l] - minimum_vertex_index_;
              if (0 <= local_vertex &&
                  local_vertex < number_of_local_vertices_) {
                local_pin_list_[number_of_local_pins_++] = local_vertex;
                ++vertex_to_hyperedges_offset_[local_vertex];
              }
            }
          } else {
            data_out_sets_[j][send_lens_[j]++] = vertices_per_processor[j] + 2;
            data_out_sets_[j][send_lens_[j]++] = local_hyperedge_weights[i];
            for (int l = start_offset; l < end_offset; ++l) {
              if (min_local_indices[j] <= local_pins[l] &&
                  local_pins[l] < max_local_indices[j]) {
                data_out_sets_[j][send_lens_[j]++] =
                    local_pins[l] - min_local_indices[j];
              }
            }
          }
          vertices_per_processor[j] = 0;
        }
        if (vertices_per_processor[j] == 1) {
          vertices_per_processor[j] = 0;
        }
      }
    }
  }
}
Esempio n. 4
0
static
void
parseCommandline( int argc, char* argv[], 
		  int* fail_hard, int* old_mode, int* cpus )
{
  char *s, *ptr = strrchr( argv[0], '/' );
  int option, tmp;

  /* exit code 0 is always good, just in case */
  memset( success, 0, sizeof(success) );
  success[0] = 1;
  *cpus = 1; 

  if ( ptr == NULL ) ptr = argv[0];
  else ptr++;
  application = ptr;

  /* default progress report location from environment variable */
  if ( (s = getenv("SEQEXEC_PROGRESS_REPORT")) != NULL ) {
    if ( (progress = open( s, O_WRONLY | O_APPEND | O_CREAT, 0666 )) == -1 ) {
      showerr( "%s: open progress %s: %d: %s\n",
	       application, s, errno, strerror(errno) );
    }
  }

  /* default parallelism from environment variable */ 
  if ( (s = getenv("SEQEXEC_CPUS")) != NULL ) { 
    if ( strcasecmp( s, "auto" ) == 0 ) *cpus = processors();
    else *cpus = atoi(s); 
    if ( *cpus < 0 ) *cpus = 1; 
  }

  opterr = 0;
  while ( (option = getopt( argc, argv, "R:S:defhn:s:" )) != -1 ) {
    switch ( option ) {
    case 'R':
      if ( progress != -1 ) close(progress);
      if ( (progress = open( optarg, O_WRONLY | O_APPEND | O_CREAT, 0666 )) == -1 ) {
	showerr( "%s: open progress %s: %d: %s\n",
		 application, optarg, errno, strerror(errno) );
      }
      break;

    case 'S':
      tmp = atoi(optarg);
      if ( tmp > 0 && tmp < sizeof(success) ) success[tmp] = 1;
      else showerr( "%s: Ignoring unreasonable success code %d\n", application, tmp );
      break;

    case 'd':
      debug++;
      break;

    case 'e':
      *old_mode = 1;
      *fail_hard = 0;
      break;

    case 'f':
      *fail_hard = 1;
      *old_mode = 0;
      break;

    case 'n':
      if ( strcasecmp( optarg, "auto" ) == 0 ) *cpus = processors();
      else *cpus = atoi(optarg); 
      if ( *cpus < 0 ) *cpus = 1; 
      break;

    case 's':
      if ( freopen( optarg, "w", stdout ) == NULL ) {
	showerr( "%s: open status %s: %d: %s\n",
		 application, optarg, errno, strerror(errno) );
	exit(2);
      }
      break;

    case 'h':
    case '?':
      helpMe( ptr, 0 );
      break;

    default:
      helpMe( ptr, 1 );
      break;
    }
  }

  if ( (argc - optind) > 1 ) helpMe( ptr, 1 );
  if ( argc != optind ) {
    if ( (freopen( argv[optind], "r", stdin )) == NULL ) {
      showerr( "%s: open input %s: %d: %s\n",
	       application, argv[optind], errno, strerror(errno) );
      exit(3);
    }
  }
}
Esempio n. 5
0
void ScriptComponent::deactivate()
{
  processors().script.unregister_script(this);
  on_deactivate();
}