MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
mtdataman.h
Go to the documentation of this file.
1 /* $Header: /var/cvs/mbdyn/mbdyn/mbdyn-1.0/mbdyn/base/mtdataman.h,v 1.36 2017/01/12 14:46:10 masarati Exp $ */
2 /*
3  * MBDyn (C) is a multibody analysis code.
4  * http://www.mbdyn.org
5  *
6  * Copyright (C) 1996-2017
7  *
8  * Pierangelo Masarati <masarati@aero.polimi.it>
9  * Paolo Mantegazza <mantegazza@aero.polimi.it>
10  *
11  * Dipartimento di Ingegneria Aerospaziale - Politecnico di Milano
12  * via La Masa, 34 - 20156 Milano, Italy
13  * http://www.aero.polimi.it
14  *
15  * Changing this copyright notice is forbidden.
16  *
17  * This program is free software; you can redistribute it and/or modify
18  * it under the terms of the GNU General Public License as published by
19  * the Free Software Foundation (version 2 of the License).
20  *
21  *
22  * This program is distributed in the hope that it will be useful,
23  * but WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25  * GNU General Public License for more details.
26  *
27  * You should have received a copy of the GNU General Public License
28  * along with this program; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */
31 
32 /* gestore dei dati */
33 
34 #ifndef MTDATAMAN_H
35 #define MTDATAMAN_H
36 
37 #ifdef USE_MULTITHREAD
38 
39 #include "ac/pthread.h" /* includes POSIX semaphores */
40 
41 #include "dataman.h"
42 #include "spmh.h"
43 #include "naivemh.h"
44 class Solver;
45 
46 /* MultiThreadDataManager - begin */
47 
48 class MultiThreadDataManager : public DataManager {
49 protected:
50  // nThreads is now in DataManager
51  enum {
52  ASS_UNKNOWN = -1,
53 
54  ASS_CC, /* use native column-compressed form */
55  ASS_NAIVE, /* use native H-P sparse solver */
56 
57  ASS_LAST
58  } AssMode;
59 
60  /* steps of CC computation */
61  enum {
62  CC_NO,
63  CC_FIRST,
64  CC_YES
65  } CCReady;
66 
67  /* per-thread specific data */
68  struct ThreadData {
69  MultiThreadDataManager *pDM;
70  integer threadNumber;
71  pthread_t thread;
72  sem_t sem;
73  clock_t cputime;
74 
75  mutable MT_VecIter<Elem *> ElemIter;
76 
77  VariableSubMatrixHandler *pWorkMatA; /* Working SubMatrix */
78  VariableSubMatrixHandler *pWorkMatB;
79  VariableSubMatrixHandler *pWorkMat; /* same as pWorkMatA */
80  MySubVectorHandler *pWorkVec;
81 
82  /* for CC assembly */
84 
85  /* for Naive assembly */
86  NaiveMatrixHandler** ppNaiveJacHdl;
87  AO_TS_t* lock;
88 
89  VectorHandler* pResHdl;
90  MatrixHandler* pMatA;
91  MatrixHandler* pMatB;
92  doublereal dCoef;
93  } *thread_data;
94 
95  enum DataManagerOp {
96  OP_UNKNOWN = -1,
97 
98  OP_ASSJAC_CC,
99 
100  OP_ASSJAC_NAIVE,
101  OP_SUM_NAIVE,
102 
103  /* used only #ifdef MBDYN_X_MT_ASSRES */
104  OP_ASSRES,
105 
106  /* not used yet */
107  OP_ASSMATS,
108  OP_BEFOREPREDICT,
109  OP_AFTERPREDICT,
110  OP_AFTERCONVERGENCE,
111  /* end of not used yet */
112 
113  OP_EXIT,
114 
115  LAST_OP
116  } op;
117 
118  /* will be replaced by barriers ... */
119  unsigned thread_count;
120 
121  /* this can be replaced by a barrier ... */
122  pthread_mutex_t thread_mutex;
123  pthread_cond_t thread_cond;
124 
125  /* this is used to propagate ErrMatrixRebuild ... */
126  AO_TS_t propagate_ErrMatrixRebuild;
127 
128  void EndOfOp(void);
129 
130  /* thread function */
131  static void *thread(void *arg);
132  static void thread_cleanup(ThreadData *arg);
133 
134  /* starts the helper threads */
135  void ThreadSpawn(void);
136  clock_t ThreadDestroy(void);
137 
138  /* specialized assembly */
139  virtual void CCAssJac(MatrixHandler& JacHdl, doublereal dCoef);
140  virtual void NaiveAssJac(MatrixHandler& JacHdl, doublereal dCoef);
141 public:
142  /* costruttore - legge i dati e costruisce le relative strutture */
143  MultiThreadDataManager(MBDynParser& HP,
144  unsigned OF,
145  Solver* pS,
146  doublereal dInitialTime,
147  const char* sOutputFileName,
148  const char* sInputFileName,
149  bool bAbortAfterInput,
150  unsigned nt);
151 
152  /* distruttore */
153  virtual ~MultiThreadDataManager(void);
154 
155  /* Assembla lo jacobiano */
156  virtual void AssJac(MatrixHandler& JacHdl, doublereal dCoef);
157 
158 #ifdef MBDYN_X_MT_ASSRES
159  /* Assembla il residuo */
160  virtual void AssRes(VectorHandler &ResHdl, doublereal dCoef)
161  throw(ChangedEquationStructure);
162 #endif /* MBDYN_X_MT_ASSRES */
163 
164  /* additional CPU time, if any */
165  virtual clock_t GetCPUTime(void) const;
166 };
167 
168 /* MultiThreadDataManager - end */
169 
170 #endif /* USE_MULTITHREAD */
171 
172 #endif /* MTDATAMAN_H */
173 
virtual void AssRes(VectorHandler &ResHdl, doublereal dCoef)
Definition: elman.cc:498
virtual void AssJac(MatrixHandler &JacHdl, doublereal dCoef)
Definition: elman.cc:392
virtual clock_t GetCPUTime(void) const
Definition: dataman.h:254
Definition: solver.h:78
double doublereal
Definition: colamd.c:52
long int integer
Definition: colamd.c:51