Main Page | Namespace List | Class Hierarchy | Class List | File List | Class Members | File Members

src/expde/evpar/evpar.cc

Go to the documentation of this file.
00001 //    expde: expression templates for partial differential equations.
00002 //    Copyright (C) 2001  Christoph Pflaum
00003 //    This program is free software; you can redistribute it and/or modify
00004 //    it under the terms of the GNU General Public License as published by
00005 //    the Free Software Foundation; either version 2 of the License, or
00006 //    (at your option) any later version.
00007 //
00008 //    This program is distributed in the hope that it will be useful,
00009 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011 //    GNU General Public License for more details.
00012 //
00013 //                 SEE  Notice1.doc made by 
00014 //                 LAWRENCE LIVERMORE NATIONAL LABORATORY
00015 //
00016 
00017 // ------------------------------------------------------------
00018 //
00019 // evpar.cc
00020 //
00021 // ------------------------------------------------------------
00022 
00023 
00024 // Include level 0:
00025 
00026 #ifdef COMP_GNUOLD
00027  #include <iostream.h>
00028  #include <fstream.h>
00029  #include <math.h>
00030  #include <time.h>
00031 #else
00032  #include <iostream>
00033  #include <fstream>
00034  #include <cmath>
00035  #include <ctime>
00036 #endif 
00037 
00038 
00039 // Include level 0:
00040 #include "../parser.h"
00041 
00042 // Include level 1:
00043 #include "../paramete.h"
00044 #include "../abbrevi.h"
00045 #include "../math_lib/math_lib.h"
00046 
00047 // Include level 2:
00048 #include "../basic/basic.h"
00049 
00050 // Include level 3:
00051 #include "../domain/domain.h"
00052 
00053 // Include level 4:
00054 #include "../formulas/boundy.h"
00055 #include "../formulas/loc_sten.h"
00056 
00057 
00058 // Include level 5.0
00059 #include "../grid/gpar.h"
00060 #include "../grid/parallel.h"
00061 #include "../grid/mgcoeff.h"
00062 #include "../grid/sto_man.h"
00063 #include "../grid/gridbase.h"
00064 #include "../grid/grid.h"
00065 
00066 // Include level 5.1
00067 #include "evpar.h"
00068 
00069 
00070 
00071 Evaluation_Parallelization_object::Evaluation_Parallelization_object(
00072                                    Grid *g, int max_v) : 
00073   grid(g) {
00074   //  max_v is maximal number of variables
00075   max_var = max_v;
00076   max_level  = g->Max_level();
00077   storage_of_update_type = new type_of_update[max_level*(max_var+1)];
00078   for(int i=max_level*(max_var+1)-1;i>=0;--i) {
00079     storage_of_update_type[i] = full_update;
00080   }
00081   array_vars = new bool[max_var];
00082   array_num  = new int[max_var];
00083   array_vars_other = new bool[max_var];
00084   array_num_other  = new int[max_var];
00085   // this formula is connected with the formula
00086   // dir_sons reordering_formula(dir_sons d);
00087 
00088   Parallel_GS_formula[0] = Edir;
00089   Parallel_GS_formula[1] = Ndir;
00090   Parallel_GS_formula[2] = Tdir;
00091   Parallel_GS_formula[3] = Sdir;
00092 
00093   Parallel_GS_formula[4] = Wdir;
00094   Parallel_GS_formula[5] = Ndir;
00095   Parallel_GS_formula[6] = Ddir;
00096   Parallel_GS_formula[7] = Sdir;
00097 };
00098 
00099 void Evaluation_Parallelization_object::Start_evaluation_seriel(
00100                 const Run_type_object rob, const int l, const int ss,
00101                 const int num_ops) {
00102   size_stencil = ss;
00103   run_object = rob;
00104   level=l;
00105   status=0;
00106   number_ops=num_ops;
00107 }
00108 
00109 void Evaluation_Parallelization_object::StartA_varcon_evaluation(int l) {
00110   level=l;
00111   for(int i=0;i<max_var;++i) {
00112     array_vars[i]=false;
00113   }
00114 };
00115 
00116 
00117 void Evaluation_Parallelization_object::StartB_varcon_evaluation() {
00118   type_of_update type_upd;
00119 
00120   anz_num=0;
00121 
00122   for(int i=0;i<max_var;++i) {
00123     if(array_vars[i]) {
00124       type_upd = Give_type_of_update(i,level);
00125       if(type_upd!=full_update) {
00126         array_num[anz_num]=i;
00127         ++anz_num;
00128       }
00129       Set_type_of_update(i,level,full_update);
00130     }
00131   }
00132   grid->Update_Variable_no_full(array_num,anz_num,level);
00133 };
00134 
00135 void Evaluation_Parallelization_object::StartA_evaluation(
00136                 const Run_type_object rob, const int l, const int ss,
00137                 const int num_ops) {
00138   size_stencil = ss;
00139   run_object = rob;
00140   level=l;
00141   status=0;
00142   number_ops=num_ops;
00143 
00144   if(size_stencil>1) {
00145     other_is_fine=other_is_coarse=false;
00146     for(int i=0;i<max_var;++i) {
00147       array_vars[i]=array_vars_other[i]=false;
00148     }
00149     //    grid->Full_update_Variable();
00150   }
00151 }
00152 
00153 
00154 void Evaluation_Parallelization_object::StartB_evaluation(
00155                                         const int number_variable,
00156                                         const bool GS_expr) {
00157   anz_num=anz_num_other=0;
00158 
00159   /*
00160   //test
00161   GS_expression = false;
00162   if(size_stencil>1) {
00163     // for left hand side:
00164     for(int i=0;i<max_var;++i) {
00165       if(array_vars[i]) {
00166         if(i==number_variable)
00167           GS_expression = true;
00168       }
00169     }
00170   }
00171   if(GS_expression!=GS_expr) {
00172     if(grid->Give_my_rank()==0)
00173       cout << "\n error! " << GS_expr << endl;
00174   }
00175   */
00176 
00177 
00178   GS_expression = GS_expr;
00179 
00180   type_of_update type_upd;
00181 
00182   if(size_stencil>1) {
00183     // coarse and fine part
00184     update_other_bla = false;
00185     for(int i=0;i<max_var;++i) {
00186       if(array_vars_other[i]) {
00187         if(other_is_fine) {
00188           type_upd = Give_type_of_update(i,level+1);
00189           if(type_upd!=full_update) {
00190             array_num_other[anz_num_other]=i;
00191             ++anz_num_other;
00192             if(type_upd==no_update) {
00193               update_other_bla = true;
00194             }
00195             Set_type_of_update(i,level+1,full_update);
00196           }
00197         }
00198         if(other_is_coarse) {
00199           type_upd = Give_type_of_update(i,level-1);
00200           if(type_upd!=full_update) {
00201             array_num_other[anz_num_other]=i;
00202             ++anz_num_other;
00203             if(type_upd==no_update) {
00204               update_other_bla = true;
00205             }
00206             Set_type_of_update(i,level-1,full_update);
00207           }
00208         }
00209       }
00210     }
00211     if(GS_expr==true) {
00212       // Gauss Seidel
00213       update_ENT = false;
00214       update_WSD = false;
00215       // for left hand side:
00216       for(int i=0;i<max_var;++i) {
00217         if(array_vars[i]) {
00218           type_upd = Give_type_of_update(i,level);
00219           array_num[anz_num]=i;
00220           ++anz_num;
00221           if(type_upd==no_update) {
00222             update_ENT = true;
00223           }
00224           //old
00225           //      Set_type_of_update(i,level,partial_update);
00226           //new
00227           Set_type_of_update(i,level,full_update);
00228         }
00229       }
00230       // for left hand side:
00231       Set_type_of_update(number_variable,level,partial_update);
00232       left_level  = level;
00233       left_update = partial_update;
00234     }
00235     else {
00236       // Jacobi
00237       update_ENT = false;
00238       update_WSD = true;
00239       // for right hand side:
00240       for(int i=0;i<max_var;++i) {
00241         if(array_vars[i]) {
00242           type_upd = Give_type_of_update(i,level);
00243           if(type_upd!=full_update) {
00244             array_num[anz_num]=i;
00245             ++anz_num;
00246             if(type_upd==no_update) {
00247               update_ENT = true;
00248             }
00249           }
00250           //old
00251           //      Set_type_of_update(i,level,no_update);
00252           //new
00253           Set_type_of_update(i,level,full_update);
00254         }
00255       }
00256       // for left hand side:
00257       Set_type_of_update(number_variable,level,no_update);
00258       left_level  = level;
00259       left_update = no_update;
00260     }
00261     
00262     if(other_is_fine && other_is_coarse) 
00263       cout << " Restriction and Prolongation in one expression "
00264            << " is not allowed!! " << endl;
00265   }
00266   else {
00267     // for left hand side:
00268     Set_type_of_update(number_variable,level,no_update);
00269     left_level  = level;
00270     left_update = no_update;
00271   }
00272     /*
00273     grid->Update_Variable(Wdir,array_num,anz_num,level);
00274     grid->Update_Variable(Edir,array_num,anz_num,level);
00275     grid->Update_Variable(Ndir,array_num,anz_num,level);
00276     grid->Update_Variable(Sdir,array_num,anz_num,level);
00277     grid->Update_Variable(Tdir,array_num,anz_num,level);
00278     grid->Update_Variable(Ddir,array_num,anz_num,level);
00279     */
00280 }
00281 
00282 
00283 evaluation_typ Evaluation_Parallelization_object::Give_next_evaluation_typ() {
00284   // -> parallel
00285   if(parallel_version) {
00286     if(status==0 && size_stencil>1) {
00287       if(other_is_fine) {
00288         if(update_other_bla==true) {
00289           // update from no -> full
00290           grid->Update_Variable_no_full(array_num_other,anz_num_other,level+1);
00291         }
00292         else {
00293           // test
00294             grid->Update_Variable_no_full(array_num,anz_num,level);
00295 
00296           // update from partial -> full
00297           grid->Update_Variable(Edir,array_num_other,anz_num_other,level+1);
00298           grid->Update_Variable(Ndir,array_num_other,anz_num_other,level+1);
00299           grid->Update_Variable(Tdir,array_num_other,anz_num_other,level+1);
00300         }
00301       }
00302       if(other_is_coarse) {
00303        if((level-1)>=(grid->Give_n_parallel()-1)) {
00304          if(update_other_bla==true) {      
00305            // update from no -> partial
00306  grid->Update_Variable_no_full(array_num_other,anz_num_other,level-1);
00307            /*
00308            grid->Update_Variable(Wdir,array_num_other,anz_num_other,level-1);
00309            grid->Update_Variable(Sdir,array_num_other,anz_num_other,level-1);
00310            grid->Update_Variable(Ddir,array_num_other,anz_num_other,level-1);
00311            */
00312          }
00313         }
00314         else {
00315           grid->Update_Variable_for_prolongation(array_num_other,
00316                                                  anz_num_other,level-1);
00317 
00318           /*
00319           grid->Update_Variable_for_prolongation(Wdir,array_num_other,
00320                                                  anz_num_other,level-1);
00321           grid->Update_Variable_for_prolongation(Edir,array_num_other,
00322                                                  anz_num_other,level-1);
00323           grid->Update_Variable_for_prolongation(Ndir,array_num_other,
00324                                                  anz_num_other,level-1);
00325           grid->Update_Variable_for_prolongation(Sdir,array_num_other,
00326                                                  anz_num_other,level-1);
00327           grid->Update_Variable_for_prolongation(Tdir,array_num_other,
00328                                                  anz_num_other,level-1);
00329           grid->Update_Variable_for_prolongation(Ddir,array_num_other,
00330                                                  anz_num_other,level-1);
00331           */
00332         }
00333       }
00334     }
00335     if(GS_expression==false) {
00336       if(status==0) {// FOR JACOBI
00337         if(size_stencil>1 && anz_num>0) {
00338           if(update_ENT &&  update_WSD) {
00339             // update from no -> full
00340             grid->Update_Variable_no_full(array_num,anz_num,level);
00341           }
00342           else {
00343             // update from partial -> full
00344 
00345             // test
00346             grid->Update_Variable_no_full(array_num,anz_num,level);
00347 
00348             grid->Update_Variable(Edir,array_num,anz_num,level);
00349             grid->Update_Variable(Ndir,array_num,anz_num,level);
00350             grid->Update_Variable(Tdir,array_num,anz_num,level);
00351           }
00352         }
00353         ++status;
00354         if(run_object.r_nearb==true) {
00355           cellpoi_pointer = grid->Start_P_cellpoi(level);
00356           
00357           if(size_stencil>1)  return cellf_large_evaluation; 
00358           else                return cellf_1_evaluation; 
00359         }
00360       }
00361       int color, kind;
00362       //      while(status<25) {
00363       while(status<33) {
00364         // color:   0,1, ..., 7
00365         // kind:    0,1,2
00366         // beachte: 3*8  = 24 
00367         //          24+1 = 25
00368         // beachte: 4*8  = 32 
00369         //          32+1 = 33
00370         color = (status-1)/4;
00371         kind  = (status-1)%4;
00372 
00373         if(kind==0) {
00374           ++status;
00375           if(run_object.r_interior==true) {
00376             interior_pointer = grid->Start_P_interior(level,color);
00377             if(max_level==level) {
00378               if(size_stencil==25) return interior_25_evaluation_fine;
00379               if(size_stencil==17) return interior_17_evaluation_fine;
00380               if(size_stencil==15) return interior_15_evaluation_fine;
00381               else                 return interior_1_evaluation_fine; 
00382             }
00383             else {
00384               if(size_stencil==25) return interior_25_evaluation_coarse;
00385               if(size_stencil==17) return interior_17_evaluation_coarse;
00386               if(size_stencil==15) return interior_15_evaluation_coarse;
00387               else                 return interior_1_evaluation_coarse;  
00388             }
00389           }
00390           kind=1;
00391         }
00392         if(kind==1) {
00393           ++status;
00394           if(run_object.r_nearb==true) {
00395             nearb_pointer = grid->Start_P_nearb(level,color);
00396             
00397             if(size_stencil>=17) return nearb_17_evaluation;
00398             if(size_stencil==15) return nearb_15_evaluation;
00399             else                 return nearb_1_evaluation;
00400           }
00401           kind=2;
00402         }
00403         if(kind==2) {
00404           ++status;
00405           Bo2p_pointer = grid->Start_P_Bo2p(level,color);
00406 
00407           if(run_object.r_boundary==1) {
00408             return boundary_evaluation_all; 
00409           }
00410           if(run_object.r_boundary<0) {
00411             return boundary_evaluation_subset; 
00412           }
00413         }
00414         if(kind==3) {
00415           ++status;
00416           nearb_pointer = grid->Start_P_exteri(level,color);
00417           if(run_object.r_boundary==1) {
00418             if(size_stencil>=17) return nearb_17_evaluation;
00419             if(size_stencil==15) return nearb_15_evaluation;
00420             else                 return nearb_1_evaluation;
00421           }
00422           if(run_object.r_boundary<0) {
00423             if(size_stencil>=17) return exteri_17_evaluation_subset;
00424             if(size_stencil==15) return exteri_15_evaluation_subset;
00425             else                 return exteri_1_evaluation_subset;
00426           }
00427         }
00428       }
00429       return stop_evaluation; 
00430     }
00431     else { // FOR GAUSS-SEIDEL
00432       if(status==0) {
00433         ++status;
00434         if(size_stencil>1 && anz_num>0) {
00435           if(update_ENT) {
00436           // test
00437             grid->Update_Variable_no_full(array_num,anz_num,level);
00438 
00439             // update from no -> partial
00440             grid->Update_Variable(Wdir,array_num,anz_num,level);
00441             grid->Update_Variable(Sdir,array_num,anz_num,level);
00442             grid->Update_Variable(Ddir,array_num,anz_num,level);
00443           }
00444         }
00445         if(run_object.r_nearb==true) {
00446           cellpoi_pointer = grid->Start_P_cellpoi(level);
00447           
00448           if(size_stencil>1)  return cellf_large_evaluation; 
00449           else                return cellf_1_evaluation; 
00450         }
00451       }
00452       
00453       int color, kind;
00454       //      while(status<25) {
00455       while(status<33) {
00456         // color:   0,1, ..., 7
00457         // kind:    0,1,2
00458         // beachte: 3*8  = 24 
00459         //          24+1 = 25
00460         // beachte: 4*8  = 32 
00461         //          32+1 = 33
00462         color = (status-1)/4;
00463         kind  = (status-1)%4;
00464         
00465         if(size_stencil>1 && color!=0 && kind==0 && anz_num>0) {
00466 
00467           // test
00468             grid->Update_Variable_no_full(array_num,anz_num,level);
00469 
00470           /*
00471           if(color>=10) {
00472             grid->Update_Variable(Wdir,array_num,anz_num,level);
00473             grid->Update_Variable(Edir,array_num,anz_num,level);
00474             grid->Update_Variable(Ndir,array_num,anz_num,level);
00475             grid->Update_Variable(Sdir,array_num,anz_num,level);
00476             grid->Update_Variable(Tdir,array_num,anz_num,level);
00477             grid->Update_Variable(Ddir,array_num,anz_num,level);
00478           }
00479           */
00480           // Eigentlich sollte man folgendes nehmen:
00481           grid->Update_Variable(Parallel_GS_formula[color-1],array_num,
00482                                 anz_num,level);
00483           
00484         }
00485         
00486         if(kind==0) {
00487           ++status;
00488           if(run_object.r_interior==true) {
00489             interior_pointer = grid->Start_P_interior(level,color);
00490             
00491             if(max_level==level) {
00492               if(size_stencil==25) return interior_25_evaluation_fine;
00493               if(size_stencil==17) return interior_17_evaluation_fine;
00494               if(size_stencil==15) return interior_15_evaluation_fine;
00495               else                 return interior_1_evaluation_fine; 
00496             }
00497             else {
00498               if(size_stencil==25) return interior_25_evaluation_coarse;
00499               if(size_stencil==17) return interior_17_evaluation_coarse;
00500               if(size_stencil==15) return interior_15_evaluation_coarse;
00501               else                 return interior_1_evaluation_coarse;  
00502             }
00503           }
00504           kind=1;
00505         }
00506         if(kind==1) {
00507           ++status;
00508           if(run_object.r_nearb==true) {
00509             nearb_pointer = grid->Start_P_nearb(level,color);
00510             
00511             if(size_stencil>=17) return nearb_17_evaluation;
00512             if(size_stencil==15) return nearb_15_evaluation;
00513             else                 return nearb_1_evaluation;
00514           }
00515           kind=2;
00516         }
00517         if(kind==2) {
00518           ++status;
00519           Bo2p_pointer = grid->Start_P_Bo2p(level,color);
00520           
00521           if(run_object.r_boundary==1) {
00522             return boundary_evaluation_all; 
00523           }
00524           if(run_object.r_boundary<0) {
00525             return boundary_evaluation_subset; 
00526           }
00527         }
00528         if(kind==3) {
00529           ++status;
00530           nearb_pointer = grid->Start_P_exteri(level,color);
00531           if(run_object.r_boundary==1) {
00532             if(size_stencil>=17) return nearb_17_evaluation;
00533             if(size_stencil==15) return nearb_15_evaluation;
00534             else                 return nearb_1_evaluation;
00535           }
00536           if(run_object.r_boundary<0) {
00537             if(size_stencil>=17) return exteri_17_evaluation_subset;
00538             if(size_stencil==15) return exteri_15_evaluation_subset;
00539             else                 return exteri_1_evaluation_subset;
00540           }
00541         }
00542       }
00543       if(size_stencil>1) {
00544         grid->Update_Variable(Parallel_GS_formula[7],array_num,anz_num,level);
00545       }
00546       return stop_evaluation; 
00547     }
00548   }
00549   // serial
00550   else {
00551     if(status==0) {
00552       ++status;
00553       if(run_object.r_nearb==true) {
00554         cellpoi_pointer = grid->Start_P_cellpoi(level);
00555         
00556         if(size_stencil>1)  return cellf_large_evaluation; 
00557         else                return cellf_1_evaluation; 
00558       }
00559     }
00560     int color, kind;
00561     //      while(status<25) {
00562     while(status<33) {
00563       // color:   0,1, ..., 7
00564       // kind:    0,1,2
00565       // beachte: 3*8  = 24 
00566       //          24+1 = 25
00567       // beachte: 4*8  = 32 
00568       //          32+1 = 33
00569       color = (status-1)/4;
00570       kind  = (status-1)%4;
00571       
00572       if(kind==0) {
00573         ++status;
00574         if(run_object.r_interior==true) {
00575           interior_pointer = grid->Start_P_interior(level,color);
00576           if(max_level==level) {
00577             if(size_stencil==25) return interior_25_evaluation_fine;
00578             if(size_stencil==17) return interior_17_evaluation_fine;
00579             if(size_stencil==15) return interior_15_evaluation_fine;
00580             else                 return interior_1_evaluation_fine; 
00581           }
00582           else {
00583             if(size_stencil==25) return interior_25_evaluation_coarse;
00584             if(size_stencil==17) return interior_17_evaluation_coarse;
00585             if(size_stencil==15) return interior_15_evaluation_coarse;
00586             else                 return interior_1_evaluation_coarse;  
00587           }
00588         }
00589         kind=1;
00590       }
00591       if(kind==1) {
00592         ++status;
00593         if(run_object.r_nearb==true) {
00594           nearb_pointer = grid->Start_P_nearb(level,color);
00595           
00596           if(size_stencil>=17) return nearb_17_evaluation;
00597           if(size_stencil==15) return nearb_15_evaluation;
00598           else                 return nearb_1_evaluation;
00599         }
00600         kind=2;
00601       }
00602       if(kind==2) {
00603         ++status;
00604         Bo2p_pointer = grid->Start_P_Bo2p(level,color);
00605         
00606         if(run_object.r_boundary==1) {
00607           return boundary_evaluation_all; 
00608         }
00609         if(run_object.r_boundary<0) {
00610           return boundary_evaluation_subset; 
00611         }
00612       }
00613       if(kind==3) {
00614         ++status;
00615         nearb_pointer = grid->Start_P_exteri(level,color);
00616         if(run_object.r_boundary==1) {
00617           if(size_stencil>=17) return nearb_17_evaluation;
00618           if(size_stencil==15) return nearb_15_evaluation;
00619           else                 return nearb_1_evaluation;
00620         }
00621         if(run_object.r_boundary<0) {
00622           if(size_stencil>=17) return exteri_17_evaluation_subset;
00623           if(size_stencil==15) return exteri_15_evaluation_subset;
00624           else                 return exteri_1_evaluation_subset;
00625         }
00626       }
00627     }
00628     return stop_evaluation; 
00629   }
00630 };
00631 
00632 

Generated on Fri Nov 2 01:25:56 2007 for IPPL by doxygen 1.3.5