-
Notifications
You must be signed in to change notification settings - Fork 7
/
alm2allmaps_transpose_mpi.c
1240 lines (1041 loc) · 43.5 KB
/
alm2allmaps_transpose_mpi.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
/*
map synthesis HEALPix function w/ MPI - does MPI parallel alm -> map and all gradient maps up to second order
This is a complete rewrite in C of the HEALPix synthesis function. Parts of these routines were
taken from the public HEALPix package. See copyright and GPL info below.
-Matthew R. Becker, UofC 2011
*/
/*
!-----------------------------------------------------------------------------
!
! Copyright (C) 1997-2008 Krzysztof M. Gorski, Eric Hivon,
! Benjamin D. Wandelt, Anthony J. Banday,
! Matthias Bartelmann, Hans K. Eriksen,
! Frode K. Hansen, Martin Reinecke
!
!
! This file is part of HEALPix.
!
! HEALPix 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 2 of the License, or
! (at your option) any later version.
!
! HEALPix 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 HEALPix; if not, write to the Free Software
! Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
!
! For more information about HEALPix see http://healpix.jpl.nasa.gov
!
!-----------------------------------------------------------------------------
! Written by Hans Kristian Eriksen and Snorre Boasson,
! but copying large parts from the serial HEALPix code.
*/
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <assert.h>
#include <fftw3.h>
#include <mpi.h>
#include <assert.h>
#include "healpix_utils.h"
#include "healpix_shtrans.h"
void alm2allmaps_mpi(double *alm_real, double *alm_imag, float *mapvec, float *mapvec_gt, float *mapvec_gp,
float *mapvec_gtt, float *mapvec_gtp, float *mapvec_gpp,
HEALPixSHTPlan plan)
{
int NTasks,ThisTask;
int *sendcnts,*sdispls,*rdispls,*recvcnts;
double *transDataRealRecv,*transDataImagRecv;
long NrTDR,NmTDR;
long mapNum,Nmaps;
long nring,j,i,lmind,l,m,mp,k,lmin,ringpix_complex;
double sfact,skfact;
double rval,ival;
long nstartpix,ringpix,shifted;
double nsintheta,ncostheta;
long Nside,lmax;
long Nrings;
long firstRing,lastRing,lastLoopRing;
long NringsThisTask,NringsLoop;
const long NringChunkBase = 20;
long ringChunkStart,ringChunkStop,*ringpixRingChunk,*shiftedRingChunk,NringChunk;
double *nsinthetaRingChunk,*ncosthetaRingChunk;
double **qmn_real[6],**qmn_imag[6],**qms_real[6],**qms_imag[6];
long Nqm,firstChunkRing,lastChunkRing;
double *plm;
plmgen_data *plmdata;
double plmeps;
long firstl;
long firstM,lastM,NMThisTask;
double runTime;
#ifdef OUTPUT_SHT_LOADBALANCE
double mintm,maxtm,avgtm;
#endif
long memTot = 0;
double transTime,fftTime,sumTime,pixTime,plmTime;
fftwf_complex *mapvec_complex[6];
double *mTime;
long Nchunks,chunkInd;
long lmaxp1;
double gradquantn,gradquants,gradfact,*svec;
double gradplmn,gradplms,gradplm_lm1_n,gradplm_lm1_s;
double ncos_nsin,ncos_nsin2,ncos2_nsin2,fac1,fac2,fac3;
long task,start,NmT,nind,sind;
double *transDataReal;
double *transDataImag;
long NmTD,NrTD;
long mind;
//init timing and basic data for plan
runTime = -MPI_Wtime();
MPI_Comm_size(MPI_COMM_WORLD,&NTasks);
MPI_Comm_rank(MPI_COMM_WORLD,&ThisTask);
transTime = 0.0;
fftTime = 0.0;
sumTime = 0.0;
pixTime = 0.0;
plmTime = 0.0;
Nmaps = 6;
Nside = order2nside(plan.order);
Nrings = 2*Nside;
plmeps = 1e-30;
lmax = plan.lmax;
mapvec_complex[0] = (fftwf_complex*) mapvec;
mapvec_complex[1] = (fftwf_complex*) mapvec_gt;
mapvec_complex[2] = (fftwf_complex*) mapvec_gp;
mapvec_complex[3] = (fftwf_complex*) mapvec_gtt;
mapvec_complex[4] = (fftwf_complex*) mapvec_gtp;
mapvec_complex[5] = (fftwf_complex*) mapvec_gpp;
//get rings for this task
firstRing = plan.firstRingTasks[ThisTask];
lastRing = plan.lastRingTasks[ThisTask];
firstM = plan.firstMTasks[ThisTask];
lastM = plan.lastMTasks[ThisTask];
if(firstRing == -1 || lastRing == -1 || firstM == -1 || lastM == -1)
{
fprintf(stderr,"problem with assigning rings/ms to tasks! (Did you ask for more tasks than rings?)\n");
for(i=0;i<NTasks;++i)
fprintf(stderr,"\t%ld: firstRing,lastRing,Nrings = %ld|%ld,%ld, firstM,lastM,NM = %ld|%ld|%ld\n",i,
plan.firstRingTasks[i],plan.lastRingTasks[i],2*Nside,
plan.firstMTasks[i],plan.lastMTasks[i],plan.lmax+1);
MPI_Abort(MPI_COMM_WORLD,123);
}
#ifdef DEBUG_IO
if(ThisTask == 0)
for(i=0;i<NTasks;++i)
fprintf(stderr,"\t%ld: firstRing,lastRing,Nrings = %ld|%ld,%ld, firstM,lastM,NM = %ld|%ld|%ld\n",i,
plan.firstRingTasks[i],plan.lastRingTasks[i],2*Nside,
plan.firstMTasks[i],plan.lastMTasks[i],plan.lmax+1);
#endif
NMThisTask = lastM-firstM+1;
NringsThisTask = lastRing - firstRing + 1;
NringsLoop = NringsThisTask;
lastLoopRing = lastRing;
if(lastRing == Nrings)
{
--NringsLoop;
--lastLoopRing;
}
Nqm = NMThisTask;
//init plm generator
plm = (double*)malloc(sizeof(double)*(lmax + 1));
assert(plm != NULL);
memTot += sizeof(double)*(lmax + 1);
plmTime -= MPI_Wtime();
plmdata = plmgen_init(lmax,plmeps);
plmTime += MPI_Wtime();
//compute layout for transposed data
NmTD = NMThisTask;
NrTD = 4*Nside-1;
//memory buffers
transDataReal = (double*)malloc(sizeof(double)*NrTD*Nmaps*NmTD);
assert(transDataReal != NULL);
memTot += sizeof(double)*NrTD*Nmaps*NmTD;
transDataImag = (double*)malloc(sizeof(double)*NrTD*Nmaps*NmTD);
assert(transDataImag != NULL);
memTot += sizeof(double)*NrTD*Nmaps*NmTD;
for(i=0;i<NrTD;++i)
for(j=0;j<Nmaps;++j)
for(k=0;k<NmTD;++k)
{
transDataReal[(i*Nmaps + j)*NmTD + k] = 0.0;
transDataImag[(i*Nmaps + j)*NmTD + k] = 0.0;
}
ringpixRingChunk = (long*)malloc(sizeof(long)*NringChunkBase);
assert(ringpixRingChunk != NULL);
memTot += sizeof(long)*NringChunkBase;
shiftedRingChunk = (long*)malloc(sizeof(long)*NringChunkBase);
assert(shiftedRingChunk != NULL);
memTot += sizeof(long)*NringChunkBase;
nsinthetaRingChunk = (double*)malloc(sizeof(double)*NringChunkBase);
assert(nsinthetaRingChunk !=NULL);
memTot += sizeof(double)*NringChunkBase;
ncosthetaRingChunk = (double*)malloc(sizeof(double)*NringChunkBase);
assert(ncosthetaRingChunk !=NULL);
memTot += sizeof(double)*NringChunkBase;
for(j=0;j<6;++j)
{
qmn_real[j] = (double**)malloc(sizeof(double*)*NringChunkBase);
assert(qmn_real[j] != NULL);
memTot += sizeof(double*)*NringChunkBase;
qmn_imag[j] = (double**)malloc(sizeof(double*)*NringChunkBase);
assert(qmn_imag[j] != NULL);
memTot += sizeof(double*)*NringChunkBase;
qms_real[j] = (double**)malloc(sizeof(double*)*NringChunkBase);
assert(qms_real[j] != NULL);
memTot += sizeof(double*)*NringChunkBase;
qms_imag[j] = (double**)malloc(sizeof(double*)*NringChunkBase);
assert(qms_imag[j] != NULL);
memTot += sizeof(double*)*NringChunkBase;
for(i=0;i<NringChunkBase;++i)
{
qmn_real[j][i] = (double*)malloc(sizeof(double)*Nqm);
assert(qmn_real[j][i] != NULL);
memTot += sizeof(double)*Nqm;
qmn_imag[j][i] = (double*)malloc(sizeof(double)*Nqm);
assert(qmn_imag[j][i] != NULL);
memTot += sizeof(double)*Nqm;
qms_real[j][i] = (double*)malloc(sizeof(double)*Nqm);
assert(qms_real[j][i] != NULL);
memTot += sizeof(double)*Nqm;
qms_imag[j][i] = (double*)malloc(sizeof(double)*Nqm);
assert(qms_imag[j][i] != NULL);
memTot += sizeof(double)*Nqm;
}
}
lmaxp1 = lmax+1;
svec = (double*)malloc(sizeof(double)*(lmax + 1)*NMThisTask);
assert(svec != NULL);
memTot += sizeof(double)*(lmax + 1)*NMThisTask;
for(m=firstM;m<=lastM;++m)
for(l=m;l<=lmax;++l)
svec[l+lmaxp1*(m-firstM)] = sqrt((2.0*l+1.0)/(2.0*l-1.0)*((double) (l*l-m*m)));
//time each m value to get load balance correct
mTime = (double*)malloc(sizeof(double)*NMThisTask);
assert(mTime != NULL);
memTot += sizeof(double)*NMThisTask;
for(i=0;i<NMThisTask;++i)
mTime[i] = 0.0;
//setup chunks
firstChunkRing = 1;
lastChunkRing = 2*Nside-1;
Nchunks = (lastChunkRing-firstChunkRing+1)/NringChunkBase;
if(Nchunks*NringChunkBase < lastChunkRing-firstChunkRing+1)
++Nchunks;
sumTime -= MPI_Wtime();
#ifdef DEBUG
#if DEBUG_LEVEL > 0
fprintf(stderr,"%f MB allocated in alm2allmaps_mpi.\n",((double) (sizeof(double)*(memTot)))/1024.0/1024.0);
#endif
#endif
//do sums over plms - store rings in transData for MPI transpose
for(chunkInd=0;chunkInd<Nchunks;++chunkInd)
{
//get index range of subchunks
ringChunkStart = chunkInd*NringChunkBase + firstChunkRing;
ringChunkStop = ringChunkStart + NringChunkBase - 1;
if(ringChunkStop > lastChunkRing)
ringChunkStop = lastChunkRing;
NringChunk = ringChunkStop - ringChunkStart + 1;
//init parms for subchunks
for(i=0;i<NringChunk;++i)
{
nring = i + ringChunkStart;
get_ring_info2(nring,&nstartpix,ringpixRingChunk+i,ncosthetaRingChunk+i,nsinthetaRingChunk+i,shiftedRingChunk+i,plan.order);
for(mapNum=0;mapNum<6;++mapNum)
for(j=0;j<Nqm;++j)
{
qmn_real[mapNum][i][j] = 0.0;
qmn_imag[mapNum][i][j] = 0.0;
qms_real[mapNum][i][j] = 0.0;
qms_imag[mapNum][i][j] = 0.0;
}
}
//sum over l at fixed m for each ring using only alms on ThisTask
for(m=firstM;m<=lastM;++m)
{
mind = m-firstM;
mTime[mind] -= MPI_Wtime();
//sum over rings - lmind tracks alm coefficients for this m
lmind = (lmax+1)*(m-firstM) + ((firstM-2)*(firstM+1))/2 - ((m-2)*(m+1))/2;
for(i=0;i<NringChunk;++i)
{
//do not sum over Ylm which are too small
lmin = get_lmin_ylm(m,(float) (nsinthetaRingChunk[i]));
if(lmin <= lmax)
{
plmTime -= MPI_Wtime();
plmgen(ncosthetaRingChunk[i],nsinthetaRingChunk[i],m,plm,&firstl,plmdata);
plmTime += MPI_Wtime();
//now do sum over l
if(firstl <= lmax)
{
//alm -> map - mapNum = 0
sfact = 1.0 - (((firstl+m)%2) << 1);
for(l=firstl;l<=lmax;++l)
{
//this is always true assert((((l+m)%2 == 0 && sfact == 1.0)) || (((l+m)%2 == 1 && sfact == -1.0)));
//pure synthesis of map
rval = alm_real[lmind + l-m]*plm[l];
ival = alm_imag[lmind + l-m]*plm[l];
qmn_real[0][i][mind] += rval;
qmn_imag[0][i][mind] += ival;
qms_real[0][i][mind] += sfact*rval;
qms_imag[0][i][mind] += sfact*ival;
//gradient w.r.t. phi is i*m/sin(\theta)P_{lm}\exp(i*m*\phi)*a_{lm} \hat{\phi}
rval *= m;
ival *= m;
qmn_real[2][i][mind] -= ival;//+= -1.0*alm_imag[lmind + l-m]*plm[l]*((double) m);
qmn_imag[2][i][mind] += rval;//alm_real[lmind + l-m]*plm[l]*((double) m);
qms_real[2][i][mind] -= sfact*ival;//+= sfact*(-1.0)*alm_imag[lmind + l-m]*plm[l]*((double) m);
qms_imag[2][i][mind] += sfact*rval;//sfact*alm_real[lmind + l-m]*plm[l]*((double) m);
//del2phi_div_sin2theta is -m^2/sin^{2}(\theta)P_{lm}\exp(i*m*\phi)*a_{lm}
rval *= m;
ival *= m;
qmn_real[5][i][mind] -= rval;//+= -1.0*alm_real[lmind + l-m]*plm[l]*((double) (m*m));
qmn_imag[5][i][mind] -= ival;//+= -1.0*alm_imag[lmind + l-m]*plm[l]*((double) (m*m));
qms_real[5][i][mind] -= sfact*rval;//+= sfact*(-1.0)*alm_real[lmind + l-m]*plm[l]*((double) (m*m));
qms_imag[5][i][mind] -= sfact*ival;//+= sfact*(-1.0)*alm_imag[lmind + l-m]*plm[l]*((double) (m*m));
sfact = -sfact;
}
//grad theta, grad2 theta, and gradthetgradphi transforms
sfact = 1.0 - 2.0*((firstl+m)%2);
ncos_nsin = ncosthetaRingChunk[i]/nsinthetaRingChunk[i];
ncos_nsin2 = ncosthetaRingChunk[i]/nsinthetaRingChunk[i]/nsinthetaRingChunk[i];
ncos2_nsin2 = ncos_nsin*ncos_nsin;
//this is the first iteration of the loop
//it is broken out here to avoid branching in the loop
l = firstl;
if(l > 0)
{
//grad theta
gradplmn = ((double) l)*ncos_nsin*plm[l];
gradplms = -sfact*gradplmn; //-1 for cos(pi-nsintheta)
qmn_real[1][i][mind] += alm_real[lmind + l-m]*gradplmn;
qmn_imag[1][i][mind] += alm_imag[lmind + l-m]*gradplmn;
qms_real[1][i][mind] += alm_real[lmind + l-m]*gradplms;
qms_imag[1][i][mind] += alm_imag[lmind + l-m]*gradplms;
//we need grad^2\theta which is l*cos\theta/sin\theta\gradplm[l] - l*plm[l]
// - l*cos^{2}\theta/sin^{2}\theta*plm[l]
// + (l+m)*sqrt((2*l+1)/(2*l-1)*(l-m)/(l+m))*plm[l-1]*cos\theta/sin^{2}\theta
// - (l+m)*sqrt((2*l+1)/(2*l-1)*(l-m)/(l+m))*\gradplm[l-1]/sin\theta
fac1 = ((double) l)*ncos_nsin;
fac2 = ((double) l)*plm[l]*(1.0 + ncos2_nsin2);
gradquantn = fac1*gradplmn - fac2;
gradquants = -fac1*gradplms - sfact*fac2;
qmn_real[3][i][mind] += alm_real[lmind + l-m]*gradquantn;
qmn_imag[3][i][mind] += alm_imag[lmind + l-m]*gradquantn;
qms_real[3][i][mind] += alm_real[lmind + l-m]*gradquants;
qms_imag[3][i][mind] += alm_imag[lmind + l-m]*gradquants;
gradplm_lm1_n = gradplmn;
gradplm_lm1_s = gradplms;
//grad theta grad phi gives factor of i*m/sintheta
gradplmn *= m;
gradplms *= m;
qmn_real[4][i][mind] -= alm_imag[lmind + l-m]*gradplmn;
qmn_imag[4][i][mind] += alm_real[lmind + l-m]*gradplmn;
qms_real[4][i][mind] -= alm_imag[lmind + l-m]*gradplms; //sfact is over all sign of plm(pi-ncostheta) at l
qms_imag[4][i][mind] += alm_real[lmind + l-m]*gradplms;
}
else
{
gradplm_lm1_n = 0.0;
gradplm_lm1_s = 0.0;
}
sfact = -sfact;
++firstl;
for(l=firstl;l<=lmax;++l)
{
//gradient w.r.t. theta is l*cos\theta/sin\theta*plm[l] - (l+m)*sqrt((2*l+1)/(2*l-1)*(l-m)/(l+m))*plm[l-1] \hat{\theta}
gradplmn = ((double) l)*ncos_nsin*plm[l]
- svec[l+lmaxp1*(m-firstM)]*plm[l-1]/nsinthetaRingChunk[i];
gradplms = -sfact*gradplmn; //-1 for cos(pi-nsintheta) and also -1 because plm of l-1 differs by -1 from plm of l for pi-theta
qmn_real[1][i][mind] += alm_real[lmind + l-m]*gradplmn;
qmn_imag[1][i][mind] += alm_imag[lmind + l-m]*gradplmn;
qms_real[1][i][mind] += alm_real[lmind + l-m]*gradplms;
qms_imag[1][i][mind] += alm_imag[lmind + l-m]*gradplms;
//we need grad^2\theta which is l*cos\theta/sin\theta\gradplm[l] - l*plm[l]
// - l*cos^{2}\theta/sin^{2}\theta*plm[l]
// + (l+m)*sqrt((2*l+1)/(2*l-1)*(l-m)/(l+m))*plm[l-1]*cos\theta/sin^{2}\theta
// - (l+m)*sqrt((2*l+1)/(2*l-1)*(l-m)/(l+m))*\gradplm[l-1]/sin\theta
fac1 = ((double) l)*ncos_nsin;
fac2 = ((double) l)*plm[l]*(1.0 + ncos2_nsin2);
fac3 = svec[l+lmaxp1*(m-firstM)]/nsinthetaRingChunk[i];
gradquantn = fac1*gradplmn - fac2 - fac3*gradplm_lm1_n;
gradquants = -fac1*gradplms - sfact*fac2 - fac3*gradplm_lm1_s;
gradfact = svec[l+lmaxp1*(m-firstM)]*plm[l-1]*ncos_nsin2;
gradquantn += gradfact;
gradquants += gradfact*sfact;
qmn_real[3][i][mind] += alm_real[lmind + l-m]*gradquantn;
qmn_imag[3][i][mind] += alm_imag[lmind + l-m]*gradquantn;
qms_real[3][i][mind] += alm_real[lmind + l-m]*gradquants;
qms_imag[3][i][mind] += alm_imag[lmind + l-m]*gradquants;
gradplm_lm1_n = gradplmn;
gradplm_lm1_s = gradplms;
//grad theta grad phi gives factor of i*m/sintheta
gradplmn *= m;
gradplms *= m;
qmn_real[4][i][mind] -= alm_imag[lmind + l-m]*gradplmn;
qmn_imag[4][i][mind] += alm_real[lmind + l-m]*gradplmn;
qms_real[4][i][mind] -= alm_imag[lmind + l-m]*gradplms; //sfact is over all sign of plm(pi-ncostheta) at l
qms_imag[4][i][mind] += alm_real[lmind + l-m]*gradplms;
sfact = -sfact;
} //for(l=firstl;l<=lmax;++l)
} //if(firstl <= lmax)
} //if(lmax >= lmin)
} //for(i=0;i<NringChunk;++i)
mTime[mind] += MPI_Wtime();
} //for(m=firstM;m<=lastM;++m)
//put data in array for transpose
for(i=0;i<NringChunk;++i)
{
nring = i + ringChunkStart - 1;
for(j=0;j<Nmaps;++j)
for(k=0;k<NmTD;++k)
{
//north ring
transDataReal[((2*nring)*Nmaps + j)*NmTD + k] = qmn_real[j][i][k];
transDataImag[((2*nring)*Nmaps + j)*NmTD + k] = qmn_imag[j][i][k];
//south ring
transDataReal[((2*nring+1)*Nmaps + j)*NmTD + k] = qms_real[j][i][k];
transDataImag[((2*nring+1)*Nmaps + j)*NmTD + k] = qms_imag[j][i][k];
}
}
}//for(chunkInd=0;chunkInd<Nchunks;++chunkInd)
///do last ring on equator as a special case to avoid branching in loops
get_ring_info2(2*Nside,&nstartpix,&ringpix,&ncostheta,&nsintheta,&shifted,plan.order);
//sum over l at fixed m for each ring using only alms on ThisTask
for(m=firstM;m<=lastM;++m)
{
mind = m-firstM;
mTime[mind] -= MPI_Wtime();
for(mapNum=0;mapNum<6;++mapNum)
{
qmn_real[mapNum][0][mind] = 0.0;
qmn_imag[mapNum][0][mind] = 0.0;
}
//lmind tracks alm coefficients for this m
lmind = (lmax+1)*(m-firstM) + ((firstM-2)*(firstM+1))/2 - ((m-2)*(m+1))/2;
//do not sum over Ylm which are too small
lmin = get_lmin_ylm(m,(float) (nsintheta));
if(lmin <= lmax)
{
plmTime -= MPI_Wtime();
plmgen(ncostheta,nsintheta,m,plm,&firstl,plmdata);
plmTime += MPI_Wtime();
//now do sum over l
if(firstl <= lmax)
{
for(l=firstl;l<=lmax;++l)
{
//alm -> map
rval = alm_real[lmind + l-m]*plm[l];
ival = alm_imag[lmind + l-m]*plm[l];
qmn_real[0][0][mind] += rval;//alm_real[lmind + l-m]*plm[l];
qmn_imag[0][0][mind] += ival;//alm_imag[lmind + l-m]*plm[l];
//gradient w.r.t. phi is i*m/sin(\theta)P_{lm}\exp(i*m*\phi)*a_{lm} \hat{\phi}
rval *= m;
ival *= m;
qmn_real[2][0][mind] -= ival;//+= -1.0*alm_imag[lmind + l-m]*plm[l]*((double) m);
qmn_imag[2][0][mind] += rval;//alm_real[lmind + l-m]*plm[l]*((double) m);
//del2phi_div_sin2theta is -m^2/sin^{2}(\theta)P_{lm}\exp(i*m*\phi)*a_{lm}
rval *= m;
ival *= m;
qmn_real[5][0][mind] -= rval;//+= -1.0*alm_real[lmind + l-m]*plm[l]*((double) (m*m));
qmn_imag[5][0][mind] -= ival;//+= -1.0*alm_imag[lmind + l-m]*plm[l]*((double) (m*m));
}
l = firstl;
gradfact = ncostheta/nsintheta;
if(l > 0)
{
//grad theta
gradplmn = ((double) l)*gradfact*plm[l];
qmn_real[1][0][mind] += alm_real[lmind + l-m]*gradplmn;
qmn_imag[1][0][mind] += alm_imag[lmind + l-m]*gradplmn;
//we need grad^2\theta which is l*cos\theta/sin\theta\gradplm[l] - l*plm[l]
// - l*cos^{2}\theta/sin^{2}\theta*plm[l]
// + (l+m)*sqrt((2*l+1)/(2*l-1)*(l-m)/(l+m))*plm[l-1]*cos\theta/sin^{2}\theta
// - (l+m)*sqrt((2*l+1)/(2*l-1)*(l-m)/(l+m))*\gradplm[l-1]/sin\theta
gradquantn = ((double) l)*gradfact*gradplmn - ((double) l)*plm[l]*(1.0 + gradfact*gradfact);
qmn_real[3][0][mind] += alm_real[lmind + l-m]*gradquantn;
qmn_imag[3][0][mind] += alm_imag[lmind + l-m]*gradquantn;
gradplm_lm1_n = gradplmn;
//grad theta grad phi
gradplmn *= m;
qmn_real[4][0][mind] -= alm_imag[lmind + l-m]*gradplmn;
qmn_imag[4][0][mind] += alm_real[lmind + l-m]*gradplmn;
}
else
gradplm_lm1_n = 0.0;
++firstl;
for(l=firstl;l<=lmax;++l)
{
//grad theta
gradplmn = ((double) l)*gradfact*plm[l] - svec[l+lmaxp1*(m-firstM)]*plm[l-1]/nsintheta;
qmn_real[1][0][mind] += alm_real[lmind + l-m]*gradplmn;
qmn_imag[1][0][mind] += alm_imag[lmind + l-m]*gradplmn;
//we need grad^2\theta which is l*cos\theta/sin\theta\gradplm[l] - l*plm[l]
// - l*cos^{2}\theta/sin^{2}\theta*plm[l]
// + (l+m)*sqrt((2*l+1)/(2*l-1)*(l-m)/(l+m))*plm[l-1]*cos\theta/sin^{2}\theta
// - (l+m)*sqrt((2*l+1)/(2*l-1)*(l-m)/(l+m))*\gradplm[l-1]/sin\theta
gradquantn = ((double) l)*gradfact*gradplmn - ((double) l)*plm[l]*(1.0 + gradfact*gradfact)
+ svec[l+lmaxp1*(m-firstM)]/nsintheta*(plm[l-1]*gradfact - gradplm_lm1_n);
qmn_real[3][0][mind] += alm_real[lmind + l-m]*gradquantn;
qmn_imag[3][0][mind] += alm_imag[lmind + l-m]*gradquantn;
gradplm_lm1_n = gradplmn;
//grad theta grad phi
gradplmn *= m;
qmn_real[4][0][mind] -= alm_imag[lmind + l-m]*gradplmn;
qmn_imag[4][0][mind] += alm_real[lmind + l-m]*gradplmn;
}//for(l=firstl;l<=lmax;++l)
}//if(firstl <= lmax)
}//if(lmax >= lmin)
mTime[mind] += MPI_Wtime();
}//for(m=firstM;m<=lastM;++m)
nring = 2*Nside - 1;
for(j=0;j<Nmaps;++j)
{
for(k=0;k<NmTD;++k)
{
//north ring
transDataReal[((2*nring)*Nmaps + j)*NmTD + k] = qmn_real[j][0][k];
transDataImag[((2*nring)*Nmaps + j)*NmTD + k] = qmn_imag[j][0][k];
}//for(k=0;k<NmTD;++k)
}//for(j=0;j<Nmaps;++j)
//free some mem
free(plm);
memTot -= sizeof(double)*(lmax+1);
plmgen_destroy(plmdata);
free(svec);
memTot -= sizeof(double)*(lmax+1)*NMThisTask;
for(mapNum=0;mapNum<6;++mapNum)
{
for(i=0;i<NringChunkBase;++i)
{
free(qmn_real[mapNum][i]);
memTot -= sizeof(double)*Nqm;
free(qmn_imag[mapNum][i]);
memTot -= sizeof(double)*Nqm;
free(qms_real[mapNum][i]);
memTot -= sizeof(double)*Nqm;
free(qms_imag[mapNum][i]);
memTot -= sizeof(double)*Nqm;
}
free(qmn_real[mapNum]);
memTot -= sizeof(double*)*NringChunkBase;
free(qmn_imag[mapNum]);
memTot -= sizeof(double*)*NringChunkBase;
free(qms_real[mapNum]);
memTot -= sizeof(double*)*NringChunkBase;
free(qms_imag[mapNum]);
memTot -= sizeof(double*)*NringChunkBase;
}
free(ringpixRingChunk);
memTot -= sizeof(long)*NringChunkBase;
free(shiftedRingChunk);
memTot -= sizeof(long)*NringChunkBase;
free(nsinthetaRingChunk);
memTot -= sizeof(double)*NringChunkBase;
free(ncosthetaRingChunk);
memTot -= sizeof(double)*NringChunkBase;
sumTime += MPI_Wtime();
/* now do transpose step
done with MPI_Alltoallv
1) compute displacements and counts
2) transpose real map
3) transpose imag map
*/
transTime -= MPI_Wtime();
sendcnts = (int*)malloc(sizeof(int)*NTasks);
assert(sendcnts != NULL);
sdispls = (int*)malloc(sizeof(int)*NTasks);
assert(sdispls != NULL);
recvcnts = (int*)malloc(sizeof(int)*NTasks);
assert(recvcnts != NULL);
rdispls = (int*)malloc(sizeof(int)*NTasks);
assert(rdispls != NULL);
memTot += 4*sizeof(int)*NTasks;
for(i=0;i<NTasks;++i)
{
//compute number of rings on task i
j = 2*(plan.lastRingTasks[i] - plan.firstRingTasks[i] + 1);
if(plan.lastRingTasks[i] == 2*Nside)
--j;
sendcnts[i] = NMThisTask*Nmaps*j;
}
sdispls[0] = 0;
for(i=1;i<NTasks;++i)
sdispls[i] = sdispls[i-1] + sendcnts[i-1];
MPI_Alltoall(sendcnts,1,MPI_INT,recvcnts,1,MPI_INT,MPI_COMM_WORLD);
rdispls[0] = 0;
for(i=1;i<NTasks;++i)
rdispls[i] = rdispls[i-1] + recvcnts[i-1];
NrTDR = 2*(plan.lastRingTasks[ThisTask] - plan.firstRingTasks[ThisTask] + 1);
if(plan.lastRingTasks[ThisTask] == 2*Nside)
--NrTDR;
NmTDR = plan.lmax+1;
transDataRealRecv = (double*)malloc(sizeof(double)*NrTDR*Nmaps*NmTDR);
assert(transDataRealRecv != NULL);
memTot += sizeof(double)*NrTDR*Nmaps*NmTDR;
transDataImagRecv = (double*)malloc(sizeof(double)*NrTDR*Nmaps*NmTDR);
assert(transDataImagRecv != NULL);
memTot += sizeof(double)*NrTDR*Nmaps*NmTDR;
int log2NTasks = 0;
while(NTasks > (1 << log2NTasks))
++log2NTasks;
int level;
int sendTask,recvTask;
MPI_Status Stat;
//algorithm to loop through pairs of tasks linearly
// -lifted from Gadget-2 under GPL (http://www.gnu.org/copyleft/gpl.html)
// -see pm_periodic.c from Gadget-2 at http://www.mpa-garching.mpg.de/gadget/
//
for(level = 0; level < (1 << log2NTasks); level++) // note: for level=0, target is the same task
{
sendTask = ThisTask;
recvTask = ThisTask ^ level;
if(recvTask < NTasks)
{
if(sendTask != recvTask)
{
MPI_Sendrecv(transDataReal+sdispls[recvTask],sendcnts[recvTask],MPI_DOUBLE,recvTask,13,
transDataRealRecv+rdispls[recvTask],recvcnts[recvTask],MPI_DOUBLE,recvTask,13,
MPI_COMM_WORLD,&Stat);
MPI_Sendrecv(transDataImag+sdispls[recvTask],sendcnts[recvTask],MPI_DOUBLE,recvTask,14,
transDataImagRecv+rdispls[recvTask],recvcnts[recvTask],MPI_DOUBLE,recvTask,14,
MPI_COMM_WORLD,&Stat);
}
else // just move cells into workspace since sendTask == recvTask and Nsend == Nrecv
{
for(i=0;i<recvcnts[recvTask];++i)
transDataRealRecv[rdispls[recvTask]+i] = transDataReal[sdispls[recvTask]+i];
for(i=0;i<recvcnts[recvTask];++i)
transDataImagRecv[rdispls[recvTask]+i] = transDataImag[sdispls[recvTask]+i];
}
}
}
free(transDataReal);
memTot -= sizeof(double)*NrTD*Nmaps*NmTD;
free(transDataImag);
memTot -= sizeof(double)*NrTD*Nmaps*NmTD;
/* this version uses MPI_Alltoallv - the version above seems to be faster
transDataRealRecv = (double*)malloc(sizeof(double)*NrTDR*Nmaps*NmTDR);
assert(transDataRealRecv != NULL);
memTot += sizeof(double)*NrTDR*Nmaps*NmTDR;
#ifdef DEBUG //mem high water for this part happens here
#if DEBUG_LEVEL > 0
fprintf(stderr,"%f MB allocated in alm2allmaps_mpi.\n",((double) (sizeof(double)*(memTot)))/1024.0/1024.0);
#endif
#endif
MPI_Alltoallv(transDataReal,sendcnts,sdispls,MPI_DOUBLE,transDataRealRecv,recvcnts,rdispls,MPI_DOUBLE,MPI_COMM_WORLD);
free(transDataReal);
memTot -= sizeof(double)*NrTD*Nmaps*NmTD;
transDataImagRecv = (double*)malloc(sizeof(double)*NrTDR*Nmaps*NmTDR);
assert(transDataImagRecv != NULL);
memTot += sizeof(double)*NrTDR*Nmaps*NmTDR;
MPI_Alltoallv(transDataImag,sendcnts,sdispls,MPI_DOUBLE,transDataImagRecv,recvcnts,rdispls,MPI_DOUBLE,MPI_COMM_WORLD);
free(transDataImag);
memTot -= sizeof(double)*NrTD*Nmaps*NmTD;
*/
free(sendcnts);
free(sdispls);
free(recvcnts);
memTot -= 3*sizeof(int)*NTasks;
transTime += MPI_Wtime();
//now sort rings into their proper pixels
pixTime -= MPI_Wtime();
double *ringTime;
ringTime = (double*)malloc(sizeof(double)*NringsThisTask);
memTot += sizeof(double)*NringsThisTask;
assert(ringTime != NULL);
for(i=0;i<NringsThisTask;++i)
ringTime[i] = 0.0;
#ifdef DEBUG
#if DEBUG_LEVEL > 0
fprintf(stderr,"%f MB allocated in alm2allmaps_mpi.\n",((double) (sizeof(double)*(memTot)))/1024.0/1024.0);
#endif
#endif
//zero mapvecs
for(nring=firstRing;nring<=lastLoopRing;++nring)
{
ringTime[nring-firstRing] -= MPI_Wtime();
get_ring_info2(nring,&nstartpix,&ringpix,&ncostheta,&nsintheta,&shifted,plan.order);
ringpix_complex = ringpix/2+1;
for(mapNum=0;mapNum<6;++mapNum)
for(i=0;i<ringpix_complex;++i)
{
//north rings
mapvec_complex[mapNum][plan.northStartIndMapvec[nring-firstRing]+i][0] = 0.0;
mapvec_complex[mapNum][plan.northStartIndMapvec[nring-firstRing]+i][1] = 0.0;
//south rings
mapvec_complex[mapNum][plan.southStartIndMapvec[nring-firstRing]+i][0] = 0.0;
mapvec_complex[mapNum][plan.southStartIndMapvec[nring-firstRing]+i][1] = 0.0;
}
ringTime[nring-firstRing] += MPI_Wtime();
}
if(lastRing == Nrings)
{
ringTime[lastRing-firstRing] -= MPI_Wtime();
get_ring_info2(lastRing,&nstartpix,&ringpix,&ncostheta,&nsintheta,&shifted,plan.order);
ringpix_complex = ringpix/2+1;
for(mapNum=0;mapNum<6;++mapNum)
for(i=0;i<ringpix_complex;++i)
{
mapvec_complex[mapNum][plan.northStartIndMapvec[nring-firstRing]+i][0] = 0.0;
mapvec_complex[mapNum][plan.northStartIndMapvec[nring-firstRing]+i][1] = 0.0;
}
ringTime[lastRing-firstRing] += MPI_Wtime();
}
//unpack map rings
for(task=0;task<NTasks;++task)
{
start = rdispls[task];
NmT = plan.lastMTasks[task] - plan.firstMTasks[task] + 1;
for(i=0;i<NringsLoop;++i)
{
nring = i + firstRing;
ringTime[nring-firstRing] -= MPI_Wtime();
get_ring_info2(nring,&nstartpix,&ringpix,&ncostheta,&nsintheta,&shifted,plan.order);
ringpix_complex = ringpix/2+1;
for(k=0;k<NmT;++k)
{
m = k + plan.firstMTasks[task];
//positive m
mp = m%ringpix;
if(mp < ringpix_complex)
{
l = (m-mp)/ringpix;
if(shifted && (l%2))
skfact = -1.0;
else
skfact = 1.0;
for(mapNum=0;mapNum<6;++mapNum)
{
nind = start + ((2*(nring-firstRing))*Nmaps + mapNum)*NmT;
sind = start + ((2*(nring-firstRing)+1)*Nmaps + mapNum)*NmT;
mapvec_complex[mapNum][plan.northStartIndMapvec[nring-firstRing]+mp][0] += transDataRealRecv[nind+k]*skfact;
mapvec_complex[mapNum][plan.northStartIndMapvec[nring-firstRing]+mp][1] += transDataImagRecv[nind+k]*skfact;
mapvec_complex[mapNum][plan.southStartIndMapvec[nring-firstRing]+mp][0] += transDataRealRecv[sind+k]*skfact;
mapvec_complex[mapNum][plan.southStartIndMapvec[nring-firstRing]+mp][1] += transDataImagRecv[sind+k]*skfact;
}
}
//negative m
if(m > 0)
{
mp = ringpix - 1 - ((m-1)%(ringpix));
//assert(mp >= 0 && mp < ringpixRingChunk[i]); //this is true
if(mp < ringpix_complex)
{
//assert(mp < ringpix_complex) //this needs to be true and should be
l = (-m - mp)/ringpix;
if(shifted && (l%2))
skfact = -1.0;
else
skfact = 1.0;
for(mapNum=0;mapNum<6;++mapNum)
{
nind = start + ((2*(nring-firstRing))*Nmaps + mapNum)*NmT;
sind = start + ((2*(nring-firstRing)+1)*Nmaps + mapNum)*NmT;
mapvec_complex[mapNum][plan.northStartIndMapvec[nring-firstRing]+mp][0] += transDataRealRecv[nind+k]*skfact;
mapvec_complex[mapNum][plan.northStartIndMapvec[nring-firstRing]+mp][1] -= transDataImagRecv[nind+k]*skfact;
mapvec_complex[mapNum][plan.southStartIndMapvec[nring-firstRing]+mp][0] += transDataRealRecv[sind+k]*skfact;
mapvec_complex[mapNum][plan.southStartIndMapvec[nring-firstRing]+mp][1] -= transDataImagRecv[sind+k]*skfact;
}
}
}
}//for(k=0;k<NmT;++k)
ringTime[nring-firstRing] += MPI_Wtime();
}//for(i=0;i<NringsLoop;++i)
//do last ring if needed
if(lastRing == 2*Nside)
{
nring = lastRing;
ringTime[nring-firstRing] -= MPI_Wtime();
get_ring_info2(nring,&nstartpix,&ringpix,&ncostheta,&nsintheta,&shifted,plan.order);
ringpix_complex = ringpix/2+1;
for(k=0;k<NmT;++k)
{
m = k + plan.firstMTasks[task];
//positive m
mp = m%ringpix;
if(mp < ringpix_complex)
{
l = (m-mp)/ringpix;
if(shifted && (l%2))
skfact = -1.0;
else
skfact = 1.0;
for(mapNum=0;mapNum<6;++mapNum)
{
nind = start + ((2*(nring-firstRing))*Nmaps + mapNum)*NmT;
mapvec_complex[mapNum][plan.northStartIndMapvec[nring-firstRing]+mp][0] += transDataRealRecv[nind+k]*skfact;
mapvec_complex[mapNum][plan.northStartIndMapvec[nring-firstRing]+mp][1] += transDataImagRecv[nind+k]*skfact;
}
}
//negative m
if(m > 0)
{
mp = ringpix - 1 - ((m-1)%(ringpix));
//assert(mp >= 0 && mp < ringpixRingChunk[i]); //this is true
if(mp < ringpix_complex)
{
//assert(mp < ringpix_complex) //this needs to be true and should be
l = (-m - mp)/ringpix;
if(shifted && (l%2))
skfact = -1.0;
else
skfact = 1.0;
for(mapNum=0;mapNum<6;++mapNum)
{
nind = start + ((2*(nring-firstRing))*Nmaps + mapNum)*NmT;
mapvec_complex[mapNum][plan.northStartIndMapvec[nring-firstRing]+mp][0] += transDataRealRecv[nind+k]*skfact;
mapvec_complex[mapNum][plan.northStartIndMapvec[nring-firstRing]+mp][1] -= transDataImagRecv[nind+k]*skfact;
}
}
}
}//for(k=0;k<NmT;++k)
ringTime[nring-firstRing] += MPI_Wtime();
}//if(lastRing == 2*Nside)
}//for(task=0;task<NTasks;++task)
free(transDataRealRecv);
memTot -= sizeof(double)*NrTDR*Nmaps*NmTDR;
free(transDataImagRecv);
memTot -= sizeof(double)*NrTDR*Nmaps*NmTDR;
free(rdispls);
memTot -= sizeof(int)*NTasks;
pixTime += MPI_Wtime();
/* debugging code
i = 0;
for(m=plan.firstMTasks[ThisTask];m<=plan.lastMTasks[ThisTask];++m)
for(l=m;l<=plan.lmax;++l)
{
if(isinf(alm_real[i]) || isnan(alm_real[i]) ||
isinf(alm_imag[i]) || isnan(alm_imag[i]))
{
fprintf(stderr,"alm is nan or inf: l,m = %ld|%ld, value = %lg|%lg\n",l,m,alm_real[i],alm_imag[i]);
assert(0);
}
++i;
}
for(nring=firstRing;nring<=lastLoopRing;++nring)
{
get_ring_info2(nring,&nstartpix,&ringpix,&ncostheta,&nsintheta,&shifted,plan.order);
ringpix = ringpix/2+1;
for(mapNum=0;mapNum<6;++mapNum)
for(i=0;i<ringpix;++i)
if(isnan(mapvec_complex[mapNum][plan.northStartIndMapvec[nring-firstRing]][0]) ||
isinf(mapvec_complex[mapNum][plan.northStartIndMapvec[nring-firstRing]][0]) ||
isnan(mapvec_complex[mapNum][plan.northStartIndMapvec[nring-firstRing]][1]) ||
isinf(mapvec_complex[mapNum][plan.northStartIndMapvec[nring-firstRing]][1]))
{
fprintf(stderr,"complex mapvec is nan or inf: mapNum = %ld, north ring,ind = %ld|%ld, value = %lg|%lg\n",mapNum,nring,i,
mapvec_complex[mapNum][plan.northStartIndMapvec[nring-firstRing]][0],
mapvec_complex[mapNum][plan.northStartIndMapvec[nring-firstRing]][1]);
assert(0);
}
for(mapNum=0;mapNum<6;++mapNum)
for(i=0;i<ringpix;++i)
if(isnan(mapvec_complex[mapNum][plan.southStartIndMapvec[nring-firstRing]][0]) ||
isinf(mapvec_complex[mapNum][plan.southStartIndMapvec[nring-firstRing]][0]) ||
isnan(mapvec_complex[mapNum][plan.southStartIndMapvec[nring-firstRing]][1]) ||
isinf(mapvec_complex[mapNum][plan.southStartIndMapvec[nring-firstRing]][1]))
{
fprintf(stderr,"complex mapvec is nan or inf: mapNum = %ld, south ring,ind = %ld|%ld, value = %lg|%lg\n",mapNum,nring,i,
mapvec_complex[mapNum][plan.southStartIndMapvec[nring-firstRing]][0],
mapvec_complex[mapNum][plan.southStartIndMapvec[nring-firstRing]][1]);
assert(0);