Show
Ignore:
Timestamp:
08/19/09 15:05:46 (7 months ago)
Author:
hongjun
Message:

o Parallel iGeom codes are added and modified.
o CGMParallelComm.*pp, FileOptions?.*pp, ParallelGeomTool?.*pp, CGMProcConfig.*pp are added in geom/parallel directory.
o Binary read and write functions are added in OCCQueryEngine.
o GeometryQueryTool?, GeometryQueryEngine? are modified by changing of OCCQueryEngine.
o partest is test file of parallel iGeom

Location:
cgm/trunk/geom/parallel
Files:
7 added
3 modified

Legend:

Unmodified
Added
Removed
  • cgm/trunk/geom/parallel/Makefile.am

    r1981 r3108  
    22AUTOMAKE_OPTIONS = foreign 
    33 
     4 
    45# Override default defines with the ones we want from the configure script 
    5 # Override default defines with the ones we want from the configure script 
    6 DEFS = $(TEMPLATE_DEFS_INCLUDED) \ 
    7        $(LITTLE_ENDIAN) $(ACIS_STEP_TRANSLATOR) $(ACIS_IGES_TRANSLATOR) \ 
    8        -DCUBIT_ACIS_VERSION=$(ACIS_VERSION) -DACIS_VERSION=$(ACIS_VERSION) \ 
    9        -D$(ACIS_PLATFORM) 
     6if build_OCC 
     7#  DEFS = $(TEMPLATE_DEFS_INCLUDED) $(HAVE_OCC_DEF) 
     8   DEFS += $(HAVE_OCC_DEF) 
     9else 
     10   DEFS = $(TEMPLATE_DEFS_INCLUDED) \ 
     11         $(LITTLE_ENDIAN) $(ACIS_STEP_TRANSLATOR) $(ACIS_IGES_TRANSLATOR) \ 
     12         -DCUBIT_ACIS_VERSION=$(ACIS_VERSION) -DACIS_VERSION=$(ACIS_VERSION) \ 
     13         -D$(ACIS_PLATFORM) 
     14#   DEFS += $(ACIS_STEP_TRANSLATOR) $(ACIS_IGES_TRANSLATOR) \ 
     15         -DCUBIT_ACIS_VERSION=$(ACIS_VERSION) -DACIS_VERSION=$(ACIS_VERSION) \ 
     16         -D$(ACIS_PLATFORM) 
     17endif 
     18 
     19# because "ISO C++ does not support ‘long long" 
     20CXXFLAGS += -Wno-long-long 
    1021 
    1122INCLUDES = -I$(top_srcdir)/util \ 
    1223           -I$(top_srcdir)/geom \ 
    1324           -I$(top_srcdir)/geom/ACIS \ 
    14            -I$(ACIS_DIR)/include \ 
     25           -I$(ACIS_DIR)/include \ 
    1526           $(MPI_INCLUDE) 
    1627 
     
    2637# The non-template sources 
    2738libcubit_parallel_la_SOURCES = \ 
    28     AcisMemFile.cpp \ 
    29     CABodies.cpp \ 
    30     CGMMemFile.cpp \ 
    31     ParallelGeomTool.cpp \ 
    32     ProcData.cpp \ 
    33     TDParallel.cpp 
     39    CGMProcConfig.cpp \ 
     40    CGMParallelComm.cpp \ 
     41    FileOptions.cpp \ 
     42    ParallelGeomTool.cpp 
    3443 
    3544# The non-template headers 
     
    3746# to the _SOURCES list above. 
    3847libcubit_parallel_la_include_HEADERS = \ 
    39     AcisMemFile.hpp \ 
    40     CABodies.cpp \ 
    41     CGMMemFile.hpp \ 
    42     ParallelGeomTool.hpp \ 
    43     ProcData.hpp \ 
    44     TDParallel.hpp 
     48    CGMProcConfig.hpp \ 
     49    CGMParallelComm.hpp \ 
     50    FileOptions.hpp \ 
     51    ParallelGeomTool.hpp 
    4552 
  • cgm/trunk/geom/parallel/ParallelGeomTool.cpp

    r1061 r3108  
     1#include <cstdio> 
     2 
     3#include "CubitString.hpp" 
     4#include "CubitMessage.hpp" 
     5#include "DLList.hpp" 
     6#include "RefEntity.hpp" 
     7#include "CubitEntity.hpp" 
     8#include "CastTo.hpp" 
     9#include "CubitUtil.hpp" 
     10 
     11#include "TopologyBridge.hpp" 
     12#include "GeometryQueryTool.hpp" 
    113#include "ParallelGeomTool.hpp" 
    2 #include "AcisMemFile.hpp" 
    3 #include "AcisQueryEngine.hpp" 
    4 #include "TSTTG_CGM.h" 
    5 #include "ProcData.hpp" 
    6  
    7 ParallelGeomTool *ParallelGeomTool::instance_ = NULL; 
    8  
    9 int ParallelGeomTool::load_parallel(TSTTG_Instance geom, 
    10                                     const char *name,  
    11                                     int par_load_option)  
     14#include "CGMParallelConventions.h" 
     15#include "CATag.hpp" 
     16#include "CGMParallelComm.hpp" 
     17 
     18const bool debug = true; 
     19 
     20enum CGMParallelActions {PA_READ=0, PA_BROADCAST, PA_DELETE_NONLOCAL, 
     21                         PA_SCATTER, 
     22                         PA_CHECK_GIDS_SERIAL, PA_GET_ENTS,  
     23                         PA_RESOLVE_SHARED_ENTS, 
     24                         PA_EXCHANGE_GHOSTS}; 
     25 
     26enum CGMPartitionActions {PT_GEOM_DIM=0, PT_PAR_PART}; 
     27 
     28const char *CGMParallelActionsNames[] = { 
     29  "PARALLEL READ", 
     30  "PARALLEL BROADCAST",  
     31  "PARALLEL DELETE NONLOCAL", 
     32  "PARALLEL SCATTER", 
     33  "PARALLEL CHECK_GIDS_SERIAL", 
     34  "PARALLEL GET_FILESET_ENTS", 
     35  "PARALLEL RESOLVE_SHARED_ENTS", 
     36  "PARALLEL EXCHANGE_GHOSTS" 
     37}; 
     38 
     39const char* ParallelGeomTool::CGMparallelOptsNames[] = { "NONE", "READ", "READ_DELETE", "BCAST",  
     40                                                         "BCAST_DELETE", "SCATTER", "SCATTER_DELETE", 
     41                                                         "READ_PARALLEL", "FORMAT", "", 0 }; 
     42 
     43const char* ParallelGeomTool::CGMpartitionOptsNames[] = { "NONE", "GEOM_DIMENSION", 
     44                                                          "PARARELL_PARTITION", "", 0 }; 
     45 
     46//ParallelGeomTool *ParallelGeomTool::instance_ = NULL; 
     47 
     48ParallelGeomTool::ParallelGeomTool(CGMTagManager* impl, CGMParallelComm *pc) 
     49  : cgmImpl(impl), myPcomm(pc)  
    1250{ 
    13     // declare an acismemfile object 
    14   AcisMemFile amf(AcisQueryEngine::instance()); 
    15  
    16   DLIList<RefEntity*> ref_ents, ref_ents_master; 
    17  
    18     // if I'm the master, load the file and get the entities 
    19   int result; 
    20   if (ProcData::instance()->is_master()) { 
    21     result = TSTTG_load(geom, name, NULL, 0); 
    22     if (TSTTB_SUCCESS != result) return result; 
    23  
    24       // get all the volumes 
    25     TSTTG_EntityHandle *ents = NULL; 
    26     int ents_alloc = 0, ents_size; 
    27     result = TSTTG_getEntities(geom, 0, TSTTG_REGION,  
    28                                &ents, &ents_alloc, &ents_size); 
    29     if (TSTTB_SUCCESS != result) return result; 
    30  
    31       // make this the storage for the ent list 
    32     ref_ents.copy_from((RefEntity**)ents, ents_size); 
    33   } 
    34  
    35     // now communicate the entities 
    36   if (BCAST == par_load_option) { 
    37       // broadcast 
    38     result = amf.bcast_entity_list(ref_ents); 
    39   } 
    40   else if (BCAST_AND_DELETE == par_load_option) { 
    41       // bcast and delete 
    42     result = amf.bcast_and_delete_entity_list(ref_ents, ref_ents_master); 
    43   } 
    44   else if (SCATTER == par_load_option) { 
    45       // scatter 
    46     result = amf.scatter_entity_list(ref_ents); 
    47   } 
     51  if (!myPcomm) { 
     52    myPcomm = CGMParallelComm::get_pcomm(impl, 0); 
     53    if (NULL == myPcomm) myPcomm = new CGMParallelComm(cgmImpl); 
     54  } 
     55  //gqt = GeometryQueryTool::instfance(); 
     56} 
     57 
     58CubitStatus ParallelGeomTool::load_file(const char *file_name, 
     59                                        const char *options, 
     60                                        const char* set_tag_name, 
     61                                        const int* set_tag_values, 
     62                                        int num_set_tag_values)  
     63{ 
     64  FileOptions opts(options); 
     65 
     66  // Get parallel settings 
     67  int parallel_mode; 
     68  FOErrorCode result = opts.match_option("PARALLEL", CGMparallelOptsNames,  
     69                                         parallel_mode); 
     70  if (FO_FAILURE == result) { 
     71    PRINT_ERROR( "Unexpected value for 'PARALLEL' option\n" ); 
     72    return CUBIT_FAILURE; 
     73  } 
     74  else if (FO_ENTITY_NOT_FOUND == result) { 
     75    parallel_mode = 0; 
     76  } 
     77 
     78  bool distrib = false; 
     79  bool surf_partition = false; 
     80  bool body_partition = false; 
     81  std::string partition_tag_name; 
     82  std::vector<int> partition_tag_vals; 
     83 
     84  // Get partition tag value(s), if any, and whether they're to be 
     85  result = opts.get_ints_option("PARTITION_VAL", partition_tag_vals); 
     86 
     87  // Get partition setting 
     88  result = opts.get_option("PARTITION", partition_tag_name); 
     89 
     90  if (FO_ENTITY_NOT_FOUND == result || partition_tag_name.empty()) { 
     91    partition_tag_name = PARALLEL_PARTITION_TAG_NAME; 
     92    distrib = true; 
     93  } 
     94  else { 
     95    if (partition_tag_name == "GEOM_DIMENSION") { 
     96      int geom_dim = 0; 
     97      for (std::vector<int>::iterator pit = partition_tag_vals.begin();  
     98           pit != partition_tag_vals.end(); pit++) { 
     99        geom_dim = *pit; 
     100        if (geom_dim == 2) surf_partition = true; // body & surface distribution 
     101        else if (geom_dim == 3) body_partition = true; // body only distribution 
     102      } 
     103      if (!surf_partition && !body_partition) { 
     104        PRINT_ERROR("Geometry dimension %d is not supported.\n", geom_dim); 
     105        return CUBIT_FAILURE; 
     106      } 
     107    } 
     108    else if (partition_tag_name == "PARALLEL_PARTITION") { 
     109    } 
     110 
     111    // distributed or assigned 
     112    result = opts.get_null_option("PARTITION_DISTRIBUTE"); 
     113    if (FO_SUCCESS == result) { 
     114      distrib = true; 
     115      body_partition = true; 
     116    } 
     117  } 
     118 
     119  // get MPI IO processor rank 
     120  int reader_rank; 
     121  result = opts.get_int_option("MPI_IO_RANK", reader_rank); 
     122  if (FO_ENTITY_NOT_FOUND == result) 
     123    reader_rank = 0; 
     124  else if (FO_SUCCESS != result) { 
     125    PRINT_ERROR( "Unexpected value for 'MPI_IO_RANK' option\n" ); 
     126    return CUBIT_FAILURE; 
     127  } 
     128 
     129  // now that we've parsed all the parallel options, make an instruction 
     130  // queue 
     131  std::vector<int> pa_vec; 
     132  bool is_reader = (reader_rank == (int) myPcomm->proc_config().proc_rank()); 
    48133   
    49   return result; 
     134  switch (parallel_mode) { 
     135 
     136  case POPT_READ: 
     137    pa_vec.push_back(PA_READ); 
     138    //pa_vec.push_back(PA_CHECK_GIDS_SERIAL); 
     139    pa_vec.push_back(PA_GET_ENTS); 
     140    break; 
     141   
     142  case POPT_DEFAULT: 
     143  case POPT_READ_DELETE: 
     144    pa_vec.push_back(PA_READ); 
     145    //pa_vec.push_back(PA_CHECK_GIDS_SERIAL); 
     146    pa_vec.push_back(PA_GET_ENTS); 
     147    pa_vec.push_back(PA_DELETE_NONLOCAL); 
     148    break; 
     149 
     150  case POPT_BCAST: 
     151    if (is_reader) { 
     152      pa_vec.push_back(PA_READ); 
     153      //pa_vec.push_back(PA_CHECK_GIDS_SERIAL); 
     154      pa_vec.push_back(PA_GET_ENTS); 
     155    } 
     156    pa_vec.push_back(PA_BROADCAST); 
     157    if (!is_reader) pa_vec.push_back(PA_GET_ENTS); 
     158    break; 
     159     
     160  case POPT_BCAST_DELETE: 
     161    if (is_reader) { 
     162      pa_vec.push_back(PA_READ); 
     163      //pa_vec.push_back(PA_CHECK_GIDS_SERIAL); 
     164      pa_vec.push_back(PA_GET_ENTS); 
     165    } 
     166    pa_vec.push_back(PA_BROADCAST); 
     167    //if (!is_reader) pa_vec.push_back(PA_GET_FILESET_ENTS); 
     168    pa_vec.push_back(PA_DELETE_NONLOCAL); 
     169    break; 
     170     
     171  case PORT_SCATTER: 
     172    if (is_reader) { 
     173      pa_vec.push_back(PA_READ); 
     174      //pa_vec.push_back(PA_CHECK_GIDS_SERIAL); 
     175      pa_vec.push_back(PA_GET_ENTS); 
     176    } 
     177    pa_vec.push_back(PA_SCATTER); 
     178    if (!is_reader) pa_vec.push_back(PA_GET_ENTS); 
     179    break; 
     180       
     181  case PORT_SCATTER_DELETE: 
     182    if (is_reader) { 
     183      pa_vec.push_back(PA_READ); 
     184      //pa_vec.push_back(PA_CHECK_GIDS_SERIAL); 
     185      pa_vec.push_back(PA_GET_ENTS); 
     186    } 
     187    pa_vec.push_back(PA_SCATTER); 
     188    if (is_reader) pa_vec.push_back(PA_DELETE_NONLOCAL); 
     189    else pa_vec.push_back(PA_GET_ENTS); 
     190    break; 
     191   
     192  case POPT_FORMAT: 
     193    PRINT_ERROR( "Access to format-specific parallel read not implemented.\n"); 
     194    return CUBIT_FAILURE; 
     195 
     196  case POPT_READ_PARALLEL: 
     197    PRINT_ERROR( "Partitioning for PARALLEL=READ_PARALLEL not supported yet.\n"); 
     198    return CUBIT_FAILURE; 
     199 
     200  default: 
     201    return CUBIT_FAILURE; 
     202  } 
     203 
     204  return load_file(file_name, parallel_mode,  
     205                   partition_tag_name, 
     206                   partition_tag_vals, distrib, pa_vec, opts, 
     207                   set_tag_name, set_tag_values, 
     208                   num_set_tag_values, 
     209                   reader_rank, surf_partition, body_partition 
     210                   ); 
    50211} 
    51212 
     213CubitStatus ParallelGeomTool::load_file(const char *file_name, 
     214                                        int parallel_mode,  
     215                                        std::string &partition_tag_name,  
     216                                        std::vector<int> &partition_tag_vals,  
     217                                        bool distrib, 
     218                                        std::vector<int> &pa_vec, 
     219                                        const FileOptions &opts, 
     220                                        const char* set_tag_name, 
     221                                        const int* set_tag_values, 
     222                                        const int num_set_tag_values, 
     223                                        const int reader_rank, 
     224                                        const bool surf_partition, 
     225                                        const bool body_partition 
     226                                        ) 
     227{ 
     228  // check file type 
     229  CubitString file_type; 
     230  //if (strstr(file_name, ".sab")) file_type = "ACIS_SAB"; 
     231  //else if (strstr(file_name, ".sat")) file_type = "ACIS_SAT"; 
     232  if (strstr(file_name, ".stp")) file_type = "STEP"; 
     233  else if (strstr(file_name, ".igs")) file_type = "IGES"; 
     234  else if (strstr(file_name, ".occ") || strstr(file_name, ".brep")) file_type = "OCC"; 
     235  else { 
     236    PRINT_ERROR("File type not known for file %s; skipping.\n", file_name); 
     237    return CUBIT_FAILURE; 
     238  } 
     239   
     240  // do the work by options 
     241  bool i_read = false; 
     242  std::vector<int>::iterator vit; 
     243  int i; 
     244  DLIList<RefEntity*> surf_entity_list, body_entity_list; 
     245  for (i = 1, vit = pa_vec.begin(); vit != pa_vec.end(); vit++, i++) { 
     246    CubitStatus tmp_result = CUBIT_SUCCESS; 
     247    switch (*vit) { 
     248//================== 
     249    case PA_READ: 
     250      i_read = true; 
     251      double tStart, tEnd; 
     252 
     253      if (debug) { 
     254        std::cout << "Reading file " << file_name << std::endl; 
     255        tStart = MPI_Wtime(); 
     256      } 
     257      tmp_result = GeometryQueryTool::instance()->import_solid_model(file_name, file_type.c_str()); 
     258 
     259      if (CUBIT_SUCCESS != tmp_result) { 
     260        PRINT_ERROR("Reading file %s failed.\n", file_name); 
     261        return CUBIT_FAILURE; 
     262      } 
     263      else if (debug) { 
     264        tEnd = MPI_Wtime(); 
     265        PRINT_INFO("Read time in proc %d is %f.\n", myPcomm->proc_config().proc_size(), 
     266                   tEnd - tStart); 
     267        PRINT_INFO("Read done.\n"); 
     268      } 
     269       
     270      break; 
     271 
     272//================== 
     273    case PA_GET_ENTS: 
     274      if (debug) std::cout << "Getting entities." << std::endl; 
     275       
     276      // get entities 
     277      if (body_partition) { 
     278        tmp_result = GeometryQueryTool::instance()->ref_entity_list("body", body_entity_list, CUBIT_FALSE); 
     279         
     280        if (CUBIT_SUCCESS != tmp_result) { 
     281          PRINT_ERROR("Getting body entities failed.\n"); 
     282          return CUBIT_FAILURE; 
     283        } 
     284      } 
     285      if (surf_partition) { 
     286        tmp_result = GeometryQueryTool::instance()->ref_entity_list("surface", surf_entity_list, CUBIT_FALSE); 
     287         
     288        if (CUBIT_SUCCESS != tmp_result) { 
     289          PRINT_ERROR("Getting surf entities failed.\n"); 
     290          return CUBIT_FAILURE; 
     291        } 
     292      } 
     293      if (debug) PRINT_INFO("Getting entities done.\n"); 
     294 
     295      break; 
     296       
     297//==================      
     298    case PA_DELETE_NONLOCAL: 
     299      if (debug) { 
     300        PRINT_INFO("Deleting nonlocal entities.\n"); 
     301        tStart = MPI_Wtime(); 
     302      } 
     303      
     304      tmp_result = delete_nonlocal_entities(partition_tag_name,  
     305                                            partition_tag_vals, 
     306                                            surf_entity_list, 
     307                                            body_entity_list, 
     308                                            distrib); 
     309      
     310      if (CUBIT_SUCCESS != tmp_result) { 
     311        PRINT_ERROR("Delete failed.\n"); 
     312        return CUBIT_FAILURE; 
     313      } 
     314      else if (debug) { 
     315        tEnd = MPI_Wtime(); 
     316        PRINT_INFO("Delete done.\n"); 
     317        PRINT_INFO("Delete time in proc %d is %f.\n", myPcomm->proc_config().proc_size(), 
     318                   tEnd - tStart); 
     319      } 
     320      break; 
     321 
     322//==================       
     323    case PA_BROADCAST: 
     324      // do the actual broadcast; if single-processor, ignore error 
     325      if (myPcomm->proc_config().proc_size() > 1) { 
     326        if (body_partition) { 
     327          if (debug) { 
     328            PRINT_INFO("Broadcasting body entities.\n"); 
     329            tStart = MPI_Wtime(); 
     330          } 
     331 
     332          tmp_result = myPcomm->broadcast_entities(reader_rank, body_entity_list); 
     333           
     334          if (CUBIT_SUCCESS != tmp_result) { 
     335            PRINT_ERROR("Broadcasting body entities failed.\n"); 
     336            return CUBIT_FAILURE; 
     337          } 
     338          else if (debug) { 
     339            tEnd = MPI_Wtime(); 
     340            PRINT_INFO("Bcast bodies done.\n"); 
     341            PRINT_INFO("Broadcast bodies time in proc %d is %f.\n", myPcomm->proc_config().proc_size(), 
     342                       tEnd - tStart); 
     343          } 
     344        } 
     345        if (surf_partition) { 
     346          if (debug) { 
     347            PRINT_INFO("Broadcasting surface entities.\n"); 
     348            tStart = MPI_Wtime(); 
     349          } 
     350          tmp_result = myPcomm->broadcast_entities(reader_rank, surf_entity_list); 
     351           
     352          if (CUBIT_SUCCESS != tmp_result) { 
     353            PRINT_ERROR("Broadcasting surface entities failed.\n"); 
     354            return CUBIT_FAILURE; 
     355          } 
     356          else if (debug) { 
     357            tEnd = MPI_Wtime(); 
     358            PRINT_INFO("Bcast surface done.\n"); 
     359            PRINT_INFO("Broadcast surfaces time in proc %d is %f.\n", myPcomm->proc_config().proc_size(), 
     360                       tEnd - tStart); 
     361          } 
     362        } 
     363      } 
     364       
     365      break; 
     366 
     367//==================       
     368    case PA_SCATTER: 
     369      // do the actual scatter 
     370      if (myPcomm->proc_config().proc_size() > 1) { 
     371        if (body_partition) { 
     372          if (debug) { 
     373            PRINT_INFO("Scattering body entities.\n"); 
     374            tStart = MPI_Wtime(); 
     375          } 
     376          tmp_result = myPcomm->scatter_entities(reader_rank, body_entity_list); 
     377           
     378          if (CUBIT_SUCCESS != tmp_result) { 
     379            PRINT_ERROR("Scattering body entities failed.\n"); 
     380            return CUBIT_FAILURE; 
     381          } 
     382          else if (debug) { 
     383            tEnd = MPI_Wtime(); 
     384            PRINT_INFO("Scatter bodies done.\n"); 
     385            PRINT_INFO("Scatter bodies time in proc %d is %f.\n", myPcomm->proc_config().proc_size(), 
     386                       tEnd - tStart); 
     387          } 
     388        } 
     389        if (surf_partition) { 
     390          if (debug) { 
     391            PRINT_INFO("Scattering surface entities.\n"); 
     392            tStart = MPI_Wtime(); 
     393          } 
     394          tmp_result = myPcomm->scatter_entities(reader_rank, surf_entity_list); 
     395           
     396          if (CUBIT_SUCCESS != tmp_result) { 
     397            PRINT_ERROR("Scattering surf entities failed.\n"); 
     398            return CUBIT_FAILURE; 
     399          } 
     400          else if (debug) { 
     401            tEnd = MPI_Wtime(); 
     402            PRINT_INFO("Scatter surfaces done;\n"); 
     403            PRINT_INFO("Scatter surfaces time in proc %d is %f.\n", myPcomm->proc_config().proc_size(), 
     404                       tEnd - tStart); 
     405          } 
     406        } 
     407      } 
     408      if (debug) PRINT_INFO("Scatter done.\n"); 
     409       
     410      break; 
     411 
     412//==================     
     413    default: 
     414      return CUBIT_FAILURE; 
     415    } 
     416  } 
     417 
     418  return CUBIT_SUCCESS; 
     419} 
     420 
     421CubitStatus ParallelGeomTool::delete_nonlocal_entities(std::string &ptag_name, 
     422                                                       std::vector<int> &ptag_vals, 
     423                                                       DLIList<RefEntity*> surf_entity_list, 
     424                                                       DLIList<RefEntity*> body_entity_list, 
     425                                                       const bool distribute) 
     426{ 
     427  unsigned int i; 
     428  CubitStatus result; 
     429  int proc_sz = myPcomm->proc_config().proc_size(); 
     430  int proc_rk = myPcomm->proc_config().proc_rank(); 
     431   
     432  if (distribute) { // Round-Robin 
     433    // for now, require that number of partition sets be greater 
     434    // than number of procs 
     435    if (body_entity_list.size() < proc_sz && 
     436        surf_entity_list.size() < proc_sz) { 
     437      result = CUBIT_FAILURE; 
     438      PRINT_ERROR("Number of procs greater than number of partitions."); 
     439      return CUBIT_FAILURE; 
     440    } 
     441     
     442    // delete unneeded surf entities 
     443    unsigned int tot_entity = surf_entity_list.size(); 
     444    unsigned int n_entity = tot_entity / proc_sz; 
     445    unsigned int n_entity_leftover = tot_entity % proc_sz; 
     446    unsigned int begin_entity = 0; 
     447 
     448    if (proc_rk < (int) n_entity_leftover) { 
     449      n_entity++; 
     450      begin_entity = n_entity * proc_rk; 
     451    } 
     452    else 
     453      begin_entity = proc_rk * n_entity + n_entity_leftover; 
     454 
     455    DLIList<RefEntity*> tmp_entity_list, delete_surf_list, delete_body_list; 
     456    unsigned int end_entity = begin_entity + n_entity; 
     457    for (i = 0; i < tot_entity; i++) { 
     458      if (i >= begin_entity && i < end_entity) tmp_entity_list.append(surf_entity_list[i]); 
     459      else { 
     460        delete_surf_list.append(surf_entity_list[i]); 
     461        //GeometryQueryTool::instance()->delete_RefEntity(surf_entity_list[i]); 
     462      } 
     463    } 
     464     
     465    // change partition surf ref entity list 
     466    myPcomm->partition_surf_list().clean_out(); 
     467    myPcomm->partition_surf_list() += tmp_entity_list; 
     468 
     469    // delete unneeded body entities 
     470    tot_entity = body_entity_list.size(); 
     471    n_entity = tot_entity / proc_sz; 
     472    n_entity_leftover = tot_entity % proc_sz; 
     473 
     474    if (proc_rk < (int) n_entity_leftover) { 
     475      n_entity++; 
     476      begin_entity = n_entity * proc_rk; 
     477    } 
     478    else 
     479      begin_entity = proc_rk * n_entity + n_entity_leftover; 
     480 
     481    end_entity = begin_entity + n_entity; 
     482    for (i = 0; i < tot_entity; i++) { 
     483      if (i >= begin_entity && i < end_entity) tmp_entity_list.append(body_entity_list[i]); 
     484      else { 
     485        delete_body_list.append(body_entity_list[i]); 
     486        //GeometryQueryTool::instance()->delete_RefEntity(body_entity_list[i]); 
     487      } 
     488    } 
     489 
     490    char pre_surf[100], pre_body[100]; 
     491    DLIList<CubitEntity*> tmp_surf_list, tmp_body_list; 
     492    if (debug) { 
     493      CAST_LIST_TO_PARENT(delete_surf_list, tmp_surf_list); 
     494      sprintf( pre_surf, "Deleted %d Surfaces: ", tmp_surf_list.size() ); 
     495      CAST_LIST_TO_PARENT(delete_body_list, tmp_body_list); 
     496      sprintf( pre_body, "Deleted %d Bodies: ", tmp_body_list.size() ); 
     497      CubitUtil::list_entity_ids( pre_surf, tmp_surf_list ); 
     498    } 
     499 
     500    unsigned int nDelete = delete_surf_list.size(); 
     501    for (i = 0; i < nDelete; i++) { 
     502      GeometryQueryTool::instance()->delete_RefEntity(surf_entity_list[i]); 
     503    } 
     504     
     505    if (debug) CubitUtil::list_entity_ids( pre_body, tmp_body_list ); 
     506     
     507    nDelete = delete_body_list.size(); 
     508    for (i = 0; i < nDelete; i++) { 
     509      GeometryQueryTool::instance()->delete_RefEntity(body_entity_list[i]); 
     510    } 
     511 
     512    // change partition surf ref entity list 
     513    myPcomm->partition_body_list().clean_out(); 
     514    myPcomm->partition_body_list() += tmp_entity_list; 
     515  } 
     516  else { 
     517    myPcomm->partition_surf_list().clean_out(); 
     518    myPcomm->partition_surf_list() += surf_entity_list; 
     519    myPcomm->partition_body_list().clean_out(); 
     520    myPcomm->partition_body_list() += body_entity_list; 
     521  } 
     522        
     523  if (debug) { 
     524    /* 
     525    surf_entity_list.clean_out(); 
     526    GeometryQueryTool::instance()->ref_entity_list("surface", surf_entity_list, CUBIT_FALSE); 
     527    body_entity_list.clean_out(); 
     528    GeometryQueryTool::instance()->ref_entity_list("body", body_entity_list, CUBIT_FALSE); 
     529    std::cerr << "My partition surf/body ref entity list size1: " 
     530    << surf_entity_list.size() << " " 
     531              << body_entity_list.size() << std::endl;*/ 
     532 
     533    std::cerr << "My partition surf/body ref entity list size: " 
     534              << myPcomm->partition_surf_list().size() << " " 
     535              << myPcomm->partition_body_list().size() << std::endl; 
     536  }     
     537   
     538  return CUBIT_SUCCESS; 
     539} 
  • cgm/trunk/geom/parallel/ParallelGeomTool.hpp

    r1061 r3108  
    22#define PARALLELGEOMTOOL_HPP 
    33 
    4 #include "TSTTG_CGM.h" 
     4#include <vector> 
     5#include "CubitDefines.h" 
     6#include "CGMParallelComm.hpp" 
     7//#include "ProcData.hpp" 
     8#include "FileOptions.hpp" 
     9//#include "CATag.hpp" 
     10//#include "CGMParallelComm.hpp" 
     11 
     12//class CGMTagManager; 
     13//class CGMParallelComm; 
    514 
    615class ParallelGeomTool  
    716{ 
    817public: 
    9   static ParallelGeomTool *instance(); 
     18 
     19  ParallelGeomTool(CGMTagManager* impl = NULL, CGMParallelComm *pc = NULL); 
     20 
     21  //static ParallelGeomTool *instance(); 
    1022 
    1123  enum ParallelLoadOption {BCAST, BCAST_AND_DELETE, SCATTER}; 
    1224   
    13     // load geometry to parallel processors, using ParallelLoadOption 
    14     // to determine how  
    15   int load_parallel(TSTTG_Instance geom, 
    16                     const char *name,  
    17                     int par_load_option); 
     25  // load a file 
     26  CubitStatus load_file(const char *file_names, const char *options, 
     27                        const char* set_tag_name = 0, 
     28                        const int* set_tag_values = 0, 
     29                        int num_set_tag_values = 0); 
    1830   
     31  CubitStatus load_file(const char *file_name, 
     32                        int parallel_mode,  
     33                        std::string &partition_tag_name,  
     34                        std::vector<int> &partition_tag_vals,  
     35                        bool distrib, 
     36                        std::vector<int> &pa_vec, 
     37                        const FileOptions &opts, 
     38                        const char* set_tag_name, 
     39                        const int* set_tag_values, 
     40                        const int num_set_tag_values, 
     41                        const int reader_rank, 
     42                        const bool surf_partition, 
     43                        const bool body_partition); 
     44   
     45  static const char *CGMparallelOptsNames[]; 
     46 
     47  static const char *CGMpartitionOptsNames[]; 
     48   
     49  enum CGMParallelOpts {POPT_NONE=0, POPT_READ, POPT_READ_DELETE, POPT_BCAST, 
     50                        POPT_BCAST_DELETE, PORT_SCATTER, 
     51                        PORT_SCATTER_DELETE, POPT_READ_PARALLEL, 
     52                        POPT_FORMAT, POPT_DEFAULT}; 
     53 
    1954private: 
    20   ParallelGeomTool() {} 
    2155 
    22   static ParallelGeomTool *instance_; 
     56  // surf ref entity list to be partitioned 
     57  DLIList<RefEntity*> msurf_entity_list; 
     58 
     59  // body ref entity list to be partitioned 
     60  DLIList<RefEntity*> mbody_entity_list; 
     61 
     62  CubitStatus delete_nonlocal_entities(std::string &ptag_name, 
     63                                       std::vector<int> &ptag_vals, 
     64                                       DLIList<RefEntity*> surf_entity_list, 
     65                                       DLIList<RefEntity*> body_entity_list, 
     66                                       bool distribute); 
     67   
     68  //CubitStatus delete_nonlocal_entities(MBEntityHandle file_set); 
     69 
     70 
     71  //static ParallelGeomTool *instance_; 
     72 
     73  CGMTagManager *cgmImpl; 
     74 
     75  // each reader can keep track of its own pcomm 
     76  CGMParallelComm *myPcomm; 
     77 
     78  //GeometryQueryTool *gqt; 
    2379}; 
    2480 
    25    
     81/* 
    2682inline ParallelGeomTool *ParallelGeomTool::instance() 
    2783{ 
    2884  if (!instance_) instance_ = new ParallelGeomTool(); 
    2985  return instance_; 
    30 } 
     86  }*/ 
    3187 
    3288#endif