-
Notifications
You must be signed in to change notification settings - Fork 15
/
BasCart_gpu.cu
4835 lines (3614 loc) · 147 KB
/
BasCart_gpu.cu
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//////////////////////////////////////////////////////////////////////////////////
// //
//Copyright (C) 2018 Bosserelle //
// This code contains an adaptation of the St Venant equation from Basilisk //
// See //
// http://basilisk.fr/src/saint-venant.h and //
// S. Popinet. Quadtree-adaptive tsunami modelling. Ocean Dynamics, //
// doi: 61(9) : 1261 - 1285, 2011 //
// //
//This program is free software: you can redistribute it and/or modify //
//it under the terms of the GNU General Public License as published by //
//the Free Software Foundation. //
// //
//This program is distributed in the hope that it will be useful, //
//but WITHOUT ANY WARRANTY; without even the implied warranty of //
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
//GNU General Public License for more details. //
// //
//You should have received a copy of the GNU General Public License //
//along with this program. If not, see <http://www.gnu.org/licenses/>. //
//////////////////////////////////////////////////////////////////////////////////
// includes, system
#include "Header.cuh"
#ifdef USE_CATALYST
#include "catalyst_adaptor.h"
#endif
//double phi = (1.0f + sqrt(5.0f)) / 2;
//double aphi = 1 / (phi + 1);
//double bphi = phi / (phi + 1);
//double twopi = 8 * atan(1.0f);
double epsilon = 1e-30;
//double g = 1.0;// 9.81;
//double rho = 1025.0;
//double eps = 0.0001;
//double CFL = 0.5;
//
//double totaltime = 0.0;
//
//
//double dt, dx;
//int nx, ny;
//
//double delta;
double *x, *y;
double *x_g, *y_g;
float *zs, *hh, *zb, *uu, *vv;//for CPU
double *zs_d, *hh_d, *zb_d, *uu_d, *vv_d; // double array only allocated instead of thge float if requested
float *zs_g, *hh_g, *zb_g, *uu_g, *vv_g; // for GPU
double *zs_gd, *hh_gd, *zb_gd, *uu_gd, *vv_gd;
float *zso, *hho, *uuo, *vvo;
double *zso_d, *hho_d, *uuo_d, *vvo_d;
float *zso_g, *hho_g, *uuo_g, *vvo_g; // for GPU
double *zso_gd, *hho_gd, *uuo_gd, *vvo_gd;
//CPU
float * dhdx, *dhdy, *dudx, *dudy, *dvdx, *dvdy;
float *dzsdx, *dzsdy;
//GPU
float * dhdx_g, *dhdy_g, *dudx_g, *dudy_g, *dvdx_g, *dvdy_g;
float *dzsdx_g, *dzsdy_g;
//double *fmu, *fmv;
double * dhdx_d, *dhdy_d, *dudx_d, *dudy_d, *dvdx_d, *dvdy_d;
double *dzsdx_d, *dzsdy_d;
double * dhdx_gd, *dhdy_gd, *dudx_gd, *dudy_gd, *dvdx_gd, *dvdy_gd;
double *dzsdx_gd, *dzsdy_gd;
float *Su, *Sv, *Fqux, *Fquy, *Fqvx, *Fqvy;
float * Fhu, *Fhv;
float * dh, *dhu, *dhv;
double *Su_d, *Sv_d, *Fqux_d, *Fquy_d, *Fqvx_d, *Fqvy_d;
double * Fhu_d, *Fhv_d;
double * dh_d, *dhu_d, *dhv_d;
//GPU
float *Su_g, *Sv_g, *Fqux_g, *Fquy_g, *Fqvx_g, *Fqvy_g;
float * Fhu_g, *Fhv_g;
float * dh_g, *dhu_g, *dhv_g;
double *Su_gd, *Sv_gd, *Fqux_gd, *Fquy_gd, *Fqvx_gd, *Fqvy_gd;
double * Fhu_gd, *Fhv_gd;
double * dh_gd, *dhu_gd, *dhv_gd;
float * TSstore, *TSstore_g;
double * TSstore_d, *TSstore_gd;
float * hhmean, *uumean, *vvmean, *zsmean;
float * hhmean_g, *uumean_g, *vvmean_g, *zsmean_g;
double * hhmean_d, *uumean_d, *vvmean_d, *zsmean_d;
double * hhmean_gd, *uumean_gd, *vvmean_gd, *zsmean_gd;
float * hhmax, *uumax, *vvmax, *zsmax;
float * hhmax_g, *uumax_g, *vvmax_g, *zsmax_g;
double * hhmax_d, *uumax_d, *vvmax_d, *zsmax_d;
double * hhmax_gd, *uumax_gd, *vvmax_gd, *zsmax_gd;
float * vort, *vort_g;// Vorticity output
double * vort_d, *vort_gd;
float dtmax = (float) (1.0 / epsilon);
double dtmax_d = 1.0 / epsilon;
double * dtmax_gd;
float * dtmax_g;
float *arrmax_g;
float *arrmin_g;
float *arrmin;
double *arrmax_gd;
double *arrmin_gd;
double *arrmin_d;
float * dummy;
double * dummy_d;
float* bathydata;
float * cf;
float * cf_g;
double * cf_d;
double * cf_gd;
// Block info
float * blockxo, *blockyo;
double * blockxo_d, *blockyo_d;
int * leftblk, *rightblk, *topblk, *botblk;
int * bndleftblk, *bndrightblk, *bndtopblk, *bndbotblk;
double * blockxo_gd, *blockyo_gd;
float * blockxo_g, *blockyo_g;
int * leftblk_g, *rightblk_g, *topblk_g, *botblk_g;
int * bndleftblk_g, *bndrightblk_g, *bndtopblk_g, *bndbotblk_g;
//River stuff
int * Riverblk, *Riverblk_g;
// Wind arrays
float * Uwind, *Uwbef, *Uwaft;
float * Vwind, *Vwbef, *Vwaft;
float * PatmX, *Patmbef, *Patmaft;
float * Patm, *dPdx, *dPdy;
double * Patm_d, *dPdx_d, *dPdy_d;
float * Uwind_g, *Uwbef_g, *Uwaft_g;
float * Vwind_g, *Vwbef_g, *Vwaft_g;
float * PatmX_g, *Patmbef_g, *Patmaft_g;
float * Patm_g, *dPdx_g, *dPdy_g;
double * Patm_gd, *dPdx_gd, *dPdy_gd;
//rain on grid
float *Rain, *Rainbef, *Rainaft;
float *Rain_g, *Rainbef_g, *Rainaft_g;
// Adaptivity
int * level, *level_g, *newlevel, *newlevel_g, *activeblk, *availblk, * invactive, *activeblk_g, *availblk_g, *csumblk, *csumblk_g,* invactive_g ;
bool* coarsen, * refine;;
//std::string outfile = "output.nc";
//std::vector<std::string> outvars;
std::map<std::string, float *> OutputVarMapCPU;
std::map<std::string, double *> OutputVarMapCPUD;
std::map<std::string, float *> OutputVarMapGPU;
std::map<std::string, double *> OutputVarMapGPUD;
std::map<std::string, int> OutputVarMaplen;
cudaArray* leftWLS_gp; // Cuda array to pre-store HD vel data before converting to textures
cudaArray* rightWLS_gp;
cudaArray* topWLS_gp;
cudaArray* botWLS_gp;
cudaArray* leftUvel_gp;
cudaArray* rightUvel_gp;
cudaArray* topUvel_gp;
cudaArray* botUvel_gp;
cudaArray* leftVvel_gp;
cudaArray* rightVvel_gp;
cudaArray* topVvel_gp;
cudaArray* botVvel_gp;
// store wind data in cuda array before sending to texture memory
cudaArray* Uwind_gp;
cudaArray* Vwind_gp;
cudaArray* Patm_gp;
cudaArray* Rain_gp;
cudaChannelFormatDesc channelDescleftbndzs = cudaCreateChannelDesc(32, 0, 0, 0, cudaChannelFormatKindFloat);
cudaChannelFormatDesc channelDescrightbndzs = cudaCreateChannelDesc(32, 0, 0, 0, cudaChannelFormatKindFloat);
cudaChannelFormatDesc channelDescbotbndzs = cudaCreateChannelDesc(32, 0, 0, 0, cudaChannelFormatKindFloat);
cudaChannelFormatDesc channelDesctopbndzs = cudaCreateChannelDesc(32, 0, 0, 0, cudaChannelFormatKindFloat);
cudaChannelFormatDesc channelDescleftbnduu = cudaCreateChannelDesc(32, 0, 0, 0, cudaChannelFormatKindFloat);
cudaChannelFormatDesc channelDescrightbnduu = cudaCreateChannelDesc(32, 0, 0, 0, cudaChannelFormatKindFloat);
cudaChannelFormatDesc channelDescbotbnduu = cudaCreateChannelDesc(32, 0, 0, 0, cudaChannelFormatKindFloat);
cudaChannelFormatDesc channelDesctopbnduu = cudaCreateChannelDesc(32, 0, 0, 0, cudaChannelFormatKindFloat);
cudaChannelFormatDesc channelDescleftbndvv = cudaCreateChannelDesc(32, 0, 0, 0, cudaChannelFormatKindFloat);
cudaChannelFormatDesc channelDescrightbndvv = cudaCreateChannelDesc(32, 0, 0, 0, cudaChannelFormatKindFloat);
cudaChannelFormatDesc channelDescbotbndvv = cudaCreateChannelDesc(32, 0, 0, 0, cudaChannelFormatKindFloat);
cudaChannelFormatDesc channelDesctopbndvv = cudaCreateChannelDesc(32, 0, 0, 0, cudaChannelFormatKindFloat);
cudaChannelFormatDesc channelDescUwind = cudaCreateChannelDesc(32, 0, 0, 0, cudaChannelFormatKindFloat);
cudaChannelFormatDesc channelDescVwind = cudaCreateChannelDesc(32, 0, 0, 0, cudaChannelFormatKindFloat);
cudaChannelFormatDesc channelDescPatm = cudaCreateChannelDesc(32, 0, 0, 0, cudaChannelFormatKindFloat);
cudaChannelFormatDesc channelDescRain = cudaCreateChannelDesc(32, 0, 0, 0, cudaChannelFormatKindFloat);
// Below file are included rather than compiled separately because this allow to use Template for function
// Otherwise I would need to keep a double and a single precision copy of almost most function wich would be impossible to manage
#include "Flow_kernel.cu"
#include "Init.cpp" // excluded from direct buil to move the template out of the main source
#include "Init_gpu.cu"
#include "Adapt_Flow_kernel.cu"
#include "Adapt_gpu.cu"
#include "write_output.cu"
#include "Mainloop_Adapt.cu"
// Main loop that actually runs the model.
void mainloopGPUDB(Param XParam)
{
double nextoutputtime = XParam.totaltime + XParam.outputtimestep;
int nstep = 0;
int nTSsteps = 0;
int rainstep = 1;
double rainuni = 0.0;
std::vector<Pointout> zsout;
std::vector< std::vector< Pointout > > zsAllout;
Pointout stepread;
FILE * fsSLTS;
dim3 blockDimRain(16, 16, 1);// The grid has a better ocupancy when the size is a factor of 16 on both x and y
//dim3 gridDim(ceil((XParam.nx*1.0) / blockDim.x), ceil((XParam.ny*1.0) / blockDim.y), 1);
dim3 gridDimRain((int)ceil((float)XParam.Rainongrid.nx / (float)blockDimRain.x), (int)ceil((float)XParam.Rainongrid.ny / (float)blockDimRain.y), 1);
dim3 blockDim(16, 16, 1);// The grid has a better ocupancy when the size is a factor of 16 on both x and y
//dim3 gridDim(ceil((XParam.nx*1.0) / blockDim.x), ceil((XParam.ny*1.0) / blockDim.y), 1);
dim3 gridDim(XParam.nblk, 1, 1);
for (int o = 0; o < XParam.TSoutfile.size(); o++)
{
//Overwrite existing files
fsSLTS = fopen(XParam.TSoutfile[o].c_str(), "w");
fprintf(fsSLTS, "# x=%f\ty=%f\ti=%d\tj=%d\t%s\n", XParam.TSnodesout[o].x, XParam.TSnodesout[o].y, XParam.TSnodesout[o].i, XParam.TSnodesout[o].j, XParam.TSoutfile[o].c_str());
fclose(fsSLTS);
// Add empty row for each output point
zsAllout.push_back(std::vector<Pointout>());
}
ResetmeanvarGPUD(XParam);
ResetmaxvarGPUD(XParam);
while (XParam.totaltime < XParam.endtime)
{
// Bnd stuff here
LeftFlowBnd(XParam);
RightFlowBnd(XParam);
TopFlowBnd(XParam);
BotFlowBnd(XParam);
// External forcing
if (!XParam.Rainongrid.inputfile.empty())
{
//(Param XParam, dim3 gridDimRain, dim3 blockDimRain, int & rainstep, double rainuni)
//this function moves in the forcing file for both inuform and variable input
rainuni = Rainthisstep(XParam, gridDimRain, blockDimRain, rainstep);
}
// Core
XParam.dt = FlowGPUDouble(XParam, nextoutputtime);
//add rivers
if (XParam.Rivers.size() > 0)
{
RiverSourceD(XParam);
}
// add rain
if (!XParam.Rainongrid.inputfile.empty())
{
if (XParam.Rainongrid.uniform == 1)
{
Rain_on_gridUNI << <gridDim, blockDim, 0 >> > (XParam.mask, rainuni, XParam.dt, zs_gd, hh_gd);
CUDA_CHECK(cudaDeviceSynchronize());
}
else
{
//(int unirain, float xorain, float yorain, float dxrain, double delta, double*blockxo, double *blockyo, double dt, T * zs, T *hh)
Rain_on_grid << <gridDim, blockDim, 0 >> > (XParam.mask, XParam.Rainongrid.xo, XParam.Rainongrid.yo, XParam.Rainongrid.dx, XParam.delta, blockxo_gd, blockyo_gd, XParam.dt, zs_gd, hh_gd);
CUDA_CHECK(cudaDeviceSynchronize());
}
}
//Time keeping
XParam.totaltime = XParam.totaltime + XParam.dt;
nstep++;
// Do Sum & Max variables Here
meanmaxvarGPUD(XParam);
//check, store Timeseries output
if (XParam.TSnodesout.size() > 0)
{
pointoutputstep(XParam, gridDim, blockDim, nTSsteps, zsAllout);
}
if (nextoutputtime - XParam.totaltime <= XParam.dt*0.00001f && XParam.outputtimestep > 0.0)
{
// Save output step
DivmeanvarGPUD(XParam, nstep);
if (XParam.outvort == 1)
{
CalcVorticity << <gridDim, blockDim, 0 >> > (vort_gd, dvdx_gd, dudy_gd);
CUDA_CHECK(cudaDeviceSynchronize());
}
if (!XParam.outvars.empty())
{
writenctimestep(XParam.outfile, XParam.totaltime);
for (int ivar = 0; ivar < XParam.outvars.size(); ivar++)
{
if (OutputVarMaplen[XParam.outvars[ivar]] > 0)
{
if (XParam.GPUDEVICE >= 0)
{
//Should be async
CUDA_CHECK(cudaMemcpy(OutputVarMapCPUD[XParam.outvars[ivar]], OutputVarMapGPUD[XParam.outvars[ivar]], OutputVarMaplen[XParam.outvars[ivar]] * sizeof(double), cudaMemcpyDeviceToHost));
}
//Create definition for each variable and store it
//writencvarstep(XParam, blockxo_d, blockyo_d, XParam.outvars[ivar], OutputVarMapCPUD[XParam.outvars[ivar]]);
writencvarstepBUQ(XParam, 3, activeblk, level, blockxo_d, blockyo_d, XParam.outvars[ivar], OutputVarMapCPUD[XParam.outvars[ivar]]);
}
}
}
// Log
nextoutputtime = min(nextoutputtime + XParam.outputtimestep, XParam.endtime);
printf("Writing output, totaltime:%f s, Mean dt=%f\n", XParam.totaltime, XParam.outputtimestep / nstep);
write_text_to_log_file("Writing outputs, totaltime: " + std::to_string(XParam.totaltime) + ", Mean dt= " + std::to_string(XParam.outputtimestep / nstep));
//Reset Avg Variables
ResetmeanvarGPUD(XParam);
if (XParam.resetmax == 1)
{
ResetmaxvarGPUD(XParam);
}
// Reset nstep
nstep = 0;
}
}
}
void mainloopGPUDATM(Param XParam) // float, metric coordinate
{
double nextoutputtime = XParam.totaltime + XParam.outputtimestep;
int nstep = 0;
int nTSsteps = 0;
int windstep = 1;
int atmpstep = 1;
int rainstep = 1;
double rainuni = 0.0;
double uwinduni = 0.0;
double vwinduni = 0.0;
double atmpuni = XParam.Paref;
std::vector<Pointout> zsout;
std::vector< std::vector< Pointout > > zsAllout;
Pointout stepread;
FILE * fsSLTS;
dim3 blockDim(16, 16, 1);// The grid has a better ocupancy when the size is a factor of 16 on both x and y
//dim3 gridDim(ceil((XParam.nx*1.0) / blockDim.x), ceil((XParam.ny*1.0) / blockDim.y), 1);
dim3 gridDim(XParam.nblk, 1, 1);
dim3 blockDimWND(16, 16, 1);// The grid has a better ocupancy when the size is a factor of 16 on both x and y
//dim3 gridDim(ceil((XParam.nx*1.0) / blockDim.x), ceil((XParam.ny*1.0) / blockDim.y), 1);
dim3 gridDimWND((int)ceil((float)XParam.windU.nx / (float)blockDimWND.x), (int)ceil((float)XParam.windU.ny / (float)blockDimWND.y), 1);
dim3 blockDimATM(16, 16, 1);// The grid has a better ocupancy when the size is a factor of 16 on both x and y
//dim3 gridDim(ceil((XParam.nx*1.0) / blockDim.x), ceil((XParam.ny*1.0) / blockDim.y), 1);
dim3 gridDimATM((int)ceil((float)XParam.atmP.nx / (float)blockDimATM.x), (int)ceil((float)XParam.atmP.ny / (float)blockDimATM.y), 1);
dim3 blockDimRain(16, 16, 1);// The grid has a better ocupancy when the size is a factor of 16 on both x and y
//dim3 gridDim(ceil((XParam.nx*1.0) / blockDim.x), ceil((XParam.ny*1.0) / blockDim.y), 1);
dim3 gridDimRain((int)ceil((float)XParam.Rainongrid.nx / (float)blockDimRain.x), (int)ceil((float)XParam.Rainongrid.ny / (float)blockDimRain.y), 1);
int winduniform = XParam.windU.uniform;
int atmpuniform = XParam.atmP.uniform;
if (XParam.windU.inputfile.empty())// this is should be true here so not really needed (?)
{
// set as uniform run 0 wind input below
winduniform = 1;
}
if (XParam.atmP.inputfile.empty())// this is should be true here so not really needed (?)
{
atmpuniform = 1;
}
for (int o = 0; o < XParam.TSoutfile.size(); o++)
{
//Overwrite existing files
fsSLTS = fopen(XParam.TSoutfile[o].c_str(), "w");
fprintf(fsSLTS, "# x=%f\ty=%f\ti=%d\tj=%d\t%s\n", XParam.TSnodesout[o].x, XParam.TSnodesout[o].y, XParam.TSnodesout[o].i, XParam.TSnodesout[o].j, XParam.TSoutfile[o].c_str());
fclose(fsSLTS);
// Add empty row for each output point
zsAllout.push_back(std::vector<Pointout>());
}
// Reset GPU mean and max arrays
ResetmeanvarGPU(XParam);
ResetmaxvarGPU(XParam);
while (XParam.totaltime < XParam.endtime)
{
// Bnd stuff here
LeftFlowBnd(XParam);
RightFlowBnd(XParam);
TopFlowBnd(XParam);
BotFlowBnd(XParam);
// Core engine
//XParam.dt = FlowGPUATM(XParam, nextoutputtime);
const int num_streams = 3;
cudaStream_t streams[num_streams];
for (int i = 0; i < num_streams; i++)
{
CUDA_CHECK(cudaStreamCreate(&streams[i]));
}
//dim3 blockDim(16, 16, 1);// The grid has a better ocupancy when the size is a factor of 16 on both x and y
//dim3 gridDim(ceil((nx*1.0f) / blockDim.x), ceil((ny*1.0f) / blockDim.y), 1);
dim3 blockDim(16, 16, 1);
dim3 gridDim(XParam.nblk, 1, 1);
dtmax = (1.0 / epsilon);
//float dtmaxtmp = dtmax;
// Check the atm Pressure forcing before starting
if (!XParam.atmP.inputfile.empty() && atmpuniform == 1) //this is a gven
{
//
AtmPthisstep(XParam, gridDimATM, blockDimATM, atmpstep);
interp2ATMP << <gridDim, blockDim, 0 >> > (XParam.atmP.xo, XParam.atmP.yo, XParam.atmP.dx, XParam.delta, XParam.Paref, blockxo_gd, blockyo_gd, Patm_gd);
CUDA_CHECK(cudaDeviceSynchronize());
}
// External forcing
if (!XParam.Rainongrid.inputfile.empty())
{
//(Param XParam, dim3 gridDimRain, dim3 blockDimRain, int & rainstep, double rainuni)
//this function moves in the forcing file for both inuform and variable input
rainuni = Rainthisstep(XParam, gridDimRain, blockDimRain, rainstep);
}
resetdtmax << <gridDim, blockDim, 0, streams[0] >> > (dtmax_gd);
//CUDA_CHECK(cudaDeviceSynchronize());
//update step 1
gradientGPUXYBUQSM << <gridDim, blockDim, 0, streams[0] >> >(XParam.theta, XParam.delta, leftblk_g, rightblk_g, topblk_g, botblk_g, hh_gd, dhdx_gd, dhdy_gd);
//CUDA_CHECK(cudaDeviceSynchronize());
gradientGPUXYBUQSM << <gridDim, blockDim, 0, streams[1] >> >(XParam.theta, XParam.delta, leftblk_g, rightblk_g, topblk_g, botblk_g, zs_gd, dzsdx_gd, dzsdy_gd);
//CUDA_CHECK(cudaDeviceSynchronize());
gradientGPUXYBUQSM << <gridDim, blockDim, 0, streams[0] >> >(XParam.theta, XParam.delta, leftblk_g, rightblk_g, topblk_g, botblk_g, uu_gd, dudx_gd, dudy_gd);
//CUDA_CHECK(cudaDeviceSynchronize());
gradientGPUXYBUQSM << <gridDim, blockDim, 0, streams[1] >> > (XParam.theta, XParam.delta, leftblk_g, rightblk_g, topblk_g, botblk_g, vv_gd, dvdx_gd, dvdy_gd);
if (atmpuni == 0)
{
gradientGPUXYBUQSM << <gridDim, blockDim, 0, streams[1] >> > (XParam.theta, XParam.delta, leftblk_g, rightblk_g, topblk_g, botblk_g, Patm_gd, dPdx_gd, dPdy_gd);
}
// Check the wind forcing at the same time here
if (!XParam.windU.inputfile.empty())
{
Windthisstep(XParam, gridDimWND, blockDimWND, streams[2], windstep, uwinduni, vwinduni);
}
CUDA_CHECK(cudaDeviceSynchronize());
//CUDA_CHECK(cudaStreamSynchronize(streams[0]));
if (atmpuni == 1)
{
updateKurgXD << <gridDim, blockDim, 0, streams[0] >> > (XParam.delta, XParam.g, XParam.eps, XParam.CFL, leftblk_g, hh_gd, zs_gd, uu_gd, vv_gd, dzsdx_gd, dhdx_gd, dudx_gd, dvdx_gd, Fhu_gd, Fqux_gd, Fqvx_gd, Su_gd, dtmax_gd);
//CUDA_CHECK(cudaDeviceSynchronize());
//CUDA_CHECK(cudaStreamSynchronize(streams[1]));
updateKurgYD << <gridDim, blockDim, 0, streams[1] >> > (XParam.delta, XParam.g, XParam.eps, XParam.CFL, botblk_g, hh_gd, zs_gd, uu_gd, vv_gd, dzsdy_gd, dhdy_gd, dudy_gd, dvdy_gd, Fhv_gd, Fqvy_gd, Fquy_gd, Sv_gd, dtmax_gd);
}
else
{
updateKurgXATM << <gridDim, blockDim, 0, streams[0] >> > (XParam.delta, XParam.g, XParam.eps, XParam.CFL, XParam.Pa2m, leftblk_g, hh_gd, zs_gd, uu_gd, vv_gd, Patm_gd, dzsdx_gd, dhdx_gd, dudx_gd, dvdx_gd, dPdx_gd, Fhu_gd, Fqux_gd, Fqvx_gd, Su_gd, dtmax_gd);
//CUDA_CHECK(cudaDeviceSynchronize());
//CUDA_CHECK(cudaStreamSynchronize(streams[1]));
updateKurgYATM << <gridDim, blockDim, 0, streams[1] >> > (XParam.delta, XParam.g, XParam.eps, XParam.CFL, XParam.Pa2m, botblk_g, hh_gd, zs_gd, uu_gd, vv_gd, Patm_gd, dzsdy_gd, dhdy_gd, dudy_gd, dvdy_gd, dPdy_gd, Fhv_gd, Fqvy_gd, Fquy_gd, Sv_gd, dtmax_gd);
}
CUDA_CHECK(cudaDeviceSynchronize());
//GPU Harris reduction #3. 8.3x reduction #0 Note #7 if a lot faster
// This was successfully tested with a range of grid size
//reducemax3 << <gridDimLine, blockDimLine, 64*sizeof(float) >> >(dtmax_g, arrmax_g, nx*ny)
int s = XParam.nblk*XParam.blksize;
int maxThreads = 256;
int threads = (s < maxThreads * 2) ? nextPow2((s + 1) / 2) : maxThreads;
int blocks = (s + (threads * 2 - 1)) / (threads * 2);
int smemSize = (threads <= 32) ? 2 * threads * sizeof(double) : threads * sizeof(double);
dim3 blockDimLine(threads, 1, 1);
dim3 gridDimLine(blocks, 1, 1);
double mindtmaxB;
reducemin3 << <gridDimLine, blockDimLine, smemSize >> > (dtmax_gd, arrmax_gd, s);
CUDA_CHECK(cudaDeviceSynchronize());
s = gridDimLine.x;
while (s > 1)//cpuFinalThreshold
{
threads = (s < maxThreads * 2) ? nextPow2((s + 1) / 2) : maxThreads;
blocks = (s + (threads * 2 - 1)) / (threads * 2);
smemSize = (threads <= 32) ? 2 * threads * sizeof(double) : threads * sizeof(double);
dim3 blockDimLineS(threads, 1, 1);
dim3 gridDimLineS(blocks, 1, 1);
CUDA_CHECK(cudaMemcpy(dtmax_gd, arrmax_gd, s * sizeof(double), cudaMemcpyDeviceToDevice));
reducemin3 << <gridDimLineS, blockDimLineS, smemSize >> > (dtmax_gd, arrmax_gd, s);
CUDA_CHECK(cudaDeviceSynchronize());
s = (s + (threads * 2 - 1)) / (threads * 2);
}
CUDA_CHECK(cudaMemcpy(dummy_d, arrmax_gd, 32 * sizeof(double), cudaMemcpyDeviceToHost));
mindtmaxB = dummy_d[0];
//32 seem safe here bu I wonder why it is not 1 for the largers arrays...
/*
for (int i = 0; i < 32; i++)
{
mindtmaxB = min(dummy[i], mindtmaxB);
printf("dt=%f\n", dummy[i]);
}
*/
//float diffdt = mindtmaxB - mindtmax;
XParam.dt = mindtmaxB;
if (ceil((nextoutputtime - XParam.totaltime) / XParam.dt)> 0.0)
{
XParam.dt = (nextoutputtime - XParam.totaltime) / ceil((nextoutputtime - XParam.totaltime) / XParam.dt);
}
//printf("dt=%f\n", XParam.dt);
if (winduniform == 1)
{
// simpler input if wind is uniform
updateEVATMWUNI << <gridDim, blockDim, 0 >> > (XParam.delta, XParam.g, XParam.lat*pi / 21600.0, uwinduni, vwinduni, XParam.Cd, rightblk_g, topblk_g, hh_gd, uu_gd, vv_gd, Fhu_gd, Fhv_gd, Su_gd, Sv_gd, Fqux_gd, Fquy_gd, Fqvx_gd, Fqvy_gd, dh_gd, dhu_gd, dhv_gd);
}
else
{
//updateEV << <gridDim, blockDim, 0 >> > ((float)XParam.delta, (float)XParam.g, rightblk_g, topblk_g, hh_g, uu_g, vv_g, Fhu_g, Fhv_g, Su_g, Sv_g, Fqux_g, Fquy_g, Fqvx_g, Fqvy_g, dh_g, dhu_g, dhv_g);
updateEVATM << <gridDim, blockDim, 0 >> > (XParam.delta, XParam.g, XParam.lat*pi / 21600.0, XParam.windU.xo, XParam.windU.yo, XParam.windU.dx, XParam.Cd, rightblk_g, topblk_g, blockxo_gd, blockyo_gd, hh_gd, uu_gd, vv_gd, Fhu_gd, Fhv_gd, Su_gd, Sv_gd, Fqux_gd, Fquy_gd, Fqvx_gd, Fqvy_gd, dh_gd, dhu_gd, dhv_gd);
}
CUDA_CHECK(cudaDeviceSynchronize());
//predictor (advance 1/2 dt)
Advkernel << <gridDim, blockDim, 0 >> >(XParam.dt*0.5, XParam.eps, hh_gd, zb_gd, uu_gd, vv_gd, dh_gd, dhu_gd, dhv_gd, zso_gd, hho_gd, uuo_gd, vvo_gd);
CUDA_CHECK(cudaDeviceSynchronize());
//corrector setp
//update again
gradientGPUXYBUQSM << <gridDim, blockDim, 0, streams[0] >> >(XParam.theta, XParam.delta, leftblk_g, rightblk_g, topblk_g, botblk_g, hho_gd, dhdx_gd, dhdy_gd);
//CUDA_CHECK(cudaDeviceSynchronize());
gradientGPUXYBUQSM << <gridDim, blockDim, 0, streams[1] >> >(XParam.theta, XParam.delta, leftblk_g, rightblk_g, topblk_g, botblk_g, zso_gd, dzsdx_gd, dzsdy_gd);
//CUDA_CHECK(cudaDeviceSynchronize());
gradientGPUXYBUQSM << <gridDim, blockDim, 0, streams[0] >> >(XParam.theta, XParam.delta, leftblk_g, rightblk_g, topblk_g, botblk_g, uuo_gd, dudx_gd, dudy_gd);
//CUDA_CHECK(cudaDeviceSynchronize());
gradientGPUXYBUQSM << <gridDim, blockDim, 0, streams[1] >> >(XParam.theta, XParam.delta, leftblk_g, rightblk_g, topblk_g, botblk_g, vvo_gd, dvdx_gd, dvdy_gd);
// No need to recalculate the gradient at this stage. (I'm not sure of that... we could reinterpolate the Patm 0.5dt foreward in time but that seems unecessary)
CUDA_CHECK(cudaDeviceSynchronize());
if (atmpuni == 1)
{
updateKurgXD << <gridDim, blockDim, 0, streams[0] >> > (XParam.delta, XParam.g, XParam.eps, XParam.CFL, leftblk_g, hho_gd, zso_gd, uuo_gd, vvo_gd, dzsdx_gd, dhdx_gd, dudx_gd, dvdx_gd, Fhu_gd, Fqux_gd, Fqvx_gd, Su_gd, dtmax_gd);
//CUDA_CHECK(cudaDeviceSynchronize());
updateKurgYD << <gridDim, blockDim, 0, streams[1] >> > (XParam.delta, XParam.g, XParam.eps, XParam.CFL, botblk_g, hho_gd, zso_gd, uuo_gd, vvo_gd, dzsdy_gd, dhdy_gd, dudy_gd, dvdy_gd, Fhv_gd, Fqvy_gd, Fquy_gd, Sv_gd, dtmax_gd);
}
else
{
updateKurgXATM << <gridDim, blockDim, 0, streams[0] >> > (XParam.delta, XParam.g, XParam.eps, XParam.CFL, XParam.Pa2m, leftblk_g, hho_gd, zso_gd, uuo_gd, vvo_gd, Patm_gd, dzsdx_gd, dhdx_gd, dudx_gd, dvdx_gd, dPdx_gd, Fhu_gd, Fqux_gd, Fqvx_gd, Su_gd, dtmax_gd);
//CUDA_CHECK(cudaDeviceSynchronize());
updateKurgYATM << <gridDim, blockDim, 0, streams[1] >> > (XParam.delta, XParam.g, XParam.eps, XParam.CFL, XParam.Pa2m, botblk_g, hho_gd, zso_gd, uuo_gd, vvo_gd, Patm_gd, dzsdy_gd, dhdy_gd, dudy_gd, dvdy_gd, dPdy_gd, Fhv_gd, Fqvy_gd, Fquy_gd, Sv_gd, dtmax_gd);
}
CUDA_CHECK(cudaDeviceSynchronize());
// no reduction of dtmax during the corrector step
if (winduniform == 1)
{
//
updateEVATMWUNI << <gridDim, blockDim, 0 >> > (XParam.delta, XParam.g, XParam.lat*pi / 21600.0, uwinduni, vwinduni, XParam.Cd, rightblk_g, topblk_g, hho_gd, uuo_gd, vvo_gd, Fhu_gd, Fhv_gd, Su_gd, Sv_gd, Fqux_gd, Fquy_gd, Fqvx_gd, Fqvy_gd, dh_gd, dhu_gd, dhv_gd);
}
else
{
//updateEV << <gridDim, blockDim, 0 >> > ((float)XParam.delta, (float)XParam.g, rightblk_g, topblk_g, hho_g, uuo_g, vvo_g, Fhu_g, Fhv_g, Su_g, Sv_g, Fqux_g, Fquy_g, Fqvx_g, Fqvy_g, dh_g, dhu_g, dhv_g);
updateEVATM << <gridDim, blockDim, 0 >> > (XParam.delta, XParam.g, XParam.lat*pi / 21600.0, XParam.windU.xo, XParam.windU.yo, XParam.windU.dx, XParam.Cd, rightblk_g, topblk_g, blockxo_gd, blockyo_gd, hho_gd, uuo_gd, vvo_gd, Fhu_gd, Fhv_gd, Su_gd, Sv_gd, Fqux_gd, Fquy_gd, Fqvx_gd, Fqvy_gd, dh_gd, dhu_gd, dhv_gd);
}
CUDA_CHECK(cudaDeviceSynchronize());
//
Advkernel << <gridDim, blockDim, 0 >> >(XParam.dt, XParam.eps, hh_gd, zb_gd, uu_gd, vv_gd, dh_gd, dhu_gd, dhv_gd, zso_gd, hho_gd, uuo_gd, vvo_gd);
CUDA_CHECK(cudaDeviceSynchronize());
//cleanup(nx, ny, hho, zso, uuo, vvo, hh, zs, uu, vv);
cleanupGPU << <gridDim, blockDim, 0 >> >(hho_gd, zso_gd, uuo_gd, vvo_gd, hh_gd, zs_gd, uu_gd, vv_gd);
CUDA_CHECK(cudaDeviceSynchronize());
//Bottom friction
bottomfriction << <gridDim, blockDim, 0 >> > (XParam.frictionmodel, XParam.dt, XParam.eps, cf_gd, hh_gd, uu_gd, vv_gd);
CUDA_CHECK(cudaDeviceSynchronize());
CUDA_CHECK(cudaStreamDestroy(streams[0]));
CUDA_CHECK(cudaStreamDestroy(streams[1]));
// Impose no slip condition by default
//noslipbndall << <gridDim, blockDim, 0 >> > (nx, ny, XParam.dt, XParam.eps, zb_g, zs_g, hh_g, uu_g, vv_g);
//CUDA_CHECK(cudaDeviceSynchronize());
// River
if (XParam.Rivers.size() > 0)
{
RiverSourceD(XParam);
}
// add rain
if (!XParam.Rainongrid.inputfile.empty())
{
if (XParam.Rainongrid.uniform == 1)
{
Rain_on_gridUNI << <gridDim, blockDim, 0 >> > (XParam.mask, rainuni, XParam.dt, zs_gd, hh_gd);
CUDA_CHECK(cudaDeviceSynchronize());
}
else
{
//(int unirain, float xorain, float yorain, float dxrain, double delta, double*blockxo, double *blockyo, double dt, T * zs, T *hh)
Rain_on_grid << <gridDim, blockDim, 0 >> > (XParam.mask, XParam.Rainongrid.xo, XParam.Rainongrid.yo, XParam.Rainongrid.dx, XParam.delta, blockxo_gd, blockyo_gd, XParam.dt, zs_gd, hh_gd);
CUDA_CHECK(cudaDeviceSynchronize());
}
}
//Time keeping
XParam.totaltime = XParam.totaltime + XParam.dt;
nstep++;
// Do Sum & Max variables Here
meanmaxvarGPUD(XParam);
//Check for TSoutput
if (XParam.TSnodesout.size() > 0)
{
pointoutputstep(XParam, gridDim, blockDim, nTSsteps, zsAllout);
}
if (nextoutputtime - XParam.totaltime <= XParam.dt*0.00001f && XParam.outputtimestep > 0.0)
{
// Avg var sum here
DivmeanvarGPUD(XParam, nstep*1.0f);
if (XParam.outvort == 1)
{
CalcVorticity << <gridDim, blockDim, 0 >> > (vort_gd, dvdx_gd, dudy_gd);
CUDA_CHECK(cudaDeviceSynchronize());
}
if (!XParam.outvars.empty())
{
writenctimestep(XParam.outfile, XParam.totaltime);
for (int ivar = 0; ivar < XParam.outvars.size(); ivar++)
{
if (OutputVarMaplen[XParam.outvars[ivar]] > 0)
{
if (XParam.GPUDEVICE >= 0)
{
//Should be async
CUDA_CHECK(cudaMemcpy(OutputVarMapCPU[XParam.outvars[ivar]], OutputVarMapGPU[XParam.outvars[ivar]], OutputVarMaplen[XParam.outvars[ivar]] * sizeof(float), cudaMemcpyDeviceToHost));
}
//Create definition for each variable and store it
//writencvarstep(XParam, blockxo_d, blockyo_d, XParam.outvars[ivar], OutputVarMapCPU[XParam.outvars[ivar]]);
writencvarstepBUQ(XParam, 3, activeblk, level, blockxo_d, blockyo_d, XParam.outvars[ivar], OutputVarMapCPUD[XParam.outvars[ivar]]);
}
}
}
nextoutputtime = min(nextoutputtime + XParam.outputtimestep, XParam.endtime);
printf("Writing output, totaltime:%f s, Mean dt=%f\n", XParam.totaltime, XParam.outputtimestep / nstep);
write_text_to_log_file("Writing outputs, totaltime: " + std::to_string(XParam.totaltime) + ", Mean dt= " + std::to_string(XParam.outputtimestep / nstep));
//.Reset Avg Variables
ResetmeanvarGPUD(XParam);
if (XParam.resetmax == 1)
{
ResetmaxvarGPUD(XParam);
}
//
// Reset nstep
nstep = 0;
} // End of output part
} //Main while loop
}
void mainloopGPUDSPH(Param XParam)// double precision and spherical coordinate system
{
double nextoutputtime = XParam.totaltime + XParam.outputtimestep;
int nstep = 0;
int rainstep = 1;
double rainuni = 0.0;
int nTSsteps = 0;
std::vector<Pointout> zsout;
std::vector< std::vector< Pointout > > zsAllout;
Pointout stepread;
FILE * fsSLTS;
dim3 blockDim(16, 16, 1);// The grid has a better ocupancy when the size is a factor of 16 on both x and y
//dim3 gridDim(ceil((XParam.nx*1.0) / blockDim.x), ceil((XParam.ny*1.0) / blockDim.y), 1);
dim3 gridDim(XParam.nblk, 1, 1);
for (int o = 0; o < XParam.TSoutfile.size(); o++)
{
//Overwrite existing files
fsSLTS = fopen(XParam.TSoutfile[o].c_str(), "w");
fprintf(fsSLTS, "# x=%f\ty=%f\ti=%d\tj=%d\t%s\n", XParam.TSnodesout[o].x, XParam.TSnodesout[o].y, XParam.TSnodesout[o].i, XParam.TSnodesout[o].j, XParam.TSoutfile[o].c_str());
fclose(fsSLTS);
// Add empty row for each output point
zsAllout.push_back(std::vector<Pointout>());
}
ResetmeanvarGPUD(XParam);
ResetmaxvarGPUD(XParam);
while (XParam.totaltime < XParam.endtime)
{
// Bnd stuff here
LeftFlowBnd(XParam);
RightFlowBnd(XParam);
TopFlowBnd(XParam);
BotFlowBnd(XParam);
// Core
XParam.dt = FlowGPUSpherical(XParam, nextoutputtime);
//Time keeping
XParam.totaltime = XParam.totaltime + XParam.dt;
nstep++;
// Add deformation?
if (XParam.deform.size() > 0 && (XParam.totaltime - XParam.dt ) <= XParam.deformmaxtime)
{
ApplyDeform(XParam,blockDim,gridDim,dummy_d, dh_gd,hh_gd, zs_gd, zb_gd );
// float * def;
// double *def_d;
// //Check each deform input
// for (int nd = 0; nd < XParam.deform.size(); nd++)
// {
// Allocate1CPU(XParam.deform[nd].grid.nx, XParam.deform[nd].grid.ny, def_d);
// Allocate1CPU(XParam.deform[nd].grid.nx, XParam.deform[nd].grid.ny, def);
// if ((XParam.totaltime - XParam.deform[nd].startime) <= XParam.dt && (XParam.totaltime - XParam.deform[nd].startime)>0.0)
// {
// readmapdata(XParam.deform[nd].grid, def);
//
// for (int k = 0; k<(XParam.deform[nd].grid.nx*XParam.deform[nd].grid.ny); k++)
// {
// def_d[k] = def[k];
// }
//
//
// interp2BUQ(XParam.nblk, XParam.blksize, XParam.dx, blockxo_d, blockyo_d, XParam.deform[nd].grid.nx, XParam.deform[nd].grid.ny, XParam.deform[nd].grid.xo, XParam.deform[nd].grid.xmax, XParam.deform[nd].grid.yo, XParam.deform[nd].grid.ymax, XParam.deform[nd].grid.dx, def_d, dummy_d);
// CUDA_CHECK(cudaMemcpy(dh_gd, dummy_d, XParam.nblk*XParam.blksize * sizeof(double), cudaMemcpyHostToDevice));
//
// if (XParam.deform[nd].duration > 0.0)
// {
//
// //do zs=zs+dummy/duration *(XParam.totaltime - XParam.deform[nd].startime);
// Deform << <gridDim, blockDim, 0 >> > (1.0 / XParam.deform[nd].duration *(XParam.totaltime - XParam.deform[nd].startime), dh_gd, zs_gd, zb_gd);
// CUDA_CHECK(cudaDeviceSynchronize());
// }
//
// else
// {
// //do zs=zs+dummy;
// Deform << <gridDim, blockDim, 0 >> > (1.0, dh_gd, zs_gd, zb_gd);
// CUDA_CHECK(cudaDeviceSynchronize());
// }
//
// }
// else if ((XParam.totaltime - XParam.deform[nd].startime) > XParam.dt && XParam.totaltime <= (XParam.deform[nd].startime + XParam.deform[nd].duration))
// {
// // read the data and store to dummy
// readmapdata(XParam.deform[nd].grid, def);
// for (int k = 0; k<(XParam.deform[nd].grid.nx*XParam.deform[nd].grid.ny); k++)
// {
// def_d[k] = def[k];
// }
//
//
// interp2BUQ(XParam.nblk, XParam.blksize, XParam.dx, blockxo_d, blockyo_d, XParam.deform[nd].grid.nx, XParam.deform[nd].grid.ny, XParam.deform[nd].grid.xo, XParam.deform[nd].grid.xmax, XParam.deform[nd].grid.yo, XParam.deform[nd].grid.ymax, XParam.deform[nd].grid.dx, def_d, dummy_d);
// CUDA_CHECK(cudaMemcpy(dh_gd, dummy_d, XParam.nblk*XParam.blksize * sizeof(double), cudaMemcpyHostToDevice));
//
// // DO zs=zs+dummy/duration*dt
// Deform << <gridDim, blockDim, 0 >> > (1.0 / XParam.deform[nd].duration *XParam.dt, dh_gd, zs_gd, zb_gd);
// CUDA_CHECK(cudaDeviceSynchronize());
//
//
// }
// free(def_d);
//
// }
}
// add rain ?
if (!XParam.Rainongrid.inputfile.empty())
{
if (XParam.Rainongrid.uniform == 1)
{
Rain_on_gridUNI << <gridDim, blockDim, 0 >> > (XParam.mask, rainuni, XParam.dt, zs_gd, hh_gd);
CUDA_CHECK(cudaDeviceSynchronize());
}
else
{
//(int unirain, float xorain, float yorain, float dxrain, double delta, double*blockxo, double *blockyo, double dt, T * zs, T *hh)
Rain_on_grid << <gridDim, blockDim, 0 >> > (XParam.mask, XParam.Rainongrid.xo, XParam.Rainongrid.yo, XParam.Rainongrid.dx, XParam.delta, blockxo_gd, blockyo_gd, XParam.dt, zs_gd, hh_gd);
CUDA_CHECK(cudaDeviceSynchronize());
}
}
// Do Sum & Max variables Here
meanmaxvarGPUD(XParam);
//check, store Timeseries output
if (XParam.TSnodesout.size() > 0)
{
pointoutputstep(XParam, gridDim, blockDim, nTSsteps, zsAllout);
}
if (nextoutputtime - XParam.totaltime <= XParam.dt*0.00001f && XParam.outputtimestep > 0.0)
{
// Save output step
DivmeanvarGPUD(XParam, nstep);
if (XParam.outvort == 1)
{
CalcVorticity << <gridDim, blockDim, 0 >> > (vort_gd, dvdx_gd, dudy_gd);
CUDA_CHECK(cudaDeviceSynchronize());
}
if (!XParam.outvars.empty())
{
writenctimestep(XParam.outfile, XParam.totaltime);
for (int ivar = 0; ivar < XParam.outvars.size(); ivar++)
{
if (OutputVarMaplen[XParam.outvars[ivar]] > 0)
{
if (XParam.GPUDEVICE >= 0)