Compare commits

...

2 Commits

Author SHA1 Message Date
jaunatisblue
588fb675a0 尝试划分4block但是效果不好,转为研究访存 2026-02-28 21:17:02 +08:00
aabe74c098 短暂的4划分但是以失败告终 2026-02-28 08:23:30 +08:00
3 changed files with 143 additions and 14 deletions

View File

@@ -617,6 +617,7 @@ void Patch::Interp_Points(MyList<var> *VarList,
{
if (owner_rank[j] < 0 && myrank == 0)
{
cout<<owner_rank[j-1]<<endl;
cout << "ERROR: Patch::Interp_Points fails to find point (";
for (int d = 0; d < dim; d++)
{

View File

@@ -710,17 +710,35 @@ MyList<Block> *Parallel::distribute_hard(MyList<Patch> *PatchLIST, int cpusize,
int kb2 = (PP->shape[2] * k) / nxyz[2];
int kb5 = (PP->shape[2] * (k + 1)) / nxyz[2] - 1;
int r_l, r_r;
if(current_block_id == 27) { r_l = 26; r_r = 27; }
else if(current_block_id == 28) { r_l = 28; r_r = 29; }
else if(current_block_id == 35) { r_l = 34; r_r = 35; }
else { r_l = 36; r_r = 37; }
int r_1, r_2, r_3, r_4;
Block * split_first_block = nullptr;
Block * split_last_block = nullptr;
// 拆分逻辑:该函数应更新类成员变量 split_first_block 和 split_last_block
splitHotspotBlock(BlL, dim, ib0, ib3, jb1, jb4, kb2, kb5,
PP, r_l, r_r, ingfsi, fngfsi, periodic,split_first_block,split_last_block);
if(current_block_id == 27)
{
r_1 = 24; r_2 = 25; r_3 = 26; r_4 = 27;
splitHotspotBlock(BlL, dim, ib0, ib3, jb1, jb4, kb2, kb5,
PP, r_1,r_2,r_3, r_4, ingfsi, fngfsi, periodic,split_first_block,split_last_block);
}
else if(current_block_id == 28)
{
r_1 = 28; r_2 = 29;
splitHotspotBlock(BlL, dim, ib0, ib3, jb1, jb4, kb2, kb5,
PP, r_1, r_2, ingfsi, fngfsi, periodic,split_first_block,split_last_block);
}
else if(current_block_id == 35)
{
r_1 = 34; r_2 = 35;
splitHotspotBlock(BlL, dim, ib0, ib3, jb1, jb4, kb2, kb5,
PP, r_1, r_2, ingfsi, fngfsi, periodic,split_first_block,split_last_block);
}
else
{
r_1 = 36; r_2 = 37; r_3 = 38; r_4 = 39;
splitHotspotBlock(BlL, dim, ib0, ib3, jb1, jb4, kb2, kb5,
PP, r_1,r_2,r_3, r_4, ingfsi, fngfsi, periodic,split_first_block,split_last_block);
}
current_ng_start = split_first_block;
ng = split_last_block;
}
@@ -823,10 +841,104 @@ MyList<Block> *Parallel::distribute_hard(MyList<Patch> *PatchLIST, int cpusize,
return BlL;
}
/**
* @brief 将当前 Block 几何4等分并存入列表
*/
Block* Parallel::splitHotspotBlock(MyList<Block>* &BlL, int _dim,
int ib0_orig, int ib3_orig,
int jb1_orig, int jb4_orig,
int kb2_orig, int kb5_orig,
Patch* PP, int r_1, int r_2, int r_3, int r_4,
int ingfsi, int fngfsi, bool periodic,
Block* &split_first_block, Block* &split_last_block)
{
// 1. 计算四分索引区间
// 计算 X 方向的总网格数
int total_len = ib3_orig - ib0_orig + 1;
// 计算三个切分点,确保覆盖 [ib0_orig, ib3_orig]
// 段 1: [ib0_orig, m1]
// 段 2: [m1 + 1, m2]
// 段 3: [m2 + 1, m3]
// 段 4: [m3 + 1, ib3_orig]
int m1 = ib0_orig + total_len / 4 - 1;
int m2 = ib0_orig + total_len / 2 - 1;
int m3 = ib0_orig + (3 * total_len) / 4 - 1;
int indices[4][6] = {
{ib0_orig, jb1_orig, kb2_orig, m1, jb4_orig, kb5_orig}, // 子块 1
{m1 + 1, jb1_orig, kb2_orig, m2, jb4_orig, kb5_orig}, // 子块 2
{m2 + 1, jb1_orig, kb2_orig, m3, jb4_orig, kb5_orig}, // 子块 3
{m3 + 1, jb1_orig, kb2_orig, ib3_orig, jb4_orig, kb5_orig} // 子块 4
};
int target_ranks[4] = {r_1, r_2, r_3, r_4};
// 2. 内部处理逻辑 (保持原有的 Ghost 扩张和物理坐标转换)
auto createSubBlock = [&](int* ib_raw, int target_rank) {
int ib_final[6];
int sh_here[3];
double bb_here[6], dd;
// --- 逻辑 A: Ghost 扩张 ---
if (periodic) {
ib_final[0] = ib_raw[0] - ghost_width;
ib_final[3] = ib_raw[3] + ghost_width;
ib_final[1] = ib_raw[1] - ghost_width;
ib_final[4] = ib_raw[4] + ghost_width;
ib_final[2] = ib_raw[2] - ghost_width;
ib_final[5] = ib_raw[5] + ghost_width;
} else {
ib_final[0] = Mymax(0, ib_raw[0] - ghost_width);
ib_final[3] = Mymin(PP->shape[0] - 1, ib_raw[3] + ghost_width);
ib_final[1] = Mymax(0, ib_raw[1] - ghost_width);
ib_final[4] = Mymin(PP->shape[1] - 1, ib_raw[4] + ghost_width);
ib_final[2] = Mymax(0, ib_raw[2] - ghost_width);
ib_final[5] = Mymin(PP->shape[2] - 1, ib_raw[5] + ghost_width);
}
sh_here[0] = ib_final[3] - ib_final[0] + 1;
sh_here[1] = ib_final[4] - ib_final[1] + 1;
sh_here[2] = ib_final[5] - ib_final[2] + 1;
// --- 逻辑 B: 物理坐标计算 ---
dd = (PP->bbox[3] - PP->bbox[0]) / PP->shape[0];
bb_here[0] = PP->bbox[0] + ib_final[0] * dd;
bb_here[3] = PP->bbox[0] + (ib_final[3] + 1) * dd;
dd = (PP->bbox[4] - PP->bbox[1]) / PP->shape[1];
bb_here[1] = PP->bbox[1] + ib_final[1] * dd;
bb_here[4] = PP->bbox[1] + (ib_final[4] + 1) * dd;
dd = (PP->bbox[5] - PP->bbox[2]) / PP->shape[2];
bb_here[2] = PP->bbox[2] + ib_final[2] * dd;
bb_here[5] = PP->bbox[2] + (ib_final[5] + 1) * dd;
Block* Bg = new Block(_dim, sh_here, bb_here, target_rank, ingfsi, fngfsi, PP->lev);
if (BlL) BlL->insert(Bg);
else BlL = new MyList<Block>(Bg);
return Bg;
};
// 3. 执行创建并返回首尾指针
split_first_block = createSubBlock(indices[0], target_ranks[0]);
createSubBlock(indices[1], target_ranks[1]); // 中间块仅插入 List
createSubBlock(indices[2], target_ranks[2]); // 中间块仅插入 List
split_last_block = createSubBlock(indices[3], target_ranks[3]);
}
/**
* @brief 将当前 Block 几何二等分并存入列表
* @param axis 拆分轴0-x, 1-y, 2-z (建议选最长轴)
*/
Block* Parallel::splitHotspotBlock(MyList<Block>* &BlL, int _dim,
int ib0_orig, int ib3_orig,
int jb1_orig, int jb4_orig,
@@ -907,10 +1019,17 @@ Block* Parallel::splitHotspotBlock(MyList<Block>* &BlL, int _dim,
{
// 映射表逻辑
int target_rank = block_id;
if (block_id == 26) target_rank = 25;
else if (block_id == 29) target_rank = 30;
else if (block_id == 34) target_rank = 33;
else if (block_id == 37) target_rank = 38;
switch(block_id){
case 24: target_rank = 23; break;
case 25: target_rank = 23; break;
case 26: target_rank = 23; break;
case 29: target_rank = 30; break;
case 34: target_rank = 33; break;
case 37: target_rank = 40; break;
case 38: target_rank = 40; break;
case 39: target_rank = 40; break;
}
Block* ng = new Block(dim, shape, bbox, target_rank, ingfsi, fngfsi, lev);

View File

@@ -32,12 +32,21 @@ namespace Parallel
int partition2(int *nxy, int split_size, int *min_width, int cpusize, int *shape); // special for 2 diemnsions
int partition3(int *nxyz, int split_size, int *min_width, int cpusize, int *shape);
MyList<Block> *distribute(MyList<Patch> *PatchLIST, int cpusize, int ingfsi, int fngfs, bool periodic, int nodes = 0); // produce corresponding Blocks
MyList<Block> *distribute_hard(MyList<Patch> *PatchLIST, int cpusize, int ingfsi, int fngfs, bool periodic, int nodes = 0); // produce corresponding Blocks
Block* splitHotspotBlock(MyList<Block>* &BlL, int _dim,
int ib0_orig, int ib3_orig,
int jb1_orig, int jb4_orig,
int kb2_orig, int kb5_orig,
Patch* PP, int r_left, int r_right,
Patch* PP, int r_1, int r_2,
int ingfsi, int fngfsi, bool periodic,
Block* &split_first_block, Block* &split_last_block);
Block* splitHotspotBlock(MyList<Block>* &BlL, int _dim,
int ib0_orig, int ib3_orig,
int jb1_orig, int jb4_orig,
int kb2_orig, int kb5_orig,
Patch* PP, int r_1, int r_2, int r_3, int r_4,
int ingfsi, int fngfsi, bool periodic,
Block* &split_first_block, Block* &split_last_block);
Block* createMappedBlock(MyList<Block>* &BlL, int _dim, int* shape, double* bbox,