예제 #1
0
bool Excn::ExodusFile::initialize(const SystemInterface& si, int start_part, int part_count)
{
  processorCount_ = si.processor_count(); // Total number processors
  partCount_      = part_count;      // Total parts we are processing
  startPart_      = start_part;      // Which one to start with
  SMART_ASSERT(partCount_ + startPart_ <= processorCount_)(partCount_)(startPart_)(processorCount_);
  
  // EPU always wants entity (block, set, map) ids as 64-bit quantities...
  mode64bit_ = EX_IDS_INT64_API;
  if (si.int64()) {
    mode64bit_ |= EX_ALL_INT64_API;

    // For output...
    mode64bit_ |= EX_ALL_INT64_DB;
  }

  // See if we can keep files open 
  int max_files = get_free_descriptor_count();
  if (partCount_ <= max_files) {
    keepOpen_ = true;
    if (si.debug() & 1)
      std::cout << "Files kept open... (Max open = " << max_files << ")\n\n";
  } else {
    keepOpen_ = false;
    std::cout << "Single file mode... (Max open = " << max_files << ")\n"
	      << "Consider using the -subcycle option for faster execution...\n\n";
  }

  fileids_.resize(processorCount_);
  filenames_.resize(processorCount_);

  std::string curdir = si.cwd();
  std::string file_prefix = si.basename();
  std::string exodus_suffix = si.exodus_suffix();
  
  std::string root_dir = si.root_dir();
  std::string sub_dir  = si.sub_dir();

  ParallelDisks disks;
  disks.Raid_Offset(si.raid_offset());
  disks.Number_of_Raids(si.raid_count());

  float version = 0.0;

  // create exo names
  for(int p = 0; p < partCount_; p++) {
    std::string name = file_prefix;
    if (!exodus_suffix.empty()) {
      name += "." + exodus_suffix;
    }

    int proc = p + startPart_;
    disks.rename_file_for_mp(root_dir, sub_dir, name, proc,
			     processorCount_); 
    filenames_[p] = name;

    if (p == 0) {
      int cpu_word_size  = sizeof(float);
      int io_word_size_var   = 0;
      int mode = EX_READ;
      mode |= mode64bit_;
      int exoid = ex_open(filenames_[p].c_str(),
			  mode, &cpu_word_size,
			  &io_word_size_var, &version);
      if (exoid < 0) {
	std::cerr << "Cannot open file '" << filenames_[p] << "'" << std::endl;
	return false;
      }

      int int64db = ex_int64_status(exoid) & EX_ALL_INT64_DB;
      if (int64db) {
	// If anything stored on input db as 64-bit int, then output db will have
	// everything stored as 64-bit ints and all API functions will use 64-bit
	mode64bit_ |= EX_ALL_INT64_API;
	mode64bit_ |= EX_ALL_INT64_DB;
      }
      
      int max_name_length = ex_inquire_int(exoid, EX_INQ_DB_MAX_USED_NAME_LENGTH);
      if (max_name_length > maximumNameLength_)
	maximumNameLength_ = max_name_length;

      ex_close(exoid);

      if (io_word_size_var < (int)sizeof(float))
	io_word_size_var = sizeof(float);

      ioWordSize_ = io_word_size_var;
      cpuWordSize_ = io_word_size_var;
    }

    if (keepOpen_ || p == 0) {
      int io_word_size_var   = 0;
      int mode = EX_READ;
      // All entity ids (block, sets) are read/written as 64-bit...
      mode |= mode64bit_;
      fileids_[p] = ex_open(filenames_[p].c_str(),
			    mode, &cpuWordSize_,
			    &io_word_size_var, &version);
      if (fileids_[p] < 0) {
	std::cerr << "Cannot open file '" << filenames_[p] << "'" << std::endl;
	return false;
      }
      ex_set_max_name_length(fileids_[p], maximumNameLength_);
      SMART_ASSERT(ioWordSize_ == io_word_size_var)(ioWordSize_)(io_word_size_var);
    }
    
    if (si.debug()&64 || p==0 || p==partCount_-1) {
      std::cout << "Input(" << p << "): '" << name.c_str() << "'" << std::endl;
      if (!(si.debug()&64) && p==0)
	std::cout << "..." << std::endl;
    }
  }

  if (mode64bit_ & EX_ALL_INT64_DB) {
    std::cout << "Input files contain 8-byte integers.\n";
    si.set_int64();
  }

  return true;
}
예제 #2
0
bool Excn::ExodusFile::initialize(const SystemInterface& si)
{
  // See if we can keep files open 
  size_t max_files = get_free_descriptor_count();
  if (si.inputFiles_.size() <= max_files) {
    keepOpen_ = true;
    if (si.debug() & 1)
      std::cout << "Files kept open... (Max open = " << max_files << ")\n\n";
  } else {
    keepOpen_ = false;
    std::cout << "Single file mode... (Max open = " << max_files << ")\n"
	      << "Consider using the -subcycle option for faster execution...\n\n";
  }

  float version = 0.0;

  // create exo names
  filenames_.resize(si.inputFiles_.size());
  fileids_.resize(si.inputFiles_.size());
  
  int int_byte_size_api = 4;
  if (si.ints_64_bit())
    int_byte_size_api = 8;
  
  int overall_max_name_length = 0;
  for(size_t p = 0; p < si.inputFiles_.size(); p++) {
    std::string name = si.inputFiles_[p];

    filenames_[p] = name;

    if (p == 0) {
      int cpu_word_size  = sizeof(float);
      int io_wrd_size   = 0;
      int exoid = ex_open(filenames_[p].c_str(),
			  EX_READ, &cpu_word_size,
			  &io_wrd_size, &version);
      if (exoid < 0) {
	std::cerr << "Cannot open file '" << filenames_[p] << "'" << std::endl;
	return false;
      }

      int max_name_length = ex_inquire_int(exoid, EX_INQ_DB_MAX_USED_NAME_LENGTH);
      if (max_name_length > overall_max_name_length)
	overall_max_name_length = max_name_length;

      ex_close(exoid);

      if (io_wrd_size < (int)sizeof(float))
	io_wrd_size = sizeof(float);

      ioWordSize_ = io_wrd_size;
      cpuWordSize_ = io_wrd_size;

      if (ex_int64_status(exoid & EX_ALL_INT64_DB) || si.ints_64_bit()) {
	exodusMode_ = EX_ALL_INT64_API;
      }
    }

    if (keepOpen_ || p == 0) {
      int io_wrd_size   = 0;
      int mode = EX_READ | exodusMode_;

      fileids_[p] = ex_open(filenames_[p].c_str(),
			    mode, &cpuWordSize_,
			    &io_wrd_size, &version);
      if (fileids_[p] < 0) {
	std::cerr << "Cannot open file '" << filenames_[p] << "'" << std::endl;
	return false;
      }

      SMART_ASSERT(ioWordSize_ == io_wrd_size)(ioWordSize_)(io_wrd_size);
    }
    
    std::cout << "Part " << p+1 << ": '" << name.c_str() << "'" << std::endl;
  }

  maximumNameLength_ = overall_max_name_length;
  for(size_t p = 0; p < si.inputFiles_.size(); p++) {
    ex_set_max_name_length(fileids_[p], maximumNameLength_);
  }

  return true;
}