From: Wolfgang Bangerth Date: Thu, 27 Jul 2000 09:33:25 +0000 (+0000) Subject: Use some parallelism when writing in gmv format. X-Git-Tag: v8.0.0~20209 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3bf2eae916007c04c466ac3677c6543fea816819;p=dealii.git Use some parallelism when writing in gmv format. git-svn-id: https://svn.dealii.org/trunk@3217 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/base/include/base/data_out_base.h b/deal.II/base/include/base/data_out_base.h index 01d7b382f0..db072abadb 100644 --- a/deal.II/base/include/base/data_out_base.h +++ b/deal.II/base/include/base/data_out_base.h @@ -311,11 +311,7 @@ class DataOutBase * is the same as for cells * in the triangulation. */ -#if ! ((__GNUC__==2) && (__GNUC_MINOR__==95)) Point vertices[GeometryInfo::vertices_per_cell]; -#else - Point vertices[1< + static void write_gmv_reorder_data_vectors (const vector > &patches, + vector > &data_vectors); }; @@ -1341,10 +1354,12 @@ class DataOutInterface : private DataOutBase private: /** - * Standard output format. - * Use this format, if output format default_format is - * requested. It can be changed by the @p{set_format} - * function or in a parameter file. + * Standard output format. Use + * this format, if output format + * default_format is + * requested. It can be changed + * by the @p{set_format} function + * or in a parameter file. */ OutputFormat default_fmt; @@ -1383,7 +1398,7 @@ class DataOutInterface : private DataOutBase * changed by using the @p{set_flags} * function. */ - GmvFlags gmv_flags; + GmvFlags gmv_flags; }; diff --git a/deal.II/base/source/data_out_base.cc b/deal.II/base/source/data_out_base.cc index bfcc08e83a..879ca50f58 100644 --- a/deal.II/base/source/data_out_base.cc +++ b/deal.II/base/source/data_out_base.cc @@ -14,19 +14,20 @@ #include #include +#include + #include #include #include #include -// egcs does not understand this at present. -// -// template -// DataOut::Patch::Patch () : -// n_subdivisions (1) -// // all the rest has a constructor of its own -// {}; +template +DataOutBase::Patch::Patch () : + n_subdivisions (1) + // all the other data has a + // constructor of its own +{}; template @@ -40,7 +41,7 @@ void DataOutBase::write_ucd (const vector > &patches, Assert (patches.size() > 0, ExcNoPatches()); const unsigned int n_data_sets = data_names.size(); - + // first count the number of cells // and cells for later use unsigned int n_cells = 0, @@ -1341,6 +1342,13 @@ void DataOutBase::write_gmv (const vector > &patches, Assert (patches.size() > 0, ExcNoPatches()); const unsigned int n_data_sets = data_names.size(); + // check against # of data sets in + // first patch. checks against all + // other patches are made in + // write_gmv_reorder_data_vectors + Assert (n_data_sets == patches[0].data.m(), + ExcUnexpectedNumberOfDatasets (patches[0].data.m(), n_data_sets)); + /////////////////////// // preamble @@ -1379,6 +1387,35 @@ void DataOutBase::write_gmv (const vector > &patches, }; + // in gmv format the vertex + // coordinates and the data have an + // order that is a bit unpleasant + // (first all x coordinates, then + // all y coordinate, ...; first all + // data of variable 1, then + // variable 2, etc), so we have to + // copy the data vectors a bit around + // + // note that we copy vectors when + // looping over the patches since we + // have to write them one variable + // at a time and don't want to use + // more than one loop + // + // this copying of data vectors can + // be done while we already output + // the vertices, so do this on a + // separate thread and when wanting + // to write out the data, we wait + // for that thread to finish + vector > data_vectors (n_data_sets, + vector (n_nodes)); + Threads::ThreadManager thread_manager; + Threads::spawn (thread_manager, + Threads::encapsulate (&DataOutBase::template + write_gmv_reorder_data_vectors) + .collect_args(patches, data_vectors)); + /////////////////////////////// // first make up a list of used // vertices along with their @@ -1573,98 +1610,23 @@ void DataOutBase::write_gmv (const vector > &patches, // data output. out << "variable" << endl; - // since here as with the vertex - // coordinates the order is a bit - // unpleasant (first all data of - // variable 1, then variable 2, etc) - // we have to copy them a bit around - // - // note that we copy vectors when - // looping over the patches since we - // have to write them one variable - // at a time and don't want to use - // more than one loop - if (true) - { - vector > data_vectors (n_data_sets, - vector (n_nodes)); - // loop over all patches - unsigned int next_value = 0; - for (typename vector >::const_iterator patch=patches.begin(); - patch != patches.end(); ++patch) - { - const unsigned int n_subdivisions = patch->n_subdivisions; - - Assert (patch->data.m() == n_data_sets, - ExcUnexpectedNumberOfDatasets (patch->data.m(), n_data_sets)); - Assert (patch->data.n() == (dim==1 ? - n_subdivisions+1 : - (dim==2 ? - (n_subdivisions+1)*(n_subdivisions+1) : - (dim==3 ? - (n_subdivisions+1)*(n_subdivisions+1)*(n_subdivisions+1) : - 0))), - ExcInvalidDatasetSize (patch->data.n(), n_subdivisions+1)); - - switch (dim) - { - case 1: - { - for (unsigned int i=0; idata(data_set,i); - - break; - }; - - case 2: - { - for (unsigned int i=0; idata(data_set,i*(n_subdivisions+1) + j); - ++next_value; - }; - - break; - }; - - case 3: - { - for (unsigned int i=0; idata(data_set, - (i*(n_subdivisions+1)+j)*(n_subdivisions+1)+k); - ++next_value; - }; + // now write the data vectors to + // @p{out} first make sure that all + // data is in place + thread_manager.wait (); - break; - }; - - default: - Assert (false, ExcNotImplemented()); - }; - }; - - // now write the data vectors to @p{out} - // the '1' means: node data (as opposed - // to cell data, which we do not - // support explicitely here) - for (unsigned int data_set=0; data_set(out, " ")); - out << endl - << endl; - }; + // then write data. + // the '1' means: node data (as opposed + // to cell data, which we do not + // support explicitely here) + for (unsigned int data_set=0; data_set(out, " ")); + out << endl + << endl; }; @@ -1681,6 +1643,95 @@ void DataOutBase::write_gmv (const vector > &patches, }; + +template +void DataOutBase::write_gmv_reorder_data_vectors (const vector > &patches, + vector > &data_vectors) +{ + // unlike in the main function, we + // don't have here the data_names + // field, so we initialize it with + // the number of data sets in the + // first patch. the equivalence of + // these two definitions is checked + // in the main function. + const unsigned int n_data_sets = patches[0].data.m(); + + Assert (data_vectors.size() == n_data_sets, + ExcInternalError()); + + // loop over all patches + unsigned int next_value = 0; + for (typename vector >::const_iterator patch=patches.begin(); + patch != patches.end(); ++patch) + { + const unsigned int n_subdivisions = patch->n_subdivisions; + + Assert (patch->data.m() == n_data_sets, + ExcUnexpectedNumberOfDatasets (patch->data.m(), n_data_sets)); + Assert (patch->data.n() == (dim==1 ? + n_subdivisions+1 : + (dim==2 ? + (n_subdivisions+1)*(n_subdivisions+1) : + (dim==3 ? + (n_subdivisions+1)*(n_subdivisions+1)*(n_subdivisions+1) : + 0))), + ExcInvalidDatasetSize (patch->data.n(), n_subdivisions+1)); + + switch (dim) + { + case 1: + { + for (unsigned int i=0; idata(data_set,i); + + break; + }; + + case 2: + { + for (unsigned int i=0; idata(data_set,i*(n_subdivisions+1) + j); + ++next_value; + }; + + break; + }; + + case 3: + { + for (unsigned int i=0; idata(data_set, + (i*(n_subdivisions+1)+j)*(n_subdivisions+1)+k); + ++next_value; + }; + + break; + }; + + default: + Assert (false, ExcNotImplemented()); + }; + }; + + for (unsigned int data_set=0; data_set::parse_parameters (ParameterHandler &prm) // explicit instantiations. functions in DataOutBase are instantiated by // the respective functions in DataOut_Interface template class DataOutInterface; - +template class DataOutBase::Patch;