当前位置: 首页>>代码示例>>C++>>正文


C++ ParallelComm::gather_data方法代码示例

本文整理汇总了C++中ParallelComm::gather_data方法的典型用法代码示例。如果您正苦于以下问题:C++ ParallelComm::gather_data方法的具体用法?C++ ParallelComm::gather_data怎么用?C++ ParallelComm::gather_data使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ParallelComm的用法示例。


在下文中一共展示了ParallelComm::gather_data方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: test_gather_onevar

void test_gather_onevar()
{
  Core moab;
  Interface& mb = moab;

  EntityHandle file_set;
  ErrorCode rval = mb.create_meshset(MESHSET_SET, file_set);
  CHECK_ERR(rval);

  std::string opts;
  get_options(opts);

  // Read cell variable vorticity and create gather set on processor 0
  opts += ";VARIABLE=vorticity;GATHER_SET=0";
  rval = mb.load_file(example, &file_set, opts.c_str());
  CHECK_ERR(rval);

#ifdef MOAB_HAVE_MPI
  ParallelComm* pcomm = ParallelComm::get_pcomm(&mb, 0);
  int rank = pcomm->proc_config().proc_rank();

  Range cells, cells_owned;
  rval = mb.get_entities_by_type(file_set, MBPOLYGON, cells);
  CHECK_ERR(rval);

  // Get local owned cells
  rval = pcomm->filter_pstatus(cells, PSTATUS_NOT_OWNED, PSTATUS_NOT, -1, &cells_owned);
  CHECK_ERR(rval);

  EntityHandle gather_set = 0;
  if (0 == rank) {
    // Get gather set
    ReadUtilIface* readUtilIface;
    mb.query_interface(readUtilIface);
    rval = readUtilIface->get_gather_set(gather_set);
    CHECK_ERR(rval);
    assert(gather_set != 0);
  }

  Tag vorticity_tag0, gid_tag;
  rval = mb.tag_get_handle("vorticity0", layers, MB_TYPE_DOUBLE, vorticity_tag0, MB_TAG_DENSE);
  CHECK_ERR(rval);

  rval = mb.tag_get_handle(GLOBAL_ID_TAG_NAME, 1, MB_TYPE_INTEGER, gid_tag, MB_TAG_DENSE);
  CHECK_ERR(rval);

  pcomm->gather_data(cells_owned, vorticity_tag0, gid_tag, gather_set, 0);

  if (0 == rank) {
    // Get gather set cells
    Range gather_set_cells;
    rval = mb.get_entities_by_type(gather_set, MBPOLYGON, gather_set_cells);
    CHECK_ERR(rval);
    CHECK_EQUAL((size_t)642, gather_set_cells.size());
    CHECK_EQUAL((size_t)1, gather_set_cells.psize());

    // Check vorticity0 tag values on 4 gather set cells: first cell, two median cells, and last cell
    EntityHandle cell_ents[] = {gather_set_cells[0], gather_set_cells[320],
                                gather_set_cells[321], gather_set_cells[641]};
    double vorticity0_val[4 * layers];
    rval = mb.tag_get_data(vorticity_tag0, cell_ents, 4, vorticity0_val);
    CHECK_ERR(rval);

    // Only check first two layers
    // Layer 0
    CHECK_REAL_EQUAL(3.629994, vorticity0_val[0 * layers], eps);
    CHECK_REAL_EQUAL(0.131688, vorticity0_val[1 * layers], eps);
    CHECK_REAL_EQUAL(-0.554888, vorticity0_val[2 * layers], eps);
    CHECK_REAL_EQUAL(-0.554888, vorticity0_val[3 * layers], eps);
    // Layer 1
    CHECK_REAL_EQUAL(3.629944, vorticity0_val[0 * layers + 1], eps);
    CHECK_REAL_EQUAL(0.131686, vorticity0_val[1 * layers + 1], eps);
    CHECK_REAL_EQUAL(-0.554881, vorticity0_val[2 * layers + 1], eps);
    CHECK_REAL_EQUAL(-0.554881, vorticity0_val[3 * layers + 1], eps);
  }
#endif
}
开发者ID:obmun,项目名称:moab,代码行数:77,代码来源:read_gcrm_nc.cpp

示例2: gather_one_cell_var

void gather_one_cell_var(int gather_set_rank)
{
  Core moab;
  Interface& mb = moab;

  EntityHandle file_set;
  ErrorCode rval = mb.create_meshset(MESHSET_SET, file_set);
  CHECK_ERR(rval);

  read_options = "PARALLEL=READ_PART;PARTITION_METHOD=TRIVIAL;PARALLEL_RESOLVE_SHARED_ENTS";
  std::ostringstream gather_set_option;
  gather_set_option << ";GATHER_SET=" << gather_set_rank;
  read_options += gather_set_option.str();

  rval = mb.load_file(example, &file_set, read_options.c_str());
  CHECK_ERR(rval);

  ParallelComm* pcomm = ParallelComm::get_pcomm(&mb, 0);
  int procs = pcomm->proc_config().proc_size();
  int rank = pcomm->proc_config().proc_rank();

  // Make sure gather_set_rank is valid
  if (gather_set_rank < 0 || gather_set_rank >= procs)
    return;

  Range cells, cells_owned;
  rval = mb.get_entities_by_type(file_set, MBPOLYGON, cells);
  CHECK_ERR(rval);

  // Get local owned cells
  rval = pcomm->filter_pstatus(cells, PSTATUS_NOT_OWNED, PSTATUS_NOT, -1, &cells_owned);
  CHECK_ERR(rval);

  EntityHandle gather_set = 0;
  if (gather_set_rank == rank) {
    // Get gather set
    ReadUtilIface* readUtilIface;
    mb.query_interface(readUtilIface);
    rval = readUtilIface->get_gather_set(gather_set);
    CHECK_ERR(rval);
    assert(gather_set != 0);
  }

  Tag vorticity_tag0, gid_tag;
  rval = mb.tag_get_handle("vorticity0", layers, MB_TYPE_DOUBLE, vorticity_tag0, MB_TAG_DENSE);
  CHECK_ERR(rval);

  rval = mb.tag_get_handle(GLOBAL_ID_TAG_NAME, 1, MB_TYPE_INTEGER, gid_tag, MB_TAG_DENSE);
  CHECK_ERR(rval);

  pcomm->gather_data(cells_owned, vorticity_tag0, gid_tag, gather_set, gather_set_rank);

  if (gather_set_rank == rank) {
    // Get gather set cells
    Range gather_set_cells;
    rval = mb.get_entities_by_type(gather_set, MBPOLYGON, gather_set_cells);
    CHECK_ERR(rval);
    CHECK_EQUAL((size_t)642, gather_set_cells.size());
    CHECK_EQUAL((size_t)1, gather_set_cells.psize());

    // Check vorticity0 tag values on 4 gather set cells: first cell, two median cells, and last cell
    EntityHandle cell_ents[] = {gather_set_cells[0], gather_set_cells[320],
                                gather_set_cells[321], gather_set_cells[641]};
    double vorticity0_val[4 * layers];
    rval = mb.tag_get_data(vorticity_tag0, &cell_ents[0], 4, vorticity0_val);
    CHECK_ERR(rval);

    // Only check first two layers
    // Layer 0
    CHECK_REAL_EQUAL(3.629994, vorticity0_val[0 * layers], eps);
    CHECK_REAL_EQUAL(0.131688, vorticity0_val[1 * layers], eps);
    CHECK_REAL_EQUAL(-0.554888, vorticity0_val[2 * layers], eps);
    CHECK_REAL_EQUAL(-0.554888, vorticity0_val[3 * layers], eps);
    // Layer 1
    CHECK_REAL_EQUAL(3.629944, vorticity0_val[0 * layers + 1], eps);
    CHECK_REAL_EQUAL(0.131686, vorticity0_val[1 * layers + 1], eps);
    CHECK_REAL_EQUAL(-0.554881, vorticity0_val[2 * layers + 1], eps);
    CHECK_REAL_EQUAL(-0.554881, vorticity0_val[3 * layers + 1], eps);
  }
}
开发者ID:obmun,项目名称:moab,代码行数:80,代码来源:gcrm_par.cpp

示例3: test_gather_onevar

void test_gather_onevar()
{
  Core moab;
  Interface& mb = moab;

  EntityHandle file_set;
  ErrorCode rval = mb.create_meshset(MESHSET_SET, file_set);
  CHECK_ERR(rval);

  std::string opts;
  get_options(opts);

  // Read vertex variable T and create gather set on processor 0
  opts += ";VARIABLE=T;GATHER_SET=0";
#ifdef MOAB_HAVE_MPI
  opts += ";PARALLEL_RESOLVE_SHARED_ENTS";
#endif
  rval = mb.load_file(example, &file_set, opts.c_str());
  CHECK_ERR(rval);

#ifdef MOAB_HAVE_MPI
  ParallelComm* pcomm = ParallelComm::get_pcomm(&mb, 0);
  int rank = pcomm->proc_config().proc_rank();

  Range verts, verts_owned;
  rval = mb.get_entities_by_type(file_set, MBVERTEX, verts);
  CHECK_ERR(rval);

  // Get local owned vertices
  rval = pcomm->filter_pstatus(verts, PSTATUS_NOT_OWNED, PSTATUS_NOT, -1, &verts_owned);
  CHECK_ERR(rval);

  EntityHandle gather_set = 0;
  if (0 == rank) {
    // Get gather set
    ReadUtilIface* readUtilIface;
    mb.query_interface(readUtilIface);
    rval = readUtilIface->get_gather_set(gather_set);
    CHECK_ERR(rval);
    assert(gather_set != 0);
  }

  Tag Ttag0, gid_tag;
  rval = mb.tag_get_handle("T0", levels, MB_TYPE_DOUBLE, Ttag0, MB_TAG_DENSE);
  CHECK_ERR(rval);

  rval = mb.tag_get_handle(GLOBAL_ID_TAG_NAME, 1, MB_TYPE_INTEGER, gid_tag, MB_TAG_DENSE);
  CHECK_ERR(rval);

  pcomm->gather_data(verts_owned, Ttag0, gid_tag, gather_set, 0);

  if (0 == rank) {
    // Get gather set vertices
    Range gather_set_verts;
    rval = mb.get_entities_by_type(gather_set, MBVERTEX, gather_set_verts);
    CHECK_ERR(rval);
    CHECK_EQUAL((size_t)3458, gather_set_verts.size());

    // Get T0 tag values on 4 strategically selected gather set vertices
    double T0_val[4 * levels];
    EntityHandle vert_ents[] = {gather_set_verts[0], gather_set_verts[1728],
                                gather_set_verts[1729], gather_set_verts[3457]};
    rval = mb.tag_get_data(Ttag0, vert_ents, 4, T0_val);
    CHECK_ERR(rval);

    const double eps = 0.001;

    // Check first level values
    CHECK_REAL_EQUAL(233.1136, T0_val[0 * levels], eps); // First vert
    CHECK_REAL_EQUAL(236.1505, T0_val[1 * levels], eps); // Median vert
    CHECK_REAL_EQUAL(235.7722, T0_val[2 * levels], eps); // Median vert
    CHECK_REAL_EQUAL(234.0416, T0_val[3 * levels], eps); // Last vert
  }
#endif
}
开发者ID:obmun,项目名称:moab,代码行数:75,代码来源:read_ucd_nc.cpp


注:本文中的ParallelComm::gather_data方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。