User Tools

Site Tools


parallelization-howto

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
parallelization-howto [2010/03/20 17:11] – Added parallel vector assembly bpparallelization-howto [2012/12/17 19:39] (current) – [Example] mikael.ohman
Line 55: Line 55:
  
 ===== Example ===== ===== Example =====
-Following method illustrates how the assembly method for vector (load vector) is changed to support parallel assembly. Note that the implementation will work for both serial and parallel modes.+Fist, we have to create an instance of //ProblemCommunicator// class , named communicator, that will set up communication maps, provide communication buffers, etc. It should be an attribute of class representing our problem. This instance is conveniently created and initialized in our problem initialization routine. 
 +<code cpp> 
 +IRResultType 
 +MyEngngModel :: initializeFrom(InputRecord *ir) 
 +
 +    // problem specific part here 
 + 
 +    // initialize communicator if in parallel mode 
 +#ifdef __PARALLEL_MODE 
 +    // first create send and receive communication buffers, here we use fix-length 
 +    // static buffers (CBT_static) (size needs to be determined) 
 +    commBuff = new CommunicatorBuff(this->giveNumberOfProcesses(), CBT_static); 
 +    // and create communicator, later we will se how to use it 
 +    communicator = new ProblemCommunicator(this, commBuff, this->giveRank(), 
 +                                           this->giveNumberOfProcesses(), 
 +                                           ProblemCommMode__NODE_CUT); 
 + 
 +#endif 
 +
 +</code> 
 + 
 +Following method illustrates how the assembly method for vector (load vector) is changed to support parallel assembly. It uses communicator, an instance of //ProblemCommunicator// class, that provides a high level interface hiding all low-level communication. Note that the implementation will work for both serial and parallel modes.
  
 <code cpp> <code cpp>
Line 77: Line 98:
  
 #ifdef __PARALLEL_MODE #ifdef __PARALLEL_MODE
-        // parallel section (compiles only when --enable-poofem configure option used +        // parallel section (compiles only when parallel support is configured)
         // pack all data, need to pass pointer to engngModel, local vector, and packing method         // pack all data, need to pass pointer to engngModel, local vector, and packing method
         // this will call pack method for each remote partition         // this will call pack method for each remote partition
Line 181: Line 202:
  
 </code> </code>
 +Provided that the suitable sparse matrix representation is used (SMT_PetscMtrx, for example) and solver (ST_Petsc, for example), no modification to the sparse matrix assembly procedure and linear system solution is necessary. We can simply pass sparse matrix, local load vector, and solution vector to the solver and get results!
 +<code cpp>
 +void
 +MyEngngModel :: solveYourselfAt(TimeStep *tStep) {
 +
 +   // create components of characteristic equation
 +   stiffnessMatrix = CreateUsrDefSparseMtrx(sparseMtrxType);
 +   loadVector.resize(this->giveNumberOfEquations(EID_MomentumBalance));
 +   displacementVector.resize(this->giveNumberOfEquations(EID_MomentumBalance));
 +   loadVector.zero(); displacementVector.zero();
 +   
 +   // initialize profile of stiffness matrix
 +   stiffnessMatrix->buildInternalStructure(this, di, EID_MomentumBalance, EModelDefaultEquationNumbering());
 +   
 +   // assemble stiffness and load vector
 +   stiffnessMatrix->zero(); // zero stiffness matrix
 +   this->assemble( stiffnessMatrix, tStep, EID_MomentumBalance, ElasticStiffnessMatrix,
 +                   EModelDefaultEquationNumbering(), this->giveDomain(di) );
 +   this->assembleLoadVector (loadVector,this->giveDomain(di),
 +                             EID_MomentumBalance, tStep);                                 
 +                                    
 +   // get numerical method to solve the problem
 +   this->giveNumericalMethod(tStep);
 +   // solve the problem (yes, this solves linear system in parallel!)
 +   nMethod->solve(stiffnessMatrix, & loadVector, & displacementVector);
 +   // postprocess results update nodes, elements, compute strains, stresses, etc
 +   this->updateYourself( this->giveCurrentStep() );
 +   // and we are done!
 +}
 +</code> 
  
 ====== Further reading ====== ====== Further reading ======
parallelization-howto.1269101500.txt.gz · Last modified: 2010/03/20 17:11 by bp