-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path065d_One_complete_construct_SG_SGinv_GPU_Lon_strip2.R
179 lines (125 loc) · 4.45 KB
/
065d_One_complete_construct_SG_SGinv_GPU_Lon_strip2.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#=============
# 24 May 2024
#=============
# Aim:
# Want to know one complete construction time for SG,and SG_inv
# with part of the code offloaded to GPU
# Method:
# 059
# data:
# CAMS Lon_strip_2_new.rds (n = 6581, 8.05GB)
library(Matrix)
#==============
# GPU settings
#==============
#------
# torch
#------
# Set the library path to the desired directory
.libPaths("/bask/projects/v/vjgo8416-xchen")
# Load the torch library
library(torch)
cat("inter threads:", "\n")
torch_get_num_interop_threads()
cat("intra threads:", "\n")
torch_get_num_threads()
#-------------------------------
# check BLAS and OPENBLAS info: only 36 works
#-------------------------------
#install.packages("RhpcBLASctl")
.libPaths("/bask/projects/v/vjgo8416-xchen")
library(RhpcBLASctl)
#cat("Check Current BLAS Library", "\n")
#sessionInfo()
cat("Check the current number of BLAS threads", "\n")
blas_get_num_procs()
#blas_set_num_threads(36) will have error 139 exit
#cat("Updated BLAS threads:", "\n")
#blas_get_num_procs()
#-----------
# GPUmatrix
#------------
#install.packages("GPUmatrix", lib="/bask/projects/v/vjgo8416-xchen")
.libPaths("/bask/projects/v/vjgo8416-xchen")
library(GPUmatrix)
system("nvidia-smi")
#===========================
# One complete construction use CAMS df_Lon_Strip_1_new.rds
#===========================
#-----
# df
#-----
df_Lon_Strp_2_Srt <- readRDS("df_Lon_Strip_2_Sort_new.rds")
#----------
# 2D coords
#----------
crds <- cbind(df_Lon_Strp_2_Srt$Lon, df_Lon_Strp_2_Srt$Lat)
#head(crds)
#----------------------------------------
# Construct displacement matrix (DSP_mat)
#----------------------------------------
# Aim:
# for TST12 function to construct shft dist matrix
source("Fn_make_DSP_mat.R")
DSP <- make_DSP_mat(crds = crds)
#str(DSP[, , 1]) # num [1:6581, 1:6581]
#str(DSP[, , 2]) # num [1:6581, 1:6581]
#DSP[, , 1][1, 1:160] #for dlt_lon ini
# [49] 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
# [57] 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
# [65] 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.75
# [73] 0.75 0.75 0.75 0.75 0.75 0.75 0.75 0.75
#[81] 0.75 0.75 0.75 0.75 0.75 0.75 0.75 0.75
#DSP[, , 2][1, 1:20] #for dlt_lat ini
#[1] 0.00 0.75 1.50 2.25
#[5] 3.00 3.75 4.50 5.25
#[9] 6.00 6.75 7.50 15.75
#[13] 17.25 18.00 18.75 19.50
#[17] 20.25 21.00 21.75 22.50
#---------------------------
# Construct distance matrix
#---------------------------
# Aim:
# for H_adj and phi for UniCAR
DIST <- as.matrix(dist(crds, diag = T, upper = T))
Nb_radius <- 1.5 # degree
H_adj <- matrix(as.numeric(abs(DIST) < Nb_radius), nrow(DIST), nrow(DIST))
diag(H_adj) <- 0
#dim(H_adj) # 3793 3793
#length(which(H_adj != 0)) # 27772
#spec <- eigen(H_adj, symmetric = T, only.values = T)$val
#max(abs(spec)) # [1] 7.972814
#phi <- 1/max(abs(spec)) # [1] 0.1253745
#phi <- trunc(phi * 100)/100 # [1] 0.12
phi <- 0.12
#--------
# pars
#--------
hierarchy_data_CAMS <- data.frame(
node_id = c(1, 2, 3, 4, 5, 5),
par_id = c(NA, 1, 2, 3, c(4, 1))
)
p = 5
source("Fn_para_mat_construct.R")
all_pars_lst_CAR_2D_CMS <- All_paras_CAR_2D(p = 5, data = hierarchy_data_CAMS)
source("Fn_set_ini_vals.R")
A_1 <- Fn_set_ini_vals(pars_mat = all_pars_lst_CAR_2D_CMS[[1]], ini_vals = 1)
dlt_lon_02 <- Fn_set_ini_vals(pars_mat = all_pars_lst_CAR_2D_CMS[[2]], ini_vals = 0.2)
dlt_lat_04 <- Fn_set_ini_vals(pars_mat = all_pars_lst_CAR_2D_CMS[[3]], ini_vals = 0.4)
sig2_mat_1 <- Fn_set_ini_vals(pars_mat = all_pars_lst_CAR_2D_CMS[[4]], ini_vals = 1)
#===========================
# TST12_SG_SGInv_CAR_2D_GPU_RM
#===========================
source("Fn_TST12_SG_SGInv_CAR_2D_GPU.R")
system.time(
SG_SGinv_CAMS_Lon_Strip_2_GPU <- TST12_SG_SGInv_CAR_2D_GPU(p = 5, data = hierarchy_data_CAMS,
A_mat = A_1,
dsp_lon_mat = DSP[, , 1],
dsp_lat_mat = DSP[, , 2],
dlt_lon_mat = dlt_lon_02,
dlt_lat_mat = dlt_lat_04,
b = "Tri-Wave",
phi = phi, H_adj = H_adj,
sig2_mat = sig2_mat_1,
reg_ini = 1e-9, thres_ini = 1e-3)
)