修改block划分,对负载高的rank所在block进行划分,添加到空rank,空rank是平移得到的

This commit is contained in:
jaunatisblue
2026-02-26 09:40:46 +08:00
parent 8abac8dd88
commit f147f79ffa
7 changed files with 14791 additions and 14008 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -24,6 +24,7 @@ using namespace std;
#endif #endif
#include <mpi.h> #include <mpi.h>
#include <memory.h>
#include "MyList.h" #include "MyList.h"
#include "Block.h" #include "Block.h"
#include "Parallel.h" #include "Parallel.h"

File diff suppressed because it is too large Load Diff

View File

@@ -1,213 +1,235 @@
#ifndef PARALLEL_H #ifndef PARALLEL_H
#define PARALLEL_H #define PARALLEL_H
#include <iostream> #include <iostream>
#include <iomanip> #include <iomanip>
#include <fstream> #include <fstream>
#include <cstdlib> #include <cstdlib>
#include <cstdio> #include <cstdio>
#include <string> #include <string>
#include <cmath> #include <cmath>
#include <new> #include <new>
using namespace std; using namespace std;
#include <memory.h>
#include "Parallel_bam.h" #include "Parallel_bam.h"
#include "var.h" #include "var.h"
#include "MPatch.h" #include "MPatch.h"
#include "Block.h" #include "Block.h"
#include "MyList.h" #include "MyList.h"
#include "macrodef.h" //need dim; ghost_width; CONTRACT #include "macrodef.h" //need dim; ghost_width; CONTRACT
namespace Parallel namespace Parallel
{ {
struct gridseg struct gridseg
{ {
double llb[dim]; double llb[dim];
double uub[dim]; double uub[dim];
int shape[dim]; int shape[dim];
double illb[dim], iuub[dim]; // only use for OutBdLow2Hi double illb[dim], iuub[dim]; // only use for OutBdLow2Hi
Block *Bg; Block *Bg;
}; };
int partition1(int &nx, int split_size, int min_width, int cpusize, int shape); // special for 1 diemnsion int partition1(int &nx, int split_size, int min_width, int cpusize, int shape); // special for 1 diemnsion
int partition2(int *nxy, int split_size, int *min_width, int cpusize, int *shape); // special for 2 diemnsions 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); 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(MyList<Patch> *PatchLIST, int cpusize, int ingfsi, int fngfs, bool periodic, int nodes = 0); // produce corresponding Blocks
void KillBlocks(MyList<Patch> *PatchLIST); 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,
void setfunction(MyList<Block> *BlL, var *vn, double func(double x, double y, double z)); int ib0_orig, int ib3_orig,
void setfunction(int rank, MyList<Block> *BlL, var *vn, double func(double x, double y, double z)); int jb1_orig, int jb4_orig,
void writefile(double time, int nx, int ny, int nz, double xmin, double xmax, double ymin, double ymax, int kb2_orig, int kb5_orig,
double zmin, double zmax, char *filename, double *data_out); Patch* PP, int r_left, int r_right,
void writefile(double time, int nx, int ny, double xmin, double xmax, double ymin, double ymax, int ingfsi, int fngfsi, bool periodic,
char *filename, double *datain); Block* &split_first_block, Block* &split_last_block);
void getarrayindex(int DIM, int *shape, int *index, int n); Block* createMappedBlock(MyList<Block>* &BlL, int _dim, int* shape, double* bbox,
int getarraylocation(int DIM, int *shape, int *index); int block_id, int ingfsi, int fngfsi, int lev);
void copy(int DIM, double *llbout, double *uubout, int *Dshape, double *DD, double *llbin, double *uubin, void KillBlocks(MyList<Patch> *PatchLIST);
int *shape, double *datain, double *llb, double *uub);
void Dump_CPU_Data(MyList<Block> *BlL, MyList<var> *DumpList, char *tag, double time, double dT); void setfunction(MyList<Block> *BlL, var *vn, double func(double x, double y, double z));
void Dump_Data(MyList<Patch> *PL, MyList<var> *DumpList, char *tag, double time, double dT); void setfunction(int rank, MyList<Block> *BlL, var *vn, double func(double x, double y, double z));
void Dump_Data(Patch *PP, MyList<var> *DumpList, char *tag, double time, double dT, int grd); void writefile(double time, int nx, int ny, int nz, double xmin, double xmax, double ymin, double ymax,
double *Collect_Data(Patch *PP, var *VP); double zmin, double zmax, char *filename, double *data_out);
void d2Dump_Data(MyList<Patch> *PL, MyList<var> *DumpList, char *tag, double time, double dT); void writefile(double time, int nx, int ny, double xmin, double xmax, double ymin, double ymax,
void d2Dump_Data(Patch *PP, MyList<var> *DumpList, char *tag, double time, double dT, int grd); char *filename, double *datain);
void Dump_Data0(Patch *PP, MyList<var> *DumpList, char *tag, double time, double dT); void getarrayindex(int DIM, int *shape, int *index, int n);
double global_interp(int DIM, int *ext, double **CoX, double *datain, int getarraylocation(int DIM, int *shape, int *index);
double *poX, int ordn, double *SoA, int Symmetry); void copy(int DIM, double *llbout, double *uubout, int *Dshape, double *DD, double *llbin, double *uubin,
double global_interp(int DIM, int *ext, double **CoX, double *datain, int *shape, double *datain, double *llb, double *uub);
double *poX, int ordn); void Dump_CPU_Data(MyList<Block> *BlL, MyList<var> *DumpList, char *tag, double time, double dT);
double Lagrangian_Int(double x, int npts, double *xpts, double *funcvals); void Dump_Data(MyList<Patch> *PL, MyList<var> *DumpList, char *tag, double time, double dT);
double LagrangePoly(double x, int pt, int npts, double *xpts); void Dump_Data(Patch *PP, MyList<var> *DumpList, char *tag, double time, double dT, int grd);
MyList<gridseg> *build_complete_gsl(Patch *Pat); double *Collect_Data(Patch *PP, var *VP);
MyList<gridseg> *build_complete_gsl(MyList<Patch> *PatL); void d2Dump_Data(MyList<Patch> *PL, MyList<var> *DumpList, char *tag, double time, double dT);
MyList<gridseg> *build_complete_gsl_virtual(MyList<Patch> *PatL); void d2Dump_Data(Patch *PP, MyList<var> *DumpList, char *tag, double time, double dT, int grd);
MyList<gridseg> *build_complete_gsl_virtual2(MyList<Patch> *PatL); // - buffer void Dump_Data0(Patch *PP, MyList<var> *DumpList, char *tag, double time, double dT);
MyList<gridseg> *build_owned_gsl0(Patch *Pat, int rank_in); // - ghost without extension, special for Sync usage double global_interp(int DIM, int *ext, double **CoX, double *datain,
MyList<gridseg> *build_owned_gsl1(Patch *Pat, int rank_in); // - ghost, similar to build_owned_gsl0 but extend one point on left side for vertex grid double *poX, int ordn, double *SoA, int Symmetry);
MyList<gridseg> *build_owned_gsl2(Patch *Pat, int rank_in); // - buffer - ghost double global_interp(int DIM, int *ext, double **CoX, double *datain,
MyList<gridseg> *build_owned_gsl3(Patch *Pat, int rank_in, int Symmetry); // - ghost - BD ghost double *poX, int ordn);
MyList<gridseg> *build_owned_gsl4(Patch *Pat, int rank_in, int Symmetry); // - buffer - ghost - BD ghost double Lagrangian_Int(double x, int npts, double *xpts, double *funcvals);
MyList<gridseg> *build_owned_gsl5(Patch *Pat, int rank_in); // similar to build_owned_gsl2 but no extension double LagrangePoly(double x, int pt, int npts, double *xpts);
MyList<gridseg> *build_owned_gsl(MyList<Patch> *PatL, int rank_in, int type, int Symmetry); MyList<gridseg> *build_complete_gsl(Patch *Pat);
void build_gstl(MyList<gridseg> *srci, MyList<gridseg> *dsti, MyList<gridseg> **out_src, MyList<gridseg> **out_dst); MyList<gridseg> *build_complete_gsl(MyList<Patch> *PatL);
int data_packer(double *data, MyList<gridseg> *src, MyList<gridseg> *dst, int rank_in, int dir, MyList<gridseg> *build_complete_gsl_virtual(MyList<Patch> *PatL);
MyList<var> *VarLists, MyList<var> *VarListd, int Symmetry); MyList<gridseg> *build_complete_gsl_virtual2(MyList<Patch> *PatL); // - buffer
void transfer(MyList<gridseg> **src, MyList<gridseg> **dst, MyList<gridseg> *build_owned_gsl0(Patch *Pat, int rank_in); // - ghost without extension, special for Sync usage
MyList<var> *VarList1 /* source */, MyList<var> *VarList2 /*target */, MyList<gridseg> *build_owned_gsl1(Patch *Pat, int rank_in); // - ghost, similar to build_owned_gsl0 but extend one point on left side for vertex grid
int Symmetry); MyList<gridseg> *build_owned_gsl2(Patch *Pat, int rank_in); // - buffer - ghost
int data_packermix(double *data, MyList<gridseg> *src, MyList<gridseg> *dst, int rank_in, int dir, MyList<gridseg> *build_owned_gsl3(Patch *Pat, int rank_in, int Symmetry); // - ghost - BD ghost
MyList<var> *VarLists, MyList<var> *VarListd, int Symmetry); MyList<gridseg> *build_owned_gsl4(Patch *Pat, int rank_in, int Symmetry); // - buffer - ghost - BD ghost
void transfermix(MyList<gridseg> **src, MyList<gridseg> **dst, MyList<gridseg> *build_owned_gsl5(Patch *Pat, int rank_in); // similar to build_owned_gsl2 but no extension
MyList<var> *VarList1 /* source */, MyList<var> *VarList2 /*target */, MyList<gridseg> *build_owned_gsl(MyList<Patch> *PatL, int rank_in, int type, int Symmetry);
int Symmetry); void build_gstl(MyList<gridseg> *srci, MyList<gridseg> *dsti, MyList<gridseg> **out_src, MyList<gridseg> **out_dst);
void Sync(Patch *Pat, MyList<var> *VarList, int Symmetry); int data_packer(double *data, MyList<gridseg> *src, MyList<gridseg> *dst, int rank_in, int dir,
void Sync(MyList<Patch> *PatL, MyList<var> *VarList, int Symmetry); MyList<var> *VarLists, MyList<var> *VarListd, int Symmetry);
void Sync_merged(MyList<Patch> *PatL, MyList<var> *VarList, int Symmetry); void transfer(MyList<gridseg> **src, MyList<gridseg> **dst,
MyList<var> *VarList1 /* source */, MyList<var> *VarList2 /*target */,
struct SyncCache { int Symmetry);
bool valid; int data_packermix(double *data, MyList<gridseg> *src, MyList<gridseg> *dst, int rank_in, int dir,
int cpusize; MyList<var> *VarLists, MyList<var> *VarListd, int Symmetry);
MyList<gridseg> **combined_src; void transfermix(MyList<gridseg> **src, MyList<gridseg> **dst,
MyList<gridseg> **combined_dst; MyList<var> *VarList1 /* source */, MyList<var> *VarList2 /*target */,
int *send_lengths; int Symmetry);
int *recv_lengths; void Sync(Patch *Pat, MyList<var> *VarList, int Symmetry);
double **send_bufs; void Sync(MyList<Patch> *PatL, MyList<var> *VarList, int Symmetry);
double **recv_bufs; void Sync_merged(MyList<Patch> *PatL, MyList<var> *VarList, int Symmetry);
int *send_buf_caps;
int *recv_buf_caps; struct SyncCache {
MPI_Request *reqs; bool valid;
MPI_Status *stats; int cpusize;
int max_reqs; MyList<gridseg> **combined_src;
bool lengths_valid; MyList<gridseg> **combined_dst;
SyncCache(); int *send_lengths;
void invalidate(); int *recv_lengths;
void destroy(); double **send_bufs;
}; double **recv_bufs;
int *send_buf_caps;
void Sync_cached(MyList<Patch> *PatL, MyList<var> *VarList, int Symmetry, SyncCache &cache); int *recv_buf_caps;
void transfer_cached(MyList<gridseg> **src, MyList<gridseg> **dst, MPI_Request *reqs;
MyList<var> *VarList1, MyList<var> *VarList2, MPI_Status *stats;
int Symmetry, SyncCache &cache); int max_reqs;
bool lengths_valid;
struct AsyncSyncState { SyncCache();
int req_no; void invalidate();
bool active; void destroy();
AsyncSyncState() : req_no(0), active(false) {} };
};
void Sync_cached(MyList<Patch> *PatL, MyList<var> *VarList, int Symmetry, SyncCache &cache);
void Sync_start(MyList<Patch> *PatL, MyList<var> *VarList, int Symmetry, void transfer_cached(MyList<gridseg> **src, MyList<gridseg> **dst,
SyncCache &cache, AsyncSyncState &state); MyList<var> *VarList1, MyList<var> *VarList2,
void Sync_finish(SyncCache &cache, AsyncSyncState &state, int Symmetry, SyncCache &cache);
MyList<var> *VarList, int Symmetry);
void OutBdLow2Hi(Patch *Patc, Patch *Patf, struct AsyncSyncState {
MyList<var> *VarList1 /* source */, MyList<var> *VarList2 /* target */, int req_no;
int Symmetry); bool active;
void OutBdLow2Hi(MyList<Patch> *PatcL, MyList<Patch> *PatfL, AsyncSyncState() : req_no(0), active(false) {}
MyList<var> *VarList1 /* source */, MyList<var> *VarList2 /* target */, };
int Symmetry);
void OutBdLow2Himix(Patch *Patc, Patch *Patf, void Sync_start(MyList<Patch> *PatL, MyList<var> *VarList, int Symmetry,
MyList<var> *VarList1 /* source */, MyList<var> *VarList2 /* target */, SyncCache &cache, AsyncSyncState &state);
int Symmetry); void Sync_finish(SyncCache &cache, AsyncSyncState &state,
void OutBdLow2Himix(MyList<Patch> *PatcL, MyList<Patch> *PatfL, MyList<var> *VarList, int Symmetry);
MyList<var> *VarList1 /* source */, MyList<var> *VarList2 /* target */, void OutBdLow2Hi(Patch *Patc, Patch *Patf,
int Symmetry); MyList<var> *VarList1 /* source */, MyList<var> *VarList2 /* target */,
void Restrict_cached(MyList<Patch> *PatcL, MyList<Patch> *PatfL, int Symmetry);
MyList<var> *VarList1, MyList<var> *VarList2, void OutBdLow2Hi(MyList<Patch> *PatcL, MyList<Patch> *PatfL,
int Symmetry, SyncCache &cache); MyList<var> *VarList1 /* source */, MyList<var> *VarList2 /* target */,
void OutBdLow2Hi_cached(MyList<Patch> *PatcL, MyList<Patch> *PatfL, int Symmetry);
MyList<var> *VarList1, MyList<var> *VarList2, void OutBdLow2Himix(Patch *Patc, Patch *Patf,
int Symmetry, SyncCache &cache); MyList<var> *VarList1 /* source */, MyList<var> *VarList2 /* target */,
void OutBdLow2Himix_cached(MyList<Patch> *PatcL, MyList<Patch> *PatfL, int Symmetry);
MyList<var> *VarList1, MyList<var> *VarList2, void OutBdLow2Himix(MyList<Patch> *PatcL, MyList<Patch> *PatfL,
int Symmetry, SyncCache &cache); MyList<var> *VarList1 /* source */, MyList<var> *VarList2 /* target */,
void Prolong(Patch *Patc, Patch *Patf, int Symmetry);
MyList<var> *VarList1 /* source */, MyList<var> *VarList2 /* target */, void Restrict_cached(MyList<Patch> *PatcL, MyList<Patch> *PatfL,
int Symmetry); MyList<var> *VarList1, MyList<var> *VarList2,
void Prolongint(Patch *Patc, Patch *Patf, int Symmetry, SyncCache &cache);
MyList<var> *VarList1 /* source */, MyList<var> *VarList2 /* target */, void OutBdLow2Hi_cached(MyList<Patch> *PatcL, MyList<Patch> *PatfL,
int Symmetry); MyList<var> *VarList1, MyList<var> *VarList2,
void Restrict(MyList<Patch> *PatcL, MyList<Patch> *PatfL, int Symmetry, SyncCache &cache);
MyList<var> *VarList1 /* source */, MyList<var> *VarList2 /* target */, void OutBdLow2Himix_cached(MyList<Patch> *PatcL, MyList<Patch> *PatfL,
int Symmetry); MyList<var> *VarList1, MyList<var> *VarList2,
void Restrict_after(MyList<Patch> *PatcL, MyList<Patch> *PatfL, int Symmetry, SyncCache &cache);
MyList<var> *VarList1 /* source */, MyList<var> *VarList2 /* target */, void Prolong(Patch *Patc, Patch *Patf,
int Symmetry); // for -ghost - BDghost MyList<var> *VarList1 /* source */, MyList<var> *VarList2 /* target */,
MyList<Parallel::gridseg> *build_PhysBD_gsl(Patch *Pat); int Symmetry);
MyList<Parallel::gridseg> *build_ghost_gsl(MyList<Patch> *PatL); void Prolongint(Patch *Patc, Patch *Patf,
MyList<Parallel::gridseg> *build_ghost_gsl(Patch *Pat); MyList<var> *VarList1 /* source */, MyList<var> *VarList2 /* target */,
MyList<Parallel::gridseg> *build_buffer_gsl(Patch *Pat); int Symmetry);
MyList<Parallel::gridseg> *build_buffer_gsl(MyList<Patch> *PatL); void Restrict(MyList<Patch> *PatcL, MyList<Patch> *PatfL,
MyList<Parallel::gridseg> *gsl_subtract(MyList<Parallel::gridseg> *A, MyList<Parallel::gridseg> *B); MyList<var> *VarList1 /* source */, MyList<var> *VarList2 /* target */,
MyList<Parallel::gridseg> *gs_subtract(MyList<Parallel::gridseg> *A, MyList<Parallel::gridseg> *B); int Symmetry);
MyList<Parallel::gridseg> *gsl_and(MyList<Parallel::gridseg> *A, MyList<Parallel::gridseg> *B); void Restrict_after(MyList<Patch> *PatcL, MyList<Patch> *PatfL,
MyList<Parallel::gridseg> *gs_and(MyList<Parallel::gridseg> *A, MyList<Parallel::gridseg> *B); MyList<var> *VarList1 /* source */, MyList<var> *VarList2 /* target */,
MyList<Parallel::gridseg> *clone_gsl(MyList<Parallel::gridseg> *p, bool first_only); int Symmetry); // for -ghost - BDghost
MyList<Parallel::gridseg> *build_bulk_gsl(Patch *Pat); // similar to build_owned_gsl0 but does not care rank issue MyList<Parallel::gridseg> *build_PhysBD_gsl(Patch *Pat);
MyList<Parallel::gridseg> *build_bulk_gsl(Block *bp, Patch *Pat); MyList<Parallel::gridseg> *build_ghost_gsl(MyList<Patch> *PatL);
void build_PhysBD_gstl(Patch *Pat, MyList<Parallel::gridseg> *srci, MyList<Parallel::gridseg> *dsti, MyList<Parallel::gridseg> *build_ghost_gsl(Patch *Pat);
MyList<Parallel::gridseg> **out_src, MyList<Parallel::gridseg> **out_dst); MyList<Parallel::gridseg> *build_buffer_gsl(Patch *Pat);
void PeriodicBD(Patch *Pat, MyList<var> *VarList, int Symmetry); MyList<Parallel::gridseg> *build_buffer_gsl(MyList<Patch> *PatL);
double L2Norm(Patch *Pat, var *vf); MyList<Parallel::gridseg> *gsl_subtract(MyList<Parallel::gridseg> *A, MyList<Parallel::gridseg> *B);
void checkgsl(MyList<Parallel::gridseg> *pp, bool first_only); MyList<Parallel::gridseg> *gs_subtract(MyList<Parallel::gridseg> *A, MyList<Parallel::gridseg> *B);
void checkvarl(MyList<var> *pp, bool first_only); MyList<Parallel::gridseg> *gsl_and(MyList<Parallel::gridseg> *A, MyList<Parallel::gridseg> *B);
MyList<Parallel::gridseg> *divide_gsl(MyList<Parallel::gridseg> *p, Patch *Pat); MyList<Parallel::gridseg> *gs_and(MyList<Parallel::gridseg> *A, MyList<Parallel::gridseg> *B);
MyList<Parallel::gridseg> *divide_gs(MyList<Parallel::gridseg> *p, Patch *Pat); MyList<Parallel::gridseg> *clone_gsl(MyList<Parallel::gridseg> *p, bool first_only);
void prepare_inter_time_level(Patch *Pat, MyList<Parallel::gridseg> *build_bulk_gsl(Patch *Pat); // similar to build_owned_gsl0 but does not care rank issue
MyList<var> *VarList1 /* source (t+dt) */, MyList<var> *VarList2 /* source (t) */, MyList<Parallel::gridseg> *build_bulk_gsl(Block *bp, Patch *Pat);
MyList<var> *VarList3 /* target (t+a*dt) */, int tindex); void build_PhysBD_gstl(Patch *Pat, MyList<Parallel::gridseg> *srci, MyList<Parallel::gridseg> *dsti,
void prepare_inter_time_level(Patch *Pat, MyList<Parallel::gridseg> **out_src, MyList<Parallel::gridseg> **out_dst);
MyList<var> *VarList1 /* source (t+dt) */, MyList<var> *VarList2 /* source (t) */, void PeriodicBD(Patch *Pat, MyList<var> *VarList, int Symmetry);
MyList<var> *VarList3 /* source (t-dt) */, MyList<var> *VarList4 /* target (t+a*dt) */, int tindex); double L2Norm(Patch *Pat, var *vf);
void prepare_inter_time_level(MyList<Patch> *PatL, void checkgsl(MyList<Parallel::gridseg> *pp, bool first_only);
MyList<var> *VarList1 /* source (t+dt) */, MyList<var> *VarList2 /* source (t) */, void checkvarl(MyList<var> *pp, bool first_only);
MyList<var> *VarList3 /* target (t+a*dt) */, int tindex); MyList<Parallel::gridseg> *divide_gsl(MyList<Parallel::gridseg> *p, Patch *Pat);
void prepare_inter_time_level(MyList<Patch> *Pat, MyList<Parallel::gridseg> *divide_gs(MyList<Parallel::gridseg> *p, Patch *Pat);
MyList<var> *VarList1 /* source (t+dt) */, MyList<var> *VarList2 /* source (t) */, void prepare_inter_time_level(Patch *Pat,
MyList<var> *VarList3 /* source (t-dt) */, MyList<var> *VarList4 /* target (t+a*dt) */, int tindex); MyList<var> *VarList1 /* source (t+dt) */, MyList<var> *VarList2 /* source (t) */,
void merge_gsl(MyList<gridseg> *&A, const double ratio); MyList<var> *VarList3 /* target (t+a*dt) */, int tindex);
bool merge_gs(MyList<gridseg> *D, MyList<gridseg> *B, MyList<gridseg> *&C, const double ratio); void prepare_inter_time_level(Patch *Pat,
// Add ghost region to tangent plane MyList<var> *VarList1 /* source (t+dt) */, MyList<var> *VarList2 /* source (t) */,
// we assume the grids have the same resolution MyList<var> *VarList3 /* source (t-dt) */, MyList<var> *VarList4 /* target (t+a*dt) */, int tindex);
void add_ghost_touch(MyList<gridseg> *&A); void prepare_inter_time_level(MyList<Patch> *PatL,
void cut_gsl(MyList<gridseg> *&A); MyList<var> *VarList1 /* source (t+dt) */, MyList<var> *VarList2 /* source (t) */,
bool cut_gs(MyList<gridseg> *D, MyList<gridseg> *B, MyList<gridseg> *&C); MyList<var> *VarList3 /* target (t+a*dt) */, int tindex);
MyList<Parallel::gridseg> *gs_subtract_virtual(MyList<Parallel::gridseg> *A, MyList<Parallel::gridseg> *B); void prepare_inter_time_level(MyList<Patch> *Pat,
void fill_level_data(MyList<Patch> *PatLd, MyList<Patch> *PatLs, MyList<Patch> *PatcL, MyList<var> *VarList1 /* source (t+dt) */, MyList<var> *VarList2 /* source (t) */,
MyList<var> *OldList, MyList<var> *StateList, MyList<var> *FutureList, MyList<var> *VarList3 /* source (t-dt) */, MyList<var> *VarList4 /* target (t+a*dt) */, int tindex);
MyList<var> *tmList, int Symmetry, bool BB, bool CC); void merge_gsl(MyList<gridseg> *&A, const double ratio);
bool PatList_Interp_Points(MyList<Patch> *PatL, MyList<var> *VarList, bool merge_gs(MyList<gridseg> *D, MyList<gridseg> *B, MyList<gridseg> *&C, const double ratio);
int NN, double **XX, // Add ghost region to tangent plane
double *Shellf, int Symmetry); // we assume the grids have the same resolution
void aligncheck(double *bbox0, double *bboxl, int lev, double *DH0, int *shape); void add_ghost_touch(MyList<gridseg> *&A);
bool point_locat_gsl(double *pox, MyList<Parallel::gridseg> *gsl); void cut_gsl(MyList<gridseg> *&A);
void checkpatchlist(MyList<Patch> *PatL, bool buflog); bool cut_gs(MyList<gridseg> *D, MyList<gridseg> *B, MyList<gridseg> *&C);
MyList<Parallel::gridseg> *gs_subtract_virtual(MyList<Parallel::gridseg> *A, MyList<Parallel::gridseg> *B);
double L2Norm(Patch *Pat, var *vf, MPI_Comm Comm_here); void fill_level_data(MyList<Patch> *PatLd, MyList<Patch> *PatLs, MyList<Patch> *PatcL,
bool PatList_Interp_Points(MyList<Patch> *PatL, MyList<var> *VarList, MyList<var> *OldList, MyList<var> *StateList, MyList<var> *FutureList,
int NN, double **XX, MyList<var> *tmList, int Symmetry, bool BB, bool CC);
double *Shellf, int Symmetry, MPI_Comm Comm_here); bool PatList_Interp_Points(MyList<Patch> *PatL, MyList<var> *VarList,
#if (PSTR == 1 || PSTR == 2 || PSTR == 3) int NN, double **XX,
MyList<Block> *distribute(MyList<Patch> *PatchLIST, int cpusize, int ingfsi, int fngfsi, double *Shellf, int Symmetry);
bool periodic, int start_rank, int end_rank, int nodes = 0); void aligncheck(double *bbox0, double *bboxl, int lev, double *DH0, int *shape);
#endif bool point_locat_gsl(double *pox, MyList<Parallel::gridseg> *gsl);
} void checkpatchlist(MyList<Patch> *PatL, bool buflog);
#endif /*PARALLEL_H */
double L2Norm(Patch *Pat, var *vf, MPI_Comm Comm_here);
bool PatList_Interp_Points(MyList<Patch> *PatL, MyList<var> *VarList,
int NN, double **XX,
double *Shellf, int Symmetry, MPI_Comm Comm_here);
#if (PSTR == 1 || PSTR == 2 || PSTR == 3)
MyList<Block> *distribute(MyList<Patch> *PatchLIST, int cpusize, int ingfsi, int fngfsi,
bool periodic, int start_rank, int end_rank, int nodes = 0);
// Redistribute blocks with time statistics for load balancing
MyList<Block> *distribute(MyList<Patch> *PatchLIST, MyList<Block> *OldBlockL,
int cpusize, int ingfsi, int fngfsi,
bool periodic, int start_rank, int end_rank, int nodes = 0);
#endif
// Dynamic load balancing: split blocks for heavy ranks
void split_heavy_blocks(MyList<Patch> *PatL, int *heavy_ranks, int num_heavy,
int split_factor, int cpusize, int ingfsi, int fngfsi);
// Check if load balancing is needed based on interpolation times
bool check_load_balance_need(double *rank_times, int nprocs, int &num_heavy, int *heavy_ranks);
}
#endif /*PARALLEL_H */

File diff suppressed because it is too large Load Diff

View File

@@ -1,92 +1,107 @@
#ifndef CGH_H #ifndef CGH_H
#define CGH_H #define CGH_H
#include <mpi.h> #include <mpi.h>
#include "MyList.h" #include "MyList.h"
#include "MPatch.h" #include "MPatch.h"
#include "macrodef.h" #include "macrodef.h"
#include "monitor.h" #include "monitor.h"
#include "Parallel.h" #include "Parallel.h"
class cgh class cgh
{ {
public: public:
int levels, movls, BH_num_in; int levels, movls, BH_num_in;
// information of boxes // information of boxes
int *grids; int *grids;
double ***bbox; double ***bbox;
int ***shape; int ***shape;
double ***handle; double ***handle;
double ***Porgls; double ***Porgls;
double *Lt; double *Lt;
// information of Patch list // information of Patch list
MyList<Patch> **PatL; MyList<Patch> **PatL;
// information of OutBdLow2Hi point list and Restrict point list // information of OutBdLow2Hi point list and Restrict point list
#if (RPB == 1) #if (RPB == 1)
MyList<Parallel::pointstru_bam> **bdsul, **rsul; MyList<Parallel::pointstru_bam> **bdsul, **rsul;
#endif #endif
#if (PSTR == 1 || PSTR == 2 || PSTR == 3) #if (PSTR == 1 || PSTR == 2 || PSTR == 3)
int mylev; int mylev;
int *start_rank, *end_rank; int *start_rank, *end_rank;
MPI_Comm *Commlev; MPI_Comm *Commlev;
#endif #endif
protected: protected:
int ingfs, fngfs; int ingfs, fngfs;
static constexpr double ratio = 0.75; static constexpr double ratio = 0.75;
int trfls; int trfls;
public: public:
cgh(int ingfsi, int fngfsi, int Symmetry, char *filename, int checkrun, monitor *ErrorMonitor); cgh(int ingfsi, int fngfsi, int Symmetry, char *filename, int checkrun, monitor *ErrorMonitor);
~cgh(); ~cgh();
void compose_cgh(int nprocs); void compose_cgh(int nprocs);
void sethandle(monitor *ErrorMonitor); void sethandle(monitor *ErrorMonitor);
void checkPatchList(MyList<Patch> *PatL, bool buflog); void checkPatchList(MyList<Patch> *PatL, bool buflog);
void Regrid(int Symmetry, int BH_num, double **Porgbr, double **Porg0, void Regrid(int Symmetry, int BH_num, double **Porgbr, double **Porg0,
MyList<var> *OldList, MyList<var> *StateList, MyList<var> *OldList, MyList<var> *StateList,
MyList<var> *FutureList, MyList<var> *tmList, bool BB, MyList<var> *FutureList, MyList<var> *tmList, bool BB,
monitor *ErrorMonitor); monitor *ErrorMonitor);
void Regrid_fake(int Symmetry, int BH_num, double **Porgbr, double **Porg0, void Regrid_fake(int Symmetry, int BH_num, double **Porgbr, double **Porg0,
MyList<var> *OldList, MyList<var> *StateList, MyList<var> *OldList, MyList<var> *StateList,
MyList<var> *FutureList, MyList<var> *tmList, bool BB, MyList<var> *FutureList, MyList<var> *tmList, bool BB,
monitor *ErrorMonitor); monitor *ErrorMonitor);
void recompose_cgh(int nprocs, bool *lev_flag, void recompose_cgh(int nprocs, bool *lev_flag,
MyList<var> *OldList, MyList<var> *StateList, MyList<var> *OldList, MyList<var> *StateList,
MyList<var> *FutureList, MyList<var> *tmList, MyList<var> *FutureList, MyList<var> *tmList,
int Symmetry, bool BB); int Symmetry, bool BB);
void recompose_cgh_fake(int nprocs, bool *lev_flag, void recompose_cgh_fake(int nprocs, bool *lev_flag,
MyList<var> *OldList, MyList<var> *StateList, MyList<var> *OldList, MyList<var> *StateList,
MyList<var> *FutureList, MyList<var> *tmList, MyList<var> *FutureList, MyList<var> *tmList,
int Symmetry, bool BB); int Symmetry, bool BB);
void read_bbox(int Symmetry, char *filename); void read_bbox(int Symmetry, char *filename);
MyList<Patch> *construct_patchlist(int lev, int Symmetry); MyList<Patch> *construct_patchlist(int lev, int Symmetry);
bool Interp_One_Point(MyList<var> *VarList, bool Interp_One_Point(MyList<var> *VarList,
double *XX, /*input global Cartesian coordinate*/ double *XX, /*input global Cartesian coordinate*/
double *Shellf, int Symmetry); double *Shellf, int Symmetry);
void recompose_cgh_Onelevel(int nprocs, int lev, void recompose_cgh_Onelevel(int nprocs, int lev,
MyList<var> *OldList, MyList<var> *StateList, MyList<var> *OldList, MyList<var> *StateList,
MyList<var> *FutureList, MyList<var> *tmList, MyList<var> *FutureList, MyList<var> *tmList,
int Symmetry, bool BB); int Symmetry, bool BB);
void Regrid_Onelevel(int lev, int Symmetry, int BH_num, double **Porgbr, double **Porg0, void Regrid_Onelevel(int lev, int Symmetry, int BH_num, double **Porgbr, double **Porg0,
MyList<var> *OldList, MyList<var> *StateList, MyList<var> *OldList, MyList<var> *StateList,
MyList<var> *FutureList, MyList<var> *tmList, bool BB, MyList<var> *FutureList, MyList<var> *tmList, bool BB,
monitor *ErrorMonitor); monitor *ErrorMonitor);
void Regrid_Onelevel_aux(int lev, int Symmetry, int BH_num, double **Porgbr, double **Porg0, void Regrid_Onelevel_aux(int lev, int Symmetry, int BH_num, double **Porgbr, double **Porg0,
MyList<var> *OldList, MyList<var> *StateList, MyList<var> *OldList, MyList<var> *StateList,
MyList<var> *FutureList, MyList<var> *tmList, bool BB, MyList<var> *FutureList, MyList<var> *tmList, bool BB,
monitor *ErrorMonitor); monitor *ErrorMonitor);
void settrfls(const int lev); void settrfls(const int lev);
#if (PSTR == 1 || PSTR == 2 || PSTR == 3) #if (PSTR == 1 || PSTR == 2 || PSTR == 3)
void construct_mylev(int nprocs); void construct_mylev(int nprocs);
#endif #endif
};
// Load balancing support
#endif /* CGH_H */ bool enable_load_balance; // Enable load balancing
int load_balance_check_interval; // Check interval (in time steps)
int current_time_step; // Current time step counter
double *rank_interp_times; // Store interpolation times for each rank
int *heavy_ranks; // Store heavy rank numbers
int num_heavy_ranks; // Number of heavy ranks
void init_load_balance(int nprocs);
void update_interp_time(int rank, double time);
bool check_and_rebalance(int nprocs, int lev,
MyList<var> *OldList, MyList<var> *StateList,
MyList<var> *FutureList, MyList<var> *tmList,
int Symmetry, bool BB);
};
#endif /* CGH_H */

File diff suppressed because it is too large Load Diff