00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef __PxStateTrans_h_
00010 #define __PxStateTrans_h_
00011
00012 #include "Core/Array/Pattern/ArrayFunc.h"
00013 #include "Core/Array/Pattern/FuncSet.h"
00014 #include "Core/Array/Pattern/PxArrayFunc.h"
00015 #include "Core/Array/Pattern/PxSystem.h"
00016 #include "Core/Array/Pattern/PxDistribution.h"
00017 #include "Core/Array/Pattern/PxPartition.h"
00018
00019 namespace Impala
00020 {
00021 namespace Core
00022 {
00023 namespace Array
00024 {
00025
00026
00027 enum states { EMPTY,
00028 SEQ_CREAT,
00029 SEQ_VALID,
00030 DYING,
00031 SEQ_PART,
00032 SEQ_FULL,
00033 PAR_PART,
00034 PAR_FULL,
00035 NOT_REDUCED
00036 };
00037
00038 namespace Pattern
00039 {
00040
00041
00042
00043
00044
00045 enum tr_force { WEAK, STRONG };
00046
00047 int prnt = 0;
00048
00049
00050
00051
00052 template<class ArrayT>
00053 inline void
00054 PxArrayPreStateTrans(ArrayT* a, int goState, int force)
00055 {
00056 int aState = a->mState;
00057
00058
00059
00060 PxInitDistribution(ArrayCW(a), ArrayCH(a), ArrayCD(a),
00061 PxXCPUs(), PxYCPUs(), PxZCPUs());
00062
00063
00064
00065 if ((goState==SEQ_VALID && force==WEAK &&
00066 (aState==SEQ_PART || aState==SEQ_FULL)) ||
00067 (goState==SEQ_VALID && force==STRONG &&
00068 (aState==SEQ_CREAT || aState==SEQ_VALID)) ||
00069 (goState==PAR_PART && (aState==SEQ_PART || aState==PAR_PART)) ||
00070 (goState==PAR_FULL && (aState==SEQ_FULL || aState==PAR_FULL))) {
00071 if (prnt) PX_COUT << "PASS: state = " << aState << PX_ENDL;
00072 return;
00073 } else if (aState==DYING || aState==NOT_REDUCED) {
00074 PX_COUT << "ERROR: state = DYING or NOT_REDUCED" << PX_ENDL;
00075 PxAbortSystem();
00076 return;
00077 }
00078
00079
00080
00081 if (aState==PAR_FULL && (goState==SEQ_VALID || goState==PAR_PART)) {
00082 if (prnt) PX_COUT << "LOCAL-2-GLOBAL COPY" << PX_ENDL;
00083 FuncSet(a, PxArrayPD(a), 0,0, ArrayW(a),ArrayH(a), 0,0);
00084 a->mState = SEQ_FULL;
00085 aState = SEQ_FULL;
00086
00087 } else if (aState==PAR_PART &&
00088 (goState==SEQ_VALID || goState==PAR_FULL)) {
00089 if (prnt) PX_COUT << "GATHER" << PX_ENDL;
00090 PxGatherArray(a, PxArrayPD(a), PxRootCPU(), PX_SBT, false);
00091 a->mState = SEQ_PART;
00092 aState = SEQ_PART;
00093 }
00094
00095 if (goState==SEQ_VALID && force==WEAK) {
00096 return;
00097 }
00098
00099
00100
00101 if (PxArrayPD(a) != 0) {
00102 if (prnt) PX_COUT << "DELETE LOCAL" << PX_ENDL;
00103 PxArrayDeletePD(a);
00104 if (goState==SEQ_VALID) {
00105 a->mState = SEQ_VALID;
00106 return;
00107 }
00108 }
00109
00110
00111
00112 if (goState==PAR_PART &&
00113 (aState==SEQ_CREAT || aState==SEQ_VALID || aState==SEQ_FULL)) {
00114 if (prnt) PX_COUT << "CREATE LOCAL (PARTIAL)" << PX_ENDL;
00115 PxArrayCreatePD(a, PxLclWidth(PxMyCPU()),
00116 PxLclHeight(PxMyCPU()), PxLclDepth(PxMyCPU()),
00117 ArrayBW(a), ArrayBH(a), ArrayBD(a));
00118 if (force==STRONG && (aState==SEQ_VALID || aState==SEQ_FULL)) {
00119 if (prnt) PX_COUT << "SCATTER" << PX_ENDL;
00120 PxScatterArray(a, PxArrayPD(a), PxRootCPU(), PX_SBT, false);
00121 }
00122 a->mState = SEQ_PART;
00123 return;
00124
00125
00126
00127 } else if (goState==PAR_FULL &&
00128 (aState==SEQ_CREAT || aState==SEQ_VALID || aState==SEQ_PART)) {
00129 if (prnt) PX_COUT << "CREATE LOCAL (FULL)" << PX_ENDL;
00130 PxArrayCreatePD(a, ArrayCW(a), ArrayCH(a), ArrayCD(a),
00131 ArrayBW(a), ArrayBH(a), ArrayBD(a));
00132 if (PxMyCPU() == PxRootCPU()) {
00133 if (prnt) PX_COUT << "GLOBAL-2-LOCAL COPY" << PX_ENDL;
00134 FuncSet(PxArrayPD(a),
00135 a, 0, 0, ArrayW(a), ArrayH(a), 0, 0);
00136 }
00137 if (force==STRONG && (aState==SEQ_VALID || aState==SEQ_PART)) {
00138 if (prnt) PX_COUT << "BROADCAST" << PX_ENDL;
00139 PxBcastArray(PxArrayPD(a), PxRootCPU(), PX_SBT, false);
00140 }
00141 a->mState = SEQ_FULL;
00142 return;
00143 }
00144 }
00145
00146
00147 template<class ArrayT>
00148 inline void
00149 PxArrayPostStateTrans(ArrayT* a)
00150 {
00151 if (a->mState == SEQ_PART) {
00152 a->mState = PAR_PART;
00153 } else if (a->mState == SEQ_FULL) {
00154 a->mState = PAR_FULL;
00155 }
00156 }
00157
00158
00159 template<class ArrayT>
00160 inline void
00161 PxArrayForceNonDistributed(ArrayT* a)
00162 {
00163 PxArrayPreStateTrans(a, SEQ_VALID, STRONG);
00164 a->mState = SEQ_VALID;
00165 }
00166
00167
00168 }
00169 }
00170 }
00171 }
00172
00173 #endif