/[escript]/branches/trilinos_from_5897/dudley/src/NodeMapping.cpp
ViewVC logotype

Diff of /branches/trilinos_from_5897/dudley/src/NodeMapping.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 6008 by caltinay, Mon Feb 22 06:59:27 2016 UTC revision 6009 by caltinay, Wed Mar 2 04:13:26 2016 UTC
# Line 17  Line 17 
17  #include "NodeMapping.h"  #include "NodeMapping.h"
18  #include "Util.h"  #include "Util.h"
19    
20    namespace dudley {
21    
22  Dudley_NodeMapping *Dudley_NodeMapping_alloc(dim_t numNodes, index_t * target, index_t unused)  Dudley_NodeMapping *Dudley_NodeMapping_alloc(dim_t numNodes, index_t * target, index_t unused)
23  {  {
24      dim_t i;      dim_t i;
# Line 25  Dudley_NodeMapping *Dudley_NodeMapping_a Line 27  Dudley_NodeMapping *Dudley_NodeMapping_a
27      /*  allocate the return value */      /*  allocate the return value */
28      min_target = Dudley_Util_getFlaggedMinInt(1, numNodes, target, unused);      min_target = Dudley_Util_getFlaggedMinInt(1, numNodes, target, unused);
29      if (min_target < 0)      if (min_target < 0)
30      {          throw DudleyException("Dudley_NodeMapping_alloc: target has negative entry.");
31      Dudley_setError(VALUE_ERROR, "Dudley_NodeMapping_alloc: target has negative entry.");  
     return NULL;  
     }  
32      /* now we assume min_target=0! */      /* now we assume min_target=0! */
33      max_target = Dudley_Util_getFlaggedMaxInt(1, numNodes, target, unused);      max_target = Dudley_Util_getFlaggedMaxInt(1, numNodes, target, unused);
34      numTargets = min_target <= max_target ? max_target + 1 : 0;      numTargets = min_target <= max_target ? max_target + 1 : 0;
35      out = new Dudley_NodeMapping;      out = new Dudley_NodeMapping;
36      if (!Dudley_checkPtr(out))      out->reference_counter = 1;
37      {      out->unused = unused;
38      out->reference_counter = 1;      out->numNodes = numNodes;
39      out->unused = unused;      out->numTargets = numTargets;
40      out->numNodes = numNodes;      out->map = new  index_t[numTargets];
41      out->numTargets = numTargets;      out->target = new  index_t[numNodes];
     out->map = new  index_t[numTargets];  
     out->target = new  index_t[numNodes];  
     if (!(Dudley_checkPtr(out->target) || Dudley_checkPtr(out->map)))  
     {  
42  #pragma omp parallel  #pragma omp parallel
43          {      {
44  #pragma omp for private(i)  #pragma omp for private(i)
45          for (i = 0; i < numTargets; ++i)          for (i = 0; i < numTargets; ++i)
46              out->map[i] = -1;              out->map[i] = -1;
47  #pragma omp for private(i)  #pragma omp for private(i)
48          for (i = 0; i < numNodes; ++i)          for (i = 0; i < numNodes; ++i) {
49          {              out->target[i] = target[i];
50              out->target[i] = target[i];              if (target[i] != unused)
51              if (target[i] != unused)                  out->map[out->target[i]] = i;
52              out->map[out->target[i]] = i;          }
         }  
53  #pragma omp for private(i)  #pragma omp for private(i)
54          for (i = 0; i < numTargets; ++i)          for (i = 0; i < numTargets; ++i) {
55          {              if (out->map[i] == -1) {
56              if (out->map[i] == -1)                  throw DudleyException("Dudley_NodeMapping_alloc: target does not define a continuous labeling.");
57              {              }
58              Dudley_setError(VALUE_ERROR,          }
                     "Dudley_NodeMapping_alloc: target does not define a continuous labeling.");  
             }  
         }  
         }  
     }  
     if (!Dudley_noError())  
     {  
         Dudley_NodeMapping_free(out);  
     }  
   
59      }      }
60      return out;      return out;
61  }  }
62    
63  void Dudley_NodeMapping_free(Dudley_NodeMapping * in)  void Dudley_NodeMapping_free(Dudley_NodeMapping* in)
64  {  {
65      if (in != NULL)      if (in != NULL) {
66      {          in->reference_counter--;
67      in->reference_counter--;          if (in->reference_counter <= 0) {
68      if (in->reference_counter <= 0)              delete[] in->target;
69      {              delete[] in->map;
70          delete[] in->target;              delete in;
71          delete[] in->map;          }
         delete in;  
     }  
72      }      }
73  }  }
74    
75  Dudley_NodeMapping *Dudley_NodeMapping_getReference(Dudley_NodeMapping * in)  Dudley_NodeMapping *Dudley_NodeMapping_getReference(Dudley_NodeMapping* in)
76  {  {
77      if (in != NULL)      if (in != NULL)
78      in->reference_counter++;          in->reference_counter++;
79      return in;      return in;
80  }  }
81    
82    } // namespace dudley
83    

Legend:
Removed from v.6008  
changed lines
  Added in v.6009

  ViewVC Help
Powered by ViewVC 1.1.26