-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathquda_interface.c
2852 lines (2379 loc) · 109 KB
/
quda_interface.c
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) 2015 Mario Schroeck
* 2016, 2017 Bartosz Kostrzewa
* 2018 Bartosz Kostrzewa, Ferenc Pittler
* 2019, 2020 Bartosz Kostrzewa
* 2021 Bartosz Kostrzewa, Marco Garofalo, Ferenc Pittler, Simone Bacchio
* 2022 Simone Romiti, Bartosz Kostrzewa
* 2023 Aniket Sen, Bartosz Kostrzewa
*
* This file is part of tmLQCD.
*
* tmLQCD 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, either version 3 of the License, or
* (at your option) any later version.
*
* tmLQCD 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 tmLQCD. If not, see <http://www.gnu.org/licenses/>.
*
*
***********************************************************************/
/***********************************************************************
*
* File quda_interface.h
*
* Authors: Mario Schroeck <[email protected]>
* Bartosz Kostrzewa <[email protected]>
*
* Interface to QUDA for multi-GPU inverters
*
* The externally accessible functions are
*
* void _initQuda()
* Initializes the QUDA library. Carries over the lattice size and the
* MPI process grid and thus must be called after initializing MPI.
* Currently it is called in init_operators() if optr->use_qudainverter
* flag is set.
* Memory for the QUDA gaugefield on the host is allocated but not filled
* yet (the latter is done in _loadGaugeQuda(), see below).
* Performance critical settings are done here and can be changed.
*
* void _endQuda()
* Finalizes the QUDA library. Call before MPI_Finalize().
*
* void _loadGaugeQuda()
* Copies and reorders the gaugefield on the host and copies it to the GPU.
* Must be called between last changes on the gaugefield (smearing etc.)
* and first call of the inverter. In particular, 'boundary(const double kappa)'
* must be called before if nontrivial boundary conditions are to be used since
* those will be applied directly to the gaugefield. Currently it is called just
* before the inversion is done (might result in wasted loads...).
* It checks whether the curently loaded gauge field corresponds to the gauge field
* about to be loaded and returns with a no-op if they agree.
*
* void _loadCloverQuda()
* Wrapper for loadCloverQuda() which checks that the currently loaded gauge field
* and the clover field about to be constructed agree. If they do, the currently
* loaded clover field is reused.
*
* void _setQudaMultigridParam()
* borrowed from QUDA multigrid_invert_test, sets up the input parameters
* for running the QUDA-MG implementation
*
* The functions
*
* int invert_eo_quda(...);
* int invert_doublet_eo_quda(...);
* void M_full_quda(...);
* void D_psi_quda(...);
*
* mimic their tmLQCD counterparts in functionality as well as input and
* output parameters. The invert functions will check the parameters
* g_mu, g_c_sw do decide which QUDA operator to create.
*
* To activate those, set "UseQudaInverter = yes" in the operator
* declaration of the input file. For details see the documentation.
*
* The function
*
* int invert_quda_direct(...);
*
* provides a direct interface to the QUDA solver and is not accessible through
* the input file.
*
* Notes:
*
* Minimum QUDA version is 0.7.0 (see https://github.com/lattice/quda/issues/151
* and https://github.com/lattice/quda/issues/157).
*
*
**************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <float.h>
#include <stdbool.h> // boolean types in C
#include "quda_interface.h"
#include "quda_types.h"
#include "boundary.h"
#include "linalg/convert_eo_to_lexic.h"
#include "linalg/mul_r.h"
#include "linalg/mul_gamma5.h"
#include "solver/solver.h"
#include "solver/solver_field.h"
#include "gettime.h"
#include "boundary.h"
#include "quda.h"
#include "global.h"
#include "operator.h"
#include "tm_debug_printf.h"
#include "phmc.h"
#include "quda_gauge_paths.inc"
#include "io/gauge.h"
#include "measure_gauge_action.h"
// nstore is generally like a gauge id, for measurements it identifies the gauge field
// uniquely
extern int nstore;
// define order of the spatial indices
// default is LX-LY-LZ-T, see below def. of local lattice size, this is related to
// the gamma basis transformation from tmLQCD -> UKQCD
// for details see https://github.com/lattice/quda/issues/157
#define USE_LZ_LY_LX_T 0
#define MAX(a,b) ((a)>(b)?(a):(b))
tm_QudaMGSetupState_t quda_mg_setup_state;
tm_QudaGaugeState_t quda_gauge_state;
tm_QudaCloverState_t quda_clover_state;
// gauge and invert paramameter structs; init. in _initQuda()
QudaGaugeParam gauge_param;
QudaInvertParam inv_param;
// params to pass to MG
QudaMultigridParam quda_mg_param;
QudaInvertParam mg_inv_param;
void* quda_mg_preconditioner;
// MGEigSolver params for all levels, these need to be around as they
// will be populated in _setQudaMultigridParam and then assigned
// on a per-level basis to QudaInvertParam members (if the EigSolver is enabled
// on the given level)
QudaEigParam mg_eig_param[QUDA_MAX_MG_LEVEL];
// input params specific to tmLQCD QUDA interface
tm_QudaParams_t quda_input;
// parameters for the eigensolver
QudaEigParam eig_param;
// pointer to the QUDA gaugefield
double *gauge_quda[4];
// re-initialized each time by _initMomQuda()
QudaGaugeParam f_gauge_param;
// pointer to the QUDA momentum field
double *mom_quda[4];
double *mom_quda_reordered[4];
// pointer to a temp. spinor, used for reordering etc.
double *tempSpinor;
// function that maps coordinates in the communication grid to MPI ranks
int commsMap(const int *coords, void *fdata) {
#if USE_LZ_LY_LX_T
int n[4] = {coords[3], coords[2], coords[1], coords[0]};
#else
int n[4] = {coords[3], coords[0], coords[1], coords[2]};
#endif
int rank = 0;
#ifdef TM_USE_MPI
MPI_Cart_rank( g_cart_grid, n, &rank );
#endif
return rank;
}
// variable to check if quda has been initialized
static int quda_initialized = 0;
void _setVerbosityQuda();
void _setQudaMultigridParam(QudaMultigridParam* mg_param);
void _setMGInvertParam(QudaInvertParam * mg_inv_param, const QudaInvertParam * const inv_param);
void _updateQudaMultigridPreconditioner(void);
void _setOneFlavourSolverParam(const double kappa, const double c_sw, const double mu,
const int solver_type, const int even_odd,
const double eps_sq, const int maxiter,
const int single_parity_solve, const int QpQm);
void set_default_gauge_param(QudaGaugeParam * gauge_param){
// local lattice size
#if USE_LZ_LY_LX_T
gauge_param->X[0] = LZ;
gauge_param->X[1] = LY;
gauge_param->X[2] = LX;
gauge_param->X[3] = T;
#else
gauge_param->X[0] = LX;
gauge_param->X[1] = LY;
gauge_param->X[2] = LZ;
gauge_param->X[3] = T;
#endif
gauge_param->anisotropy = 1.0;
gauge_param->type = QUDA_WILSON_LINKS;
gauge_param->gauge_order = QUDA_QDP_GAUGE_ORDER;
gauge_param->cpu_prec = QUDA_DOUBLE_PRECISION;
gauge_param->cuda_prec = QUDA_DOUBLE_PRECISION;
gauge_param->reconstruct = QUDA_RECONSTRUCT_NO;
gauge_param->reconstruct_sloppy = QUDA_RECONSTRUCT_NO;
gauge_param->reconstruct_precondition = QUDA_RECONSTRUCT_NO;
gauge_param->reconstruct_refinement_sloppy = QUDA_RECONSTRUCT_NO;
gauge_param->reconstruct_eigensolver = QUDA_RECONSTRUCT_NO;
gauge_param->gauge_fix = QUDA_GAUGE_FIXED_NO;
// For multi-GPU, ga_pad must be large enough to store a time-slice
int x_face_size = gauge_param->X[1]*gauge_param->X[2]*gauge_param->X[3]/2;
int y_face_size = gauge_param->X[0]*gauge_param->X[2]*gauge_param->X[3]/2;
int z_face_size = gauge_param->X[0]*gauge_param->X[1]*gauge_param->X[3]/2;
int t_face_size = gauge_param->X[0]*gauge_param->X[1]*gauge_param->X[2]/2;
int pad_size =MAX(x_face_size, y_face_size);
pad_size = MAX(pad_size, z_face_size);
pad_size = MAX(pad_size, t_face_size);
gauge_param->ga_pad = pad_size;
gauge_param->make_resident_gauge = QUDA_BOOLEAN_NO;
gauge_param->t_boundary = QUDA_PERIODIC_T;
}
void _setDefaultQudaParam(void){
reset_quda_gauge_state(&quda_gauge_state);
reset_quda_clover_state(&quda_clover_state);
reset_quda_mg_setup_state(&quda_mg_setup_state);
quda_mg_preconditioner = NULL;
// *** QUDA parameters begin here (sloppy prec. will be adjusted in invert)
QudaPrecision cpu_prec = QUDA_DOUBLE_PRECISION;
QudaPrecision cuda_prec = QUDA_DOUBLE_PRECISION;
QudaPrecision cuda_prec_sloppy = QUDA_SINGLE_PRECISION;
QudaPrecision cuda_prec_precondition = QUDA_SINGLE_PRECISION;
QudaTune tune = QUDA_TUNE_YES;
// *** the remainder should not be changed for this application
inv_param.Ls = 1;
set_default_gauge_param(&gauge_param);
gauge_param.cuda_prec_sloppy = cuda_prec_sloppy;
gauge_param.cuda_prec_refinement_sloppy = cuda_prec_sloppy;
gauge_param.cuda_prec_precondition = cuda_prec_precondition;
gauge_param.cuda_prec_eigensolver = cuda_prec_precondition;
inv_param.dagger = QUDA_DAG_NO;
inv_param.mass_normalization = QUDA_KAPPA_NORMALIZATION;
inv_param.solver_normalization = QUDA_DEFAULT_NORMALIZATION;
inv_param.pipeline = quda_input.pipeline;
inv_param.gcrNkrylov = quda_input.gcrNkrylov;
inv_param.residual_type = (QudaResidualType)(QUDA_L2_RELATIVE_RESIDUAL);
inv_param.tol_hq = 0.1;
// alternative reliable does not seem to work well with twisted mass (clover) fermions
inv_param.use_alternative_reliable = 0;
// Tests show that setting reliable_delta = 1e-1 results in good time to solution and good
// convergence also in double-half mixed precision
// However, it is important to set 'max_res_increase' and 'max_res_increase_total'
// to sufficiently large values
inv_param.reliable_delta = 1e-1;
inv_param.reliable_delta_refinement = 1e-1;
inv_param.max_res_increase = 10;
inv_param.max_res_increase_total = 40;
inv_param.use_sloppy_partial_accumulator = 0;
// domain decomposition preconditioner parameters
inv_param.inv_type_precondition = QUDA_CG_INVERTER;
inv_param.schwarz_type = QUDA_ADDITIVE_SCHWARZ;
inv_param.precondition_cycle = 1;
inv_param.tol_precondition = 1e-1;
inv_param.maxiter_precondition = 10;
inv_param.verbosity_precondition = QUDA_SILENT;
if( g_debug_level > 3 )
inv_param.verbosity_precondition = QUDA_SUMMARIZE;
if( g_debug_level > 5 )
inv_param.verbosity_precondition = QUDA_VERBOSE;
inv_param.omega = 1.0;
inv_param.cpu_prec = cpu_prec;
inv_param.cuda_prec = cuda_prec;
inv_param.cuda_prec_sloppy = cuda_prec_sloppy;
inv_param.cuda_prec_refinement_sloppy = cuda_prec_sloppy;
inv_param.cuda_prec_precondition = cuda_prec_precondition;
inv_param.cuda_prec_eigensolver = cuda_prec_precondition;
inv_param.chrono_precision = cuda_prec_sloppy;
inv_param.clover_rho = 0.0;
inv_param.clover_cpu_prec = cpu_prec;
inv_param.clover_cuda_prec = cuda_prec;
inv_param.clover_cuda_prec_sloppy = cuda_prec_sloppy;
inv_param.clover_cuda_prec_refinement_sloppy = cuda_prec_sloppy;
inv_param.clover_cuda_prec_precondition = cuda_prec_precondition;
inv_param.clover_cuda_prec_eigensolver = cuda_prec_precondition;
inv_param.return_clover = QUDA_BOOLEAN_FALSE;
inv_param.return_clover_inverse = QUDA_BOOLEAN_FALSE;
inv_param.preserve_source = QUDA_PRESERVE_SOURCE_YES;
inv_param.gamma_basis = QUDA_CHIRAL_GAMMA_BASIS; // CHIRAL -> UKQCD does not seem to be supported right now...
inv_param.dirac_order = QUDA_DIRAC_ORDER;
inv_param.clover_location = QUDA_CUDA_FIELD_LOCATION;
inv_param.input_location = QUDA_CPU_FIELD_LOCATION;
inv_param.output_location = QUDA_CPU_FIELD_LOCATION;
inv_param.tune = tune ? QUDA_TUNE_YES : QUDA_TUNE_NO;
// QUDA commit https://github.com/lattice/quda/commit/50864ffde1bd8f46fd4a2a2b2e6d44a5a588e2c2
// has removed these
// when running with a very recent QUDA version, TM_QUDA_EXPERIMENTAL should be set
// via --enable-quda_experimental so that these are not set
#ifndef TM_QUDA_EXPERIMENTAL
inv_param.sp_pad = 0; // 24*24*24/2;
inv_param.cl_pad = 0; // 24*24*24/2;
#endif
_setVerbosityQuda();
}
void _setVerbosityQuda(){
// solver verbosity and general verbosity
QudaVerbosity gen_verb = QUDA_SUMMARIZE;
if( g_debug_level == 0 ) {
inv_param.verbosity = QUDA_SILENT;
gen_verb = QUDA_SUMMARIZE;
}
else if( g_debug_level >= 1 && g_debug_level < 3 ) {
inv_param.verbosity = QUDA_SUMMARIZE;
}
else if( g_debug_level >= 3 && g_debug_level < 5 ) {
inv_param.verbosity = QUDA_VERBOSE;
gen_verb = QUDA_VERBOSE;
}
else if( g_debug_level >= 5 ) {
inv_param.verbosity = QUDA_DEBUG_VERBOSE;
gen_verb = QUDA_DEBUG_VERBOSE;
}
// general verbosity
setVerbosityQuda(gen_verb, "# QUDA: ", stdout);
}
void set_force_gauge_param( QudaGaugeParam * f_gauge_param){
set_default_gauge_param(f_gauge_param);
f_gauge_param->t_boundary = QUDA_PERIODIC_T;
f_gauge_param->ga_pad = 0;
f_gauge_param->use_resident_gauge = QUDA_BOOLEAN_NO;
f_gauge_param->make_resident_gauge = QUDA_BOOLEAN_NO;
f_gauge_param->use_resident_mom = QUDA_BOOLEAN_NO;
f_gauge_param->make_resident_mom = QUDA_BOOLEAN_NO;
f_gauge_param->return_result_mom = QUDA_BOOLEAN_YES;
f_gauge_param->overwrite_mom = QUDA_BOOLEAN_YES;
}
void _initQuda() {
if( quda_initialized )
return;
if( g_debug_level > 0 )
if(g_proc_id == 0)
printf("\n# TM_QUDA: Detected QUDA version %d.%d.%d\n\n", QUDA_VERSION_MAJOR, QUDA_VERSION_MINOR, QUDA_VERSION_SUBMINOR);
if( QUDA_VERSION_MAJOR == 0 && QUDA_VERSION_MINOR < 7) {
fprintf(stderr, "Error: minimum QUDA version required is 0.7.0 (for support of chiral basis and removal of bug in mass normalization with preconditioning).\n");
exit(-2);
}
if( quda_input.enable_device_memory_pool ){
setenv("QUDA_ENABLE_DEVICE_MEMORY_POOL", "1", 1);
tm_debug_printf(0, 0, "# TM_QUDA: Setting environment variable QUDA_ENABLE_DEVICE_MEMORY_POOL=1\n");
} else {
setenv("QUDA_ENABLE_DEVICE_MEMORY_POOL", "0", 1);
tm_debug_printf(0, 0, "# TM_QUDA: Setting environment variable QUDA_ENABLE_DEVICE_MEMORY_POOL=0\n");
}
if( quda_input.enable_pinned_memory_pool ){
setenv("QUDA_ENABLE_PINNED_MEMORY_POOL", "1", 1);
tm_debug_printf(0, 0, "# TM_QUDA: Setting environment variable QUDA_ENABLE_PINNED_MEMORY_POOL=1\n");
} else {
setenv("QUDA_ENABLE_PINNED_MEMORY_POOL", "0", 1);
tm_debug_printf(0, 0, "# TM_QUDA: Setting environment variable QUDA_ENABLE_PINNED_MEMORY_POOL=0\n");
}
gauge_param = newQudaGaugeParam();
f_gauge_param = newQudaGaugeParam();
inv_param = newQudaInvertParam();
mg_inv_param = newQudaInvertParam();
quda_mg_param = newQudaMultigridParam();
for( int level = 0; level < QUDA_MAX_MG_LEVEL; ++level ){
mg_eig_param[level] = newQudaEigParam();
}
_setDefaultQudaParam();
// declare the grid mapping used for communications in a multi-GPU grid
#if USE_LZ_LY_LX_T
int grid[4] = {g_nproc_z, g_nproc_y, g_nproc_x, g_nproc_t};
#else
int grid[4] = {g_nproc_x, g_nproc_y, g_nproc_z, g_nproc_t};
#endif
initCommsGridQuda(4, grid, commsMap, NULL);
// alloc gauge_quda
size_t gSize = (gauge_param.cpu_prec == QUDA_DOUBLE_PRECISION) ? sizeof(double) : sizeof(float);
for (int dir = 0; dir < 4; dir++) {
gauge_quda[dir] = (double*) malloc(VOLUME*18*gSize);
if(gauge_quda[dir] == NULL) {
fprintf(stderr, "_initQuda: malloc for gauge_quda[dir] failed");
exit(-2);
}
}
// alloc space for a temp. spinor, used throughout this module
tempSpinor = (double*)malloc( 2*VOLUME*24*sizeof(double) ); /* factor 2 for doublet */
if(tempSpinor == NULL) {
fprintf(stderr, "_initQuda: malloc for tempSpinor failed");
exit(-2);
}
// initialize the QUDA library
#ifdef TM_USE_MPI
initQuda(-1); //sets device numbers automatically
#else
// when running in 'subprocess' mode, the external program should have provided us with a unique
// id in the range 0 to (N-1), where N is the number of NVIDIA devices available (see wrapper/lib_wrapper.c)
if(subprocess_flag){
initQuda(g_external_id);
}else{
initQuda(0); //scalar build without subprocess: use device 0
}
#endif
quda_initialized = 1;
}
// finalize the QUDA library
void _endQuda() {
if( quda_initialized ) {
if( quda_mg_preconditioner != NULL ){
destroyMultigridQuda(quda_mg_preconditioner);
quda_mg_preconditioner = NULL;
}
for(int dir = 0; dir < 4; dir++){
if( (void*)gauge_quda[dir] != NULL ) free((void*)gauge_quda[dir]);
if( (void*)mom_quda[dir] != NULL ) free((void*)mom_quda[dir]);
if( (void*)mom_quda_reordered[dir] != NULL ) free((void*)mom_quda_reordered[dir]);
}
freeGaugeQuda();
freeCloverQuda(); // this is safe even if there is no Clover field loaded, at least it was in QUDA v0.7.2
free((void*)tempSpinor);
endQuda();
}
}
void _loadCloverQuda(QudaInvertParam* inv_param){
static int first_call = 1;
// check if loaded clover and gauge fields agree
if( check_quda_clover_state(&quda_clover_state, &quda_gauge_state, inv_param) ){
tm_debug_printf(0, 0, "# TM_QUDA: Clover field and inverse already loaded for gauge_id: %f\n", quda_gauge_state.gauge_id);
} else {
tm_stopwatch_push(&g_timers, "loadCloverQuda", "");
if(first_call){
first_call = 1;
} else {
freeCloverQuda();
}
reset_quda_clover_state(&quda_clover_state);
loadCloverQuda(NULL, NULL, inv_param);
set_quda_clover_state(&quda_clover_state, &quda_gauge_state, inv_param);
tm_stopwatch_pop(&g_timers, 0, 0, "TM_QUDA");
}
}
void reorder_gauge_toQuda( const su3 ** const gaugefield, const CompressionType compression ) {
tm_stopwatch_push(&g_timers, __func__, "");
#ifdef TM_USE_OMP
#pragma omp parallel
{
#endif
_Complex double tmpcplx;
size_t gSize = (gauge_param.cpu_prec == QUDA_DOUBLE_PRECISION) ? sizeof(double) : sizeof(float);
// now copy and reorder
#ifdef TM_USE_OMP
#pragma omp for collapse(4)
#endif
for( int x0=0; x0<T; x0++ )
for( int x1=0; x1<LX; x1++ )
for( int x2=0; x2<LY; x2++ )
for( int x3=0; x3<LZ; x3++ ) {
#if USE_LZ_LY_LX_T
int j = x3 + LZ*x2 + LY*LZ*x1 + LX*LY*LZ*x0;
int tm_idx = x1 + LX*x2 + LY*LX*x3 + LZ*LY*LX*x0;
#else
int j = x1 + LX*x2 + LY*LX*x3 + LZ*LY*LX*x0;
int tm_idx = x3 + LZ*x2 + LY*LZ*x1 + LX*LY*LZ*x0;
#endif
int oddBit = (x0+x1+x2+x3) & 1;
int quda_idx = 18*(oddBit*VOLUME/2+j/2);
#if USE_LZ_LY_LX_T
memcpy( &(gauge_quda[0][quda_idx]), &(gaugefield[tm_idx][3]), 18*gSize);
memcpy( &(gauge_quda[1][quda_idx]), &(gaugefield[tm_idx][2]), 18*gSize);
memcpy( &(gauge_quda[2][quda_idx]), &(gaugefield[tm_idx][1]), 18*gSize);
memcpy( &(gauge_quda[3][quda_idx]), &(gaugefield[tm_idx][0]), 18*gSize);
#else
memcpy( &(gauge_quda[0][quda_idx]), &(gaugefield[tm_idx][1]), 18*gSize);
memcpy( &(gauge_quda[1][quda_idx]), &(gaugefield[tm_idx][2]), 18*gSize);
memcpy( &(gauge_quda[2][quda_idx]), &(gaugefield[tm_idx][3]), 18*gSize);
memcpy( &(gauge_quda[3][quda_idx]), &(gaugefield[tm_idx][0]), 18*gSize);
#endif
if( compression == NO_COMPRESSION && quda_input.fermionbc == TM_QUDA_THETABC ) {
// apply theta boundary conditions if compression is not used
for( int i=0; i<9; i++ ) {
tmpcplx = gauge_quda[0][quda_idx+2*i] + I*gauge_quda[0][quda_idx+2*i+1];
tmpcplx *= -phase_1/g_kappa;
gauge_quda[0][quda_idx+2*i] = creal(tmpcplx);
gauge_quda[0][quda_idx+2*i+1] = cimag(tmpcplx);
tmpcplx = gauge_quda[1][quda_idx+2*i] + I*gauge_quda[1][quda_idx+2*i+1];
tmpcplx *= -phase_2/g_kappa;
gauge_quda[1][quda_idx+2*i] = creal(tmpcplx);
gauge_quda[1][quda_idx+2*i+1] = cimag(tmpcplx);
tmpcplx = gauge_quda[2][quda_idx+2*i] + I*gauge_quda[2][quda_idx+2*i+1];
tmpcplx *= -phase_3/g_kappa;
gauge_quda[2][quda_idx+2*i] = creal(tmpcplx);
gauge_quda[2][quda_idx+2*i+1] = cimag(tmpcplx);
tmpcplx = gauge_quda[3][quda_idx+2*i] + I*gauge_quda[3][quda_idx+2*i+1];
tmpcplx *= -phase_0/g_kappa;
gauge_quda[3][quda_idx+2*i] = creal(tmpcplx);
gauge_quda[3][quda_idx+2*i+1] = cimag(tmpcplx);
}
// when compression is not used, we can still force naive anti-periodic boundary conditions
} else {
if ( quda_input.fermionbc == TM_QUDA_APBC && x0+g_proc_coords[0]*T == g_nproc_t*T-1 ) {
for( int i=0; i<18; i++ ) {
gauge_quda[3][quda_idx+i] = -gauge_quda[3][quda_idx+i];
}
} // quda_input.fermionbc
} // if(compression & boundary conditions)
} // volume loop
#ifdef TM_USE_OMP
} // OpenMP parallel closing brace
#endif
tm_stopwatch_pop(&g_timers, 0, 0, "TM_QUDA");
}
void _loadGaugeQuda( const CompressionType compression ) {
static int first_call = 1;
// check if the currently loaded gauge field is also the current gauge field
// and if so, return immediately
tm_debug_printf(0, 1, "# TM_QUDA: Called _loadGaugeQuda for gauge_id: %f\n", g_gauge_state.gauge_id);
if( inv_param.verbosity > QUDA_SILENT ){
if(g_proc_id == 0) {
if( compression == NO_COMPRESSION ){
if( quda_input.fermionbc == TM_QUDA_THETABC ){
printf("# TM_QUDA: Theta boundary conditions will be applied to gauge field\n");
}
} else {
if( quda_input.fermionbc == TM_QUDA_APBC ){
printf("# TM_QUDA: Temporal ABPC will be applied to gauge field\n");
}
}
}
}
if( check_quda_gauge_state(&quda_gauge_state, g_gauge_state.gauge_id, X1, X2, X3, X0, &gauge_param) ){
return;
} else {
if( first_call ){
first_call = 0;
} else {
freeGaugeQuda();
}
reset_quda_gauge_state(&quda_gauge_state);
}
reorder_gauge_toQuda(g_gauge_field, compression);
tm_stopwatch_push(&g_timers, "loadGaugeQuda", "");
loadGaugeQuda((void*)gauge_quda, &gauge_param);
tm_stopwatch_pop(&g_timers, 0, 0, "TM_QUDA");
set_quda_gauge_state(&quda_gauge_state, g_gauge_state.gauge_id, X1, X2, X3, X0, &gauge_param);
}
// reorder spinor to QUDA format
void reorder_spinor_toQuda( double* sp, QudaPrecision precision, int doublet ) {
tm_stopwatch_push(&g_timers, __func__, "");
memcpy( tempSpinor, sp, (1+doublet)*VOLUME*24*sizeof(double) );
// now copy and reorder from tempSpinor to spinor
#ifdef TM_USE_OMP
#pragma omp parallel for collapse(4)
#endif
for( int x0=0; x0<T; x0++ )
for( int x1=0; x1<LX; x1++ )
for( int x2=0; x2<LY; x2++ )
for( int x3=0; x3<LZ; x3++ ) {
#if USE_LZ_LY_LX_T
int j = x3 + LZ*x2 + LY*LZ*x1 + LX*LY*LZ*x0;
int tm_idx = x1 + LX*x2 + LY*LX*x3 + LZ*LY*LX*x0;
#else
int j = x1 + LX*x2 + LY*LX*x3 + LZ*LY*LX*x0;
int tm_idx = x3 + LZ*x2 + LY*LZ*x1 + LX*LY*LZ*x0;
#endif
int oddBit = (x0+x1+x2+x3) & 1;
if( doublet ) {
memcpy( &(sp[24*(oddBit*VOLUME+j/2)]), &(tempSpinor[24*tm_idx ]), 24*sizeof(double));
memcpy( &(sp[24*(oddBit*VOLUME+j/2+VOLUME/2)]), &(tempSpinor[24*(tm_idx+VOLUME)]), 24*sizeof(double));
}
else {
memcpy( &(sp[24*(oddBit*VOLUME/2+j/2)]), &(tempSpinor[24*tm_idx]), 24*sizeof(double));
}
}
tm_stopwatch_pop(&g_timers, 0, 0, "TM_QUDA");
}
void _initMomQuda(void) {
static int first_call = 1;
if( first_call ){
first_call = 0;
set_force_gauge_param(&f_gauge_param);
for(int i = 0; i < 4; i++){
mom_quda[i] = (double*)malloc(VOLUME*10*sizeof(double));
mom_quda_reordered[i] = (double*)malloc(VOLUME*10*sizeof(double));
if( (void*)mom_quda[i] == NULL || (void*)mom_quda_reordered[i] == NULL ){
fatal_error("Memory allocation for host momentum field failed!", __func__);
}
}
}
}
void reorder_mom_fromQuda() {
// mom_quda -> mom_quda_reordered
tm_stopwatch_push(&g_timers, __func__, "");
#ifdef TM_USE_OMP
#pragma omp parallel for collapse(4)
#endif
for( int x0=0; x0<T; x0++ )
for( int x1=0; x1<LX; x1++ )
for( int x2=0; x2<LY; x2++ )
for( int x3=0; x3<LZ; x3++ ) {
#if USE_LZ_LY_LX_T
int j = x3 + LZ*x2 + LY*LZ*x1 + LX*LY*LZ*x0;
int tm_idx = x1 + LX*x2 + LY*LX*x3 + LZ*LY*LX*x0;
#else
int j = x1 + LX*x2 + LY*LX*x3 + LZ*LY*LX*x0;
int tm_idx = x3 + LZ*x2 + LY*LZ*x1 + LX*LY*LZ*x0;
#endif
int oddBit = (x0+x1+x2+x3) & 1;
int quda_idx = 10*(oddBit*VOLUME/2+j/2);
tm_idx *= 10;
#if USE_LZ_LY_LX_T
memcpy( &(mom_quda_reordered[3][tm_idx]), &(mom_quda[0][quda_idx]), 10*sizeof(double));
memcpy( &(mom_quda_reordered[2][tm_idx]), &(mom_quda[1][quda_idx]), 10*sizeof(double));
memcpy( &(mom_quda_reordered[1][tm_idx]), &(mom_quda[2][quda_idx]), 10*sizeof(double));
memcpy( &(mom_quda_reordered[0][tm_idx]), &(mom_quda[3][quda_idx]), 10*sizeof(double));
#else
memcpy( &(mom_quda_reordered[1][tm_idx]), &(mom_quda[0][quda_idx]), 10*sizeof(double));
memcpy( &(mom_quda_reordered[2][tm_idx]), &(mom_quda[1][quda_idx]), 10*sizeof(double));
memcpy( &(mom_quda_reordered[3][tm_idx]), &(mom_quda[2][quda_idx]), 10*sizeof(double));
memcpy( &(mom_quda_reordered[0][tm_idx]), &(mom_quda[3][quda_idx]), 10*sizeof(double));
#endif
}
tm_stopwatch_pop(&g_timers, 0, 0, "TM_QUDA");
}
// reorder spinor from QUDA format
void reorder_spinor_fromQuda( double* sp, QudaPrecision precision, int doublet) {
tm_stopwatch_push(&g_timers, __func__, "");
memcpy( tempSpinor, sp, (1+doublet)*VOLUME*24*sizeof(double) );
// now copy and reorder from tempSpinor to spinor
#ifdef TM_USE_OMP
#pragma omp parallel for collapse(4)
#endif
for( int x0=0; x0<T; x0++ )
for( int x1=0; x1<LX; x1++ )
for( int x2=0; x2<LY; x2++ )
for( int x3=0; x3<LZ; x3++ ) {
#if USE_LZ_LY_LX_T
int j = x3 + LZ*x2 + LY*LZ*x1 + LX*LY*LZ*x0;
int tm_idx = x1 + LX*x2 + LY*LX*x3 + LZ*LY*LX*x0;
#else
int j = x1 + LX*x2 + LY*LX*x3 + LZ*LY*LX*x0;
int tm_idx = x3 + LZ*x2 + LY*LZ*x1 + LX*LY*LZ*x0;
#endif
int oddBit = (x0+x1+x2+x3) & 1;
if( doublet ) {
memcpy( &(sp[24*tm_idx]), &(tempSpinor[24*(oddBit*VOLUME+j/2) ]), 24*sizeof(double));
memcpy( &(sp[24*(tm_idx+VOLUME)]), &(tempSpinor[24*(oddBit*VOLUME+j/2+VOLUME/2)]), 24*sizeof(double));
}
else {
memcpy( &(sp[24*tm_idx]), &(tempSpinor[24*(oddBit*VOLUME/2+j/2)]), 24*sizeof(double));
}
}
tm_stopwatch_pop(&g_timers, 0, 0, "TM_QUDA");
}
// reorder spinor to QUDA format
void reorder_spinor_eo_toQuda(double* sp, QudaPrecision precision, int doublet, int odd) {
tm_stopwatch_push(&g_timers, __func__, "");
static const int change_sign[4] = {-1, 1, 1, -1};
static const int change_spin[4] = {3, 2, 1, 0};
const int Vh = VOLUME/2;
memcpy(tempSpinor, sp, (1+doublet)*Vh*24*sizeof(double) );
// now copy and reorder from tempSpinor to spinor
#ifdef TM_USE_OMP
#pragma omp parallel for collapse(4)
#endif
for( int x0=0; x0<T; x0++ )
for( int x1=0; x1<LX; x1++ )
for( int x2=0; x2<LY; x2++ )
for( int x3=0; x3<LZ; x3++ ) {
#if USE_LZ_LY_LX_T
const int q_eo_idx = (x3 + LZ*x2 + LY*LZ*x1 + LX*LY*LZ*x0)/2;
const int tm_eo_idx = (x1 + LX*x2 + LY*LX*x3 + LZ*LY*LX*x0)/2;
#else
const int q_eo_idx = (x1 + LX*x2 + LY*LX*x3 + LZ*LY*LX*x0)/2;
const int tm_eo_idx = (x3 + LZ*x2 + LY*LZ*x1 + LX*LY*LZ*x0)/2;
#endif
const int oddBit = (x0+x1+x2+x3) & 1;
if( oddBit == odd ){
for(int q_spin = 0; q_spin < 4; q_spin++){
const int tm_spin = change_spin[q_spin];
for(int col = 0; col < 3; col++){
for(int reim = 0; reim < 2; reim++){
sp[24*q_eo_idx + 6*q_spin + 2*col + reim] =
change_sign[q_spin] * tempSpinor[24*tm_eo_idx + 6*tm_spin + 2*col + reim];
if(doublet){
sp[24*(q_eo_idx+Vh) + 6*q_spin + 2*col + reim] =
change_sign[q_spin] * tempSpinor[24*(tm_eo_idx+Vh) + 6*tm_spin + 2*col + reim];
}
}
}
}
}
}
tm_stopwatch_pop(&g_timers, 0, 0, "TM_QUDA");
}
// reorder spinor from QUDA format
void reorder_spinor_eo_fromQuda( double* sp, QudaPrecision precision, int doublet, int odd) {
tm_stopwatch_push(&g_timers, __func__, "");
const int change_sign[4] = {-1, 1, 1, -1};
const int change_spin[4] = {3, 2, 1, 0};
const int Vh = VOLUME/2;
memcpy( tempSpinor, sp, (1+doublet)*(VOLUME/2)*24*sizeof(double) );
// now copy and reorder from tempSpinor to spinor
#ifdef TM_USE_OMP
#pragma omp parallel for collapse(4)
#endif
for( int x0=0; x0<T; x0++ )
for( int x1=0; x1<LX; x1++ )
for( int x2=0; x2<LY; x2++ )
for( int x3=0; x3<LZ; x3++ ) {
#if USE_LZ_LY_LX_T
const int q_eo_idx = (x3 + LZ*x2 + LY*LZ*x1 + LX*LY*LZ*x0)/2;
const int tm_eo_idx = (x1 + LX*x2 + LY*LX*x3 + LZ*LY*LX*x0)/2;
#else
const int q_eo_idx = (x1 + LX*x2 + LY*LX*x3 + LZ*LY*LX*x0)/2;
const int tm_eo_idx = (x3 + LZ*x2 + LY*LZ*x1 + LX*LY*LZ*x0)/2;
#endif
const int oddBit = (x0+x1+x2+x3) & 1;
if( oddBit == odd ){
for(int q_spin = 0; q_spin < 4; q_spin++){
const int tm_spin = change_spin[q_spin];
for(int col = 0; col < 3; col++){
for(int reim = 0; reim < 2; reim++){
sp[24*tm_eo_idx + 6*tm_spin + 2*col + reim] =
change_sign[q_spin] * tempSpinor[24*q_eo_idx + 6*q_spin + 2*col + reim];
if(doublet){
sp[24*(tm_eo_idx+Vh) + 6*tm_spin + 2*col + reim] =
change_sign[q_spin] * tempSpinor[24*(q_eo_idx+Vh) + 6*q_spin + 2*col + reim];
}
}
}
}
}
}
tm_stopwatch_pop(&g_timers, 0, 0, "TM_QUDA");
}
void set_boundary_conditions(CompressionType* compression, QudaGaugeParam * gauge_param) {
// we can't have compression and theta-BC, but we will support compression
// for theta_0 = 0.0 or theta_0 = 1.0 (using naive periodic or anti-periodic boundary conditions
// warning the user that the residual check will fail)
if( fabs(X1)>0.0 || fabs(X2)>0.0 || fabs(X3)>0.0 || (fabs(X0) > 2*DBL_EPSILON && fabs(fabs(X0)-1.0) > 2*DBL_EPSILON ) ) {
if( *compression!=NO_COMPRESSION ) {
if(g_proc_id == 0) {
printf("\n# TM_QUDA: WARNING you can't use compression %d with boundary conditions for fermion fields (t,x,y,z)*pi: (%f,%f,%f,%f) \n", *compression,X0,X1,X2,X3);
printf("# TM_QUDA: disabling compression.\n\n");
}
*compression=NO_COMPRESSION;
}
}
QudaReconstructType link_recon = QUDA_RECONSTRUCT_NO;
QudaReconstructType link_recon_sloppy = QUDA_RECONSTRUCT_NO;
if( *compression==NO_COMPRESSION ) {
// without compression, any kind of boundary conditions are supported
// and will be applied to the gauge field as required
if( quda_input.fermionbc != TM_QUDA_APBC ){
gauge_param->t_boundary = QUDA_PERIODIC_T;
} else {
gauge_param->t_boundary = QUDA_ANTI_PERIODIC_T;
}
link_recon = QUDA_RECONSTRUCT_NO;
link_recon_sloppy = QUDA_RECONSTRUCT_NO;
} else {
// if we reach this point with compression (see logic above), theta_0 is either 0.0 or 1.0
// if it is 1.0, we explicitly enabled TM_QUDA_APBC to force simple anti-periodic boundary
// conditions
if( fabs(X0)>0.0 ){
quda_input.fermionbc = TM_QUDA_APBC;
tm_debug_printf(0, 0,
"# TM_QUDA: WARNING You have set temporal theta-BC but gauge compression is enabled. "
"This will be overriden to use naive APBC instead. This works fine, but the residual "
"check on the host (CPU) will fail.\n");
}
if( quda_input.fermionbc == TM_QUDA_APBC ) {
gauge_param->t_boundary = QUDA_ANTI_PERIODIC_T;
} else {
gauge_param->t_boundary = QUDA_PERIODIC_T;
}
link_recon = QUDA_RECONSTRUCT_12;
link_recon_sloppy = QUDA_RECONSTRUCT_12;
tm_debug_printf(0, 0,
"\n# TM_QUDA: WARNING using %d compression with trivial (A)PBC instead "
"of theta-BC ((t,x,y,z)*pi: (%f,%f,%f,%f))! This works fine but the residual "
"check on the host (CPU) will fail.\n",
*compression,X0,X1,X2,X3);
}
gauge_param->reconstruct = link_recon;
gauge_param->reconstruct_sloppy = link_recon_sloppy;
gauge_param->reconstruct_refinement_sloppy = link_recon_sloppy;
gauge_param->reconstruct_precondition = link_recon_sloppy;
gauge_param->reconstruct_eigensolver = link_recon;
}
void set_sloppy_prec(const SloppyPrecision sloppy_precision, const SloppyPrecision refinement_precision, QudaGaugeParam * gauge_param, QudaInvertParam * inv_param) {
// choose sloppy prec.
QudaPrecision cuda_prec_sloppy;
QudaPrecision cuda_prec_refinement_sloppy;
if( sloppy_precision==SLOPPY_DOUBLE ) {
inv_param->reliable_delta = 1e-4;
cuda_prec_sloppy = QUDA_DOUBLE_PRECISION;
if(g_proc_id == 0) printf("# TM_QUDA: Using double prec. as sloppy!\n");
}
else if( sloppy_precision==SLOPPY_HALF ) {
// in double-half, we perform many reliable updates
inv_param->reliable_delta = 1e-1;
cuda_prec_sloppy = QUDA_HALF_PRECISION;
if(g_proc_id == 0) printf("# TM_QUDA: Using half prec. as sloppy!\n");
}
else {
inv_param->reliable_delta = 1e-2;
cuda_prec_sloppy = QUDA_SINGLE_PRECISION;
if(g_proc_id == 0) printf("# TM_QUDA: Using single prec. as sloppy!\n");
}
if( refinement_precision == SLOPPY_DOUBLE ){
inv_param->reliable_delta_refinement = 1e-4;
cuda_prec_refinement_sloppy = QUDA_DOUBLE_PRECISION;
}
else if( refinement_precision == SLOPPY_HALF ){
inv_param->reliable_delta_refinement = 1e-1;
cuda_prec_refinement_sloppy = QUDA_HALF_PRECISION;
if(g_proc_id == 0) printf("# TM_QUDA: Using double-half refinement in mshift-solver!\n");
}
else {
inv_param->reliable_delta_refinement = 1e-2;
cuda_prec_refinement_sloppy = QUDA_SINGLE_PRECISION;
if(g_proc_id == 0) printf("# TM_QUDA: Using double-single refinement in mshift-solver!\n");
}
gauge_param->cuda_prec_sloppy = cuda_prec_sloppy;
inv_param->cuda_prec_sloppy = cuda_prec_sloppy;
inv_param->clover_cuda_prec_sloppy = cuda_prec_sloppy;
inv_param->cuda_prec_refinement_sloppy = cuda_prec_refinement_sloppy;
gauge_param->cuda_prec_refinement_sloppy = cuda_prec_refinement_sloppy;
inv_param->clover_cuda_prec_refinement_sloppy = cuda_prec_refinement_sloppy;
}
int invert_quda_direct(double * const propagator, double const * const source,
const int op_id) {
tm_stopwatch_push(&g_timers, __func__, "");
spinor ** solver_field = NULL;
init_solver_field(&solver_field, VOLUME, 1);
memcpy((void*)(solver_field[0]), (void*)(source), VOLUME*sizeof(spinor));
double atime, atotaltime = gettime();
void *spinorIn = (void*)solver_field[0]; // source
void *spinorOut = (void*)propagator; // solution
operator * optr = &operator_list[op_id];
// g_kappa is necessary for the gauge field to be correctly translated from tmLQCD to QUDA
g_kappa = optr->kappa;
g_c_sw = optr->c_sw;
g_mu = optr->mu;
boundary(optr->kappa);
if ( g_relative_precision_flag )
inv_param.residual_type = QUDA_L2_RELATIVE_RESIDUAL;
else
inv_param.residual_type = QUDA_L2_ABSOLUTE_RESIDUAL;
inv_param.kappa = optr->kappa;
// figure out which BC to use (theta, trivial...)
set_boundary_conditions(&optr->compression_type, &gauge_param);
// set the sloppy precision of the mixed prec solver
set_sloppy_prec(optr->sloppy_precision, optr->solver_params.refinement_precision, &gauge_param, &inv_param);
// load gauge after setting precision, this is a no-op if the current gauge field
// is already loaded and the boundary conditions have not changed
atime = gettime();
_loadGaugeQuda(optr->compression_type);
if(g_proc_id==0 && g_debug_level > 0 ) printf("# TM_QUDA: Time for loadGaugeQuda: %.4e\n",gettime()-atime);
// this will also construct the clover field and its inverse, if required
// it will also run the MG setup
_setOneFlavourSolverParam(optr->kappa,
optr->c_sw,
optr->mu,
optr->solver,
optr->even_odd_flag,
optr->eps_sq,
optr->maxiter,