[MOAB-dev] r2209 - in MOAB/trunk: parallel tools/iMesh
kraftche at mcs.anl.gov
kraftche at mcs.anl.gov
Tue Nov 4 13:15:01 CST 2008
Author: kraftche
Date: 2008-11-04 13:15:01 -0600 (Tue, 04 Nov 2008)
New Revision: 2209
Modified:
MOAB/trunk/parallel/MBParallelComm.cpp
MOAB/trunk/parallel/MBParallelComm.hpp
MOAB/trunk/tools/iMesh/iMeshP_MOAB.cpp
Log:
iMeshP_loadFile & iMeshP_saveFile
Modified: MOAB/trunk/parallel/MBParallelComm.cpp
===================================================================
--- MOAB/trunk/parallel/MBParallelComm.cpp 2008-11-04 17:42:04 UTC (rev 2208)
+++ MOAB/trunk/parallel/MBParallelComm.cpp 2008-11-04 19:15:01 UTC (rev 2209)
@@ -3725,6 +3725,66 @@
return result;
}
+MBErrorCode MBParallelComm::set_partitioning( MBEntityHandle set)
+{
+ MBErrorCode rval;
+ MBTag prtn_tag;
+ rval = mbImpl->tag_create( PARTITIONING_PCOMM_TAG_NAME,
+ sizeof(int),
+ MB_TAG_SPARSE,
+ MB_TYPE_INTEGER,
+ prtn_tag,
+ 0, true );
+ if (MB_SUCCESS != rval)
+ return rval;
+
+ // get my id
+ MBParallelComm* pcomm_arr[MAX_SHARING_PROCS];
+ MBTag pc_tag = pcomm_tag(mbImpl, false);
+ if (0 == pc_tag)
+ return MB_FAILURE;
+ MBErrorCode result = mbImpl->tag_get_data(pc_tag, 0, 0, pcomm_arr);
+ if (MB_SUCCESS != result)
+ return MB_FAILURE;
+ int id = std::find(pcomm_arr,pcomm_arr+MAX_SHARING_PROCS,this) - pcomm_arr;
+ if (id == MAX_SHARING_PROCS)
+ return MB_FAILURE;
+
+ MBEntityHandle old = partitioningSet;
+ if (old) {
+ rval = mbImpl->tag_delete_data( prtn_tag, &old, 1 );
+ if (MB_SUCCESS != rval)
+ return rval;
+ partitioningSet = 0;
+ }
+
+ if (!set)
+ return MB_SUCCESS;
+
+ MBRange contents;
+ if (old) {
+ rval = mbImpl->get_entities_by_handle( old, contents );
+ if (MB_SUCCESS != rval)
+ return rval;
+ }
+ else {
+ contents = partition_sets();
+ }
+
+ rval = mbImpl->add_entities( set, contents );
+ if (MB_SUCCESS != rval)
+ return rval;
+
+ // store pcomm id on new partition set
+ rval = mbImpl->tag_set_data( prtn_tag, &set, 1, &id );
+ if (MB_SUCCESS != rval)
+ return rval;
+
+ partitioningSet = set;
+ return MB_SUCCESS;
+}
+
+
//! return all the entities in parts owned locally
MBErrorCode MBParallelComm::get_part_entities(MBRange &ents, int dim)
{
Modified: MOAB/trunk/parallel/MBParallelComm.hpp
===================================================================
--- MOAB/trunk/parallel/MBParallelComm.hpp 2008-11-04 17:42:04 UTC (rev 2208)
+++ MOAB/trunk/parallel/MBParallelComm.hpp 2008-11-04 19:15:01 UTC (rev 2209)
@@ -362,7 +362,7 @@
bool shared_test = false );
MBEntityHandle get_partitioning() const { return partitioningSet; }
- void set_partitioning( MBEntityHandle h ) { partitioningSet = h; }
+ MBErrorCode set_partitioning( MBEntityHandle h );
MBErrorCode get_global_part_count( int& count_out ) const;
MBErrorCode get_part_owner( int part_id, int& owner_out ) const;
MBErrorCode get_part_id( MBEntityHandle part, int& id_out ) const;
Modified: MOAB/trunk/tools/iMesh/iMeshP_MOAB.cpp
===================================================================
--- MOAB/trunk/tools/iMesh/iMeshP_MOAB.cpp 2008-11-04 17:42:04 UTC (rev 2208)
+++ MOAB/trunk/tools/iMesh/iMeshP_MOAB.cpp 2008-11-04 19:15:01 UTC (rev 2209)
@@ -1403,6 +1403,63 @@
int *err )
{ FIXME; RETURN(iBase_NOT_SUPPORTED); }
+static std::string append_option( const char* options,
+ int options_len,
+ const char* option,
+ const char* default_value = 0 )
+{
+ std::string::size_type i;
+
+ // construct a std::string containing at least the leading
+ // separator.
+ std::string opt( options, options_len );
+ if (opt.empty())
+ opt = ";";
+ char sep = opt[0];
+
+ // make sure that the separator is ok (not contained in the option)
+ const char separators[] = ";:,.!@$#%&*^|/\"'\\~%";
+ if (strchr(option,sep) || (default_value && (sep == '=' || strchr(default_value,sep)))) {
+ // need a new separator.
+ int c, e = sizeof(separators)-1;
+ for (c = 0; c < e; ++c)
+ if (!strchr(opt.c_str(),separators[c]) &&
+ !strchr(option,separators[c]) &&
+ (!default_value || !strchr(default_value,separators[c])))
+ break;
+ if (c == e)
+ return std::string();
+
+ i = 0;
+ while (std::string::npos != (i = opt.find(sep,i)))
+ opt[i] = separators[c];
+ sep = separators[c];
+ }
+
+ // search for the required option
+ std::string search(&sep,1);
+ search += option;
+ const std::string::size_type sl = search.length();
+ i = opt.find( search );
+ while (i != std::string::npos) {
+ std::string::size_type end = i + sl;
+ if (end == opt.size() || opt[end] == sep || opt[end] == '=')
+ break;
+ i = end;
+ }
+
+ // if string doesn't already contain the option, append it.
+ if (i == std::string::npos) {
+ opt += search;
+ if (default_value) {
+ opt += "=";
+ opt += default_value;
+ }
+ }
+
+ return opt;
+}
+
void iMeshP_load( iMesh_Instance instance,
const iMeshP_PartitionHandle partition,
const iBase_EntitySetHandle entity_set_handle,
@@ -1411,8 +1468,41 @@
int *err,
int name_len,
int options_len )
-{ FIXME; RETURN(iBase_NOT_SUPPORTED); }
+{
+ MBErrorCode rval;
+ // make sure 'options' string contains 'PARALLEL'
+ std::string opt = append_option( options, options_len, "PARALLEL" );
+ if (opt.empty())
+ RETURN(iBase_FAILURE);
+
+ // load the file
+ iMesh_load( instance, entity_set_handle, name, opt.c_str(), err, name_len, opt.length() );
+ if (*err) return;
+
+ // look for most recent pcomm instance
+ MBParallelComm* pcomm = 0;
+ for (int i = 0; i < MAX_SHARING_PROCS; ++i) {
+ MBParallelComm* tmp_pcomm = MBParallelComm::get_pcomm( MBI, i );
+ if (tmp_pcomm)
+ pcomm = tmp_pcomm;
+ }
+ if (!pcomm) {
+ RETURN (iBase_FAILURE);
+ }
+
+ // if user-specified partition set, use it instead
+ if (partition) {
+ MBEntityHandle old_partition = pcomm->get_partitioning();
+ if (old_partition)
+ MBI->delete_entities( &old_partition, 1 );
+ rval = pcomm->set_partitioning( itaps_cast<MBEntityHandle>(partition) );
+ CHKERR(rval);
+ }
+
+ RETURN (iBase_SUCCESS);
+}
+
void iMeshP_save( iMesh_Instance instance,
const iMeshP_PartitionHandle partition,
const iBase_EntitySetHandle entity_set_handle,
@@ -1421,11 +1511,18 @@
int *err,
const int name_len,
int options_len )
-{ FIXME; RETURN(iBase_NOT_SUPPORTED); }
+{
+ MBEntityHandle set;
+ set = entity_set_handle ? itaps_cast<MBEntityHandle>(entity_set_handle)
+ : itaps_cast<MBEntityHandle>(partition);
+ iMesh_save( instance, itaps_cast<iBase_EntitySetHandle>(set),
+ name, options, err, name_len, options_len );
+}
+
// Map from processes to parts:
// Given a partition handle and a process rank,
// return the part handles owned by the process.
More information about the moab-dev
mailing list