Skip to content

Commit 29ab449

Browse files
committed
parallel second order FSM
1 parent ce256d3 commit 29ab449

File tree

16 files changed

+1156
-350
lines changed

16 files changed

+1156
-350
lines changed

docs/source/examples/01_uniform.ipynb

Lines changed: 55 additions & 3 deletions
Large diffs are not rendered by default.

docs/source/examples/01_uniform_spherical.ipynb

Lines changed: 166 additions & 0 deletions
Large diffs are not rendered by default.

docs/source/examples/02_cplxmodel_raytracing.ipynb

Lines changed: 81 additions & 29 deletions
Large diffs are not rendered by default.

docs/source/examples/02_random_model.ipynb

Lines changed: 48 additions & 5 deletions
Large diffs are not rendered by default.

docs/source/examples/03_spherical2.ipynb

Lines changed: 236 additions & 0 deletions
Large diffs are not rendered by default.

docs/source/examples/04_distance.ipynb

Lines changed: 17 additions & 10 deletions
Large diffs are not rendered by default.

docs/source/jupyter_examples.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ Jupyter 使用示例
1515
:maxdepth: 2
1616

1717
examples/01_uniform
18+
examples/01_uniform_spherical
1819
examples/02_random_model
1920
examples/02_cplxmodel_raytracing
2021
examples/03_spherical
22+
examples/03_spherical2
2123
examples/04_distance
2224

pyfmm/C_extension/Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ LIB_NAME = $(LIB_DIR)$(FILESEP)libfmm
3535
LIB_EXT = .so
3636

3737
CC = gcc
38-
CFLAGS = -O3 -g -ffast-math -march=native -mtune=native -fPIC -Wimplicit-function-declaration -I$(INC_DIR) -lm # -fsanitize=address -lasan
39-
LDFLAGS = -shared -lm # -lasan
38+
FOMPFLAGS = -fopenmp
39+
CFLAGS = $(FOMPFLAGS) -O3 -g -ffast-math -march=native -mtune=native -fPIC -Wimplicit-function-declaration -I$(INC_DIR) -lm # -fsanitize=address -lasan
40+
LDFLAGS = $(FOMPFLAGS) -shared -lm # -lasan
4041

4142
SRCS = $(wildcard $(SRC_DIR)/*.c)
4243
INCS = $(wildcard $(INC_DIR)/*.h)

pyfmm/C_extension/include/fsm.h

Lines changed: 75 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,79 @@
77
#pragma once
88

99
#include "const.h"
10+
#include "heapsort.h"
11+
12+
13+
/**
14+
* 定义OpenMP多线程数
15+
*
16+
* @param num_threads (in)线程数
17+
*/
18+
void set_fsm_num_threads(int num_threads);
19+
20+
21+
/**
22+
* 使用Fast Sweeping Method计算全局走时场
23+
*
24+
* @param rs (in)维度1坐标数组
25+
* @param nr (in)rs长度
26+
* @param ts (in)维度2坐标数组
27+
* @param nt (in)ts长度
28+
* @param ps (in)维度2坐标数组
29+
* @param np (in)ps长度
30+
* @param rr (in)源点维度1坐标
31+
* @param tt (in)源点维度2坐标
32+
* @param pp (in)源点维度3坐标
33+
* @param maxodr (in)使用的最大差分阶数
34+
* @param Slw (in)展平的三维慢度场
35+
* @param TT (inout)展平的三维走时场,如果初始值有非零值,会被直接加入堆中,此时源点不再使用
36+
* @param sphcoord (in)是否使用球坐标
37+
* @param rfgfac (in)对于源点附近的格点间加密倍数,>1
38+
* @param rfgn (in)对于源点附近的格点间加密处理的辐射半径,>=1
39+
* @param printbar (in)是否打印进度条
40+
* @param eps (in)Sweep后的最大更新量达到收敛条件
41+
* @param maxLoops (in)Fast Sweeping Method整体迭代次数(对于3D模型,向8个方向各Sweep一次为迭代一次)
42+
* @param isparallel (in)是否使用并行FSM
43+
*
44+
*
45+
*/
46+
int FastSweeping(
47+
const double *rs, int nr,
48+
const double *ts, int nt,
49+
const double *ps, int np,
50+
double rr, double tt, double pp,
51+
int maxodr, const MYREAL *Slw,
52+
MYREAL *TT, bool sphcoord,
53+
int rfgfac, int rfgn, bool printbar,
54+
double eps, int maxLoops, bool isparallel);
55+
56+
57+
/**
58+
* 在有初始走时的情况下使用Fast Marching Method计算全局走时场
59+
*
60+
* @param rs (in)维度1坐标数组
61+
* @param nr (in)rs长度
62+
* @param ts (in)维度2坐标数组
63+
* @param nt (in)ts长度
64+
* @param ps (in)维度2坐标数组
65+
* @param np (in)ps长度
66+
* @param maxodr (in)使用的最大差分阶数
67+
* @param Slw (in)展平的三维慢度场
68+
* @param TT (inout)展平的三维走时场
69+
* @param FMM_stat (out)记录每个节点的状态(alive, close, far)
70+
* @param sphcoord (in)是否使用球坐标
71+
* @param printbar (in)是否打印进度条
72+
* @param eps (in)Sweep后的最大更新量达到收敛条件
73+
* @param maxLoops (in)Fast Sweeping Method整体迭代次数(对于3D模型,向8个方向各Sweep一次为迭代一次)
74+
* @param isparallel (in)是否使用并行FSM
75+
*
76+
* @return nsweep,
77+
*/
78+
int FastSweeping_with_initial(
79+
const double *rs, int nr,
80+
const double *ts, int nt,
81+
const double *ps, int np,
82+
int maxodr, const MYREAL *Slw, MYREAL *TT,
83+
char *FMM_stat, bool sphcoord, bool printbar,
84+
double eps, int maxLoops, bool isparallel);
1085

11-
typedef struct _FSW_DATA {
12-
// int idx;
13-
MYREAL t;
14-
double h;
15-
} FSW_DATA;

pyfmm/C_extension/src/fmm.c

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ HEAP_DATA * FastMarching_with_initial(
137137
double sin_ts[nt];
138138
if(sphcoord){
139139
for(int it=0; it<nt; ++it){
140-
sin_ts[it] = sin(ts[it]);
141-
if(fabs(sin_ts[it]) < 1e-12) sin_ts[it] += 1e-12;
140+
sin_ts[it] = fabs(sin(ts[it]));
141+
if(sin_ts[it] < 1e-12) sin_ts[it] += 1e-12;
142142
}
143143
}
144144

@@ -592,7 +592,7 @@ HEAP_DATA * init_source_TT_refinegrid(
592592
TT[jdx] = rfg_TT[rfg_jdx];
593593
// printf("rfg_TT = %f, jr, jt, jp %d, %d, %d\n", rfg_TT[rfg_jdx], jr, jt, jp);
594594
FMM_stat[jdx] = FMM_ALV;
595-
(*pNdots)--;
595+
if(pNdots!=NULL) (*pNdots)--;
596596
}
597597
if(jdx1>=0){
598598
FMM_data = HeapPush(FMM_data, psize, pcap, jdx1, NroIdx, TT);
@@ -828,16 +828,6 @@ MYREAL FMM_raytracing(
828828

829829

830830
int ntp = nt*np;
831-
832-
double sin_ts[nt];
833-
if(sphcoord){
834-
for(int it=0; it<nt; ++it){
835-
sin_ts[it] = sin(ts[it]);
836-
if(fabs(sin_ts[it]) < 1e-6) sin_ts[it] += 1e-6;
837-
}
838-
} else {
839-
for(int it=0; it<nt; sin_ts[it]=0.0, ++it);
840-
}
841831

842832
int idot = 0;
843833

0 commit comments

Comments
 (0)