HΦ  3.2.0
sz.c
Go to the documentation of this file.
1 /* HPhi - Quantum Lattice Model Simulator */
2 /* Copyright (C) 2015 The University of Tokyo */
3 
4 /* This program is free software: you can redistribute it and/or modify */
5 /* it under the terms of the GNU General Public License as published by */
6 /* the Free Software Foundation, either version 3 of the License, or */
7 /* (at your option) any later version. */
8 
9 /* This program is distributed in the hope that it will be useful, */
10 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
11 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
12 /* GNU General Public License for more details. */
13 
14 /* You should have received a copy of the GNU General Public License */
15 /* along with this program. If not, see <http://www.gnu.org/licenses/>. */
16 
17 #include <bitcalc.h>
18 #include "common/setmemory.h"
19 #include "FileIO.h"
20 #include "sz.h"
21 #include "wrapperMPI.h"
22 #include "xsetmem.h"
23 
40  long unsigned int ib,
41  long unsigned int ihfbit,
42  struct BindStruct *X,
43  long unsigned int *list_1_,
44  long unsigned int *list_2_1_,
45  long unsigned int *list_2_2_,
46  long unsigned int *list_jb_
47 );
48 
62 int sz
63 (
64  struct BindStruct *X,
65  long unsigned int *list_1_,
66  long unsigned int *list_2_1_,
67  long unsigned int *list_2_2_
68  )
69 {
70  FILE *fp,*fp_err;
71  char sdt[D_FileNameMax],sdt_err[D_FileNameMax];
72  long unsigned int *HilbertNumToSz;
73  long unsigned int i,icnt;
74  long unsigned int ib,jb;
75 
76  long unsigned int j;
77  long unsigned int div;
78  long unsigned int num_up,num_down;
79  long unsigned int irght,ilft,ihfbit;
80 
81  //*[s] for omp parall
82  unsigned int all_up,all_down,tmp_res,num_threads;
83  long unsigned int tmp_1,tmp_2,tmp_3;
84  long int **comb;
85  //*[e] for omp parall
86 
87  // [s] for Kondo
88  unsigned int N_all_up, N_all_down;
89  unsigned int all_loc;
90  long unsigned int num_loc, div_down;
91  unsigned int num_loc_up;
92  int icheck_loc;
93  int ihfSpinDown=0;
94  // [e] for Kondo
95 
96  long unsigned int i_max=0;
97  double idim=0.0;
98  long unsigned int div_up;
99 
100  // [s] for general spin
101  long int *list_2_1_Sz;
102  long int *list_2_2_Sz;
103  if(X->Def.iFlgGeneralSpin==TRUE){
104  list_2_1_Sz = li_1d_allocate(X->Check.sdim+2);
105  list_2_2_Sz = li_1d_allocate((X->Def.Tpow[X->Def.Nsite-1]*X->Def.SiteToBit[X->Def.Nsite-1]/X->Check.sdim)+2);
106  for(j=0; j<X->Check.sdim+2;j++){
107  list_2_1_Sz[j]=0;
108  }
109  for(j=0; j< (X->Def.Tpow[X->Def.Nsite-1]*X->Def.SiteToBit[X->Def.Nsite-1]/X->Check.sdim)+2; j++){
110  list_2_2_Sz[j]=0;
111  }
112  }
113  // [e] for general spin
114 
115  long unsigned int *list_jb;
116  list_jb = lui_1d_allocate(X->Large.SizeOflistjb);
117  for(i=0; i<X->Large.SizeOflistjb; i++){
118  list_jb[i]=0;
119  }
120 
121 //hacker
122  int hacker;
123  long unsigned int tmp_i,tmp_j,tmp_pow,max_tmp_i;
124  long unsigned int ia,ja;
125  long unsigned int ibpatn=0;
126 //hacker
127 
128  int iSpnup, iMinup,iAllup;
129  unsigned int N2=0;
130  unsigned int N=0;
131  fprintf(stdoutMPI, "%s", cProStartCalcSz);
134 
135  if(X->Check.idim_max!=0){
136  switch(X->Def.iCalcModel){
137  case HubbardGC:
138  case HubbardNConserved:
139  case Hubbard:
140  N2=2*X->Def.Nsite;
141  idim = pow(2.0,N2);
142  break;
143  case KondoGC:
144  case Kondo:
145  N2 = 2*X->Def.Nsite;
146  N = X->Def.Nsite;
147  idim = pow(2.0,N2);
148  for(j=0;j<N;j++){
149  fprintf(stdoutMPI, cStateLocSpin,j,X->Def.LocSpn[j]);
150  }
151  break;
152  case SpinGC:
153  case Spin:
154  N=X->Def.Nsite;
155  if(X->Def.iFlgGeneralSpin==FALSE){
156  idim = pow(2.0, N);
157  }
158  else{
159  idim=1;
160  for(j=0; j<N; j++){
161  idim *= X->Def.SiteToBit[j];
162  }
163  }
164  break;
165  }
166  comb = li_2d_allocate(X->Def.Nsite+1,X->Def.Nsite+1);
167  i_max=X->Check.idim_max;
168 
169  switch(X->Def.iCalcModel){
170  case HubbardNConserved:
171  case Hubbard:
172  case KondoGC:
173  case Kondo:
174  case Spin:
175  if(X->Def.iFlgGeneralSpin==FALSE){
176  if(GetSplitBitByModel(X->Def.Nsite, X->Def.iCalcModel, &irght, &ilft, &ihfbit)!=0){
177  exitMPI(-1);
178  }
179  X->Large.irght=irght;
180  X->Large.ilft=ilft;
181  X->Large.ihfbit=ihfbit;
182  //fprintf(stdoutMPI, "idim=%lf irght=%ld ilft=%ld ihfbit=%ld \n",idim,irght,ilft,ihfbit);
183  }
184  else{
185  ihfbit=X->Check.sdim;
186  //fprintf(stdoutMPI, "idim=%lf ihfbit=%ld \n",idim, ihfbit);
187  }
188  break;
189  default:
190  break;
191  }
192 
193  icnt=1;
194  jb=0;
195 
196  if(X->Def.READ==1){
197  if(Read_sz(X, irght, ilft, ihfbit, &i_max)!=0){
198  exitMPI(-1);
199  }
200  }
201  else{
202  sprintf(sdt, cFileNameSzTimeKeep, X->Def.CDataFileHead);
203 #ifdef _OPENMP
204  num_threads = omp_get_max_threads();
205 #else
206  num_threads=1;
207 #endif
208  childfopenMPI(sdt,"a", &fp);
209  fprintf(fp, "num_threads==%d\n",num_threads);
210  fclose(fp);
211 
212  //*[s] omp parallel
213 
216  switch(X->Def.iCalcModel){
217  case HubbardGC:
218  icnt = X->Def.Tpow[2*X->Def.Nsite-1]*2+0;/*Tpow[2*X->Def.Nsit]=1*/
219  break;
220 
221  case SpinGC:
222  if(X->Def.iFlgGeneralSpin==FALSE){
223  icnt = X->Def.Tpow[X->Def.Nsite-1]*2+0;/*Tpow[X->Def.Nsit]=1*/
224  }
225  else{
226  icnt = X->Def.Tpow[X->Def.Nsite-1]*X->Def.SiteToBit[X->Def.Nsite-1];
227  }
228  break;
229 
230  case KondoGC:
231  // this part can not be parallelized
232  jb = 0;
233  num_loc=0;
234  for(j=X->Def.Nsite/2; j< X->Def.Nsite ;j++){ // counting # of localized spins
235  if(X->Def.LocSpn[j] != ITINERANT){ // //ITINERANT ==0 -> itinerant
236  num_loc += 1;
237  }
238  }
239 
240  for(ib=0;ib<X->Check.sdim;ib++){
241  list_jb[ib]=jb;
242  i=ib*ihfbit;
243  icheck_loc=1;
244  for(j=(X->Def.Nsite+1)/2; j< X->Def.Nsite ;j++){
245  div_up = i & X->Def.Tpow[2*j];
246  div_up = div_up/X->Def.Tpow[2*j];
247  div_down = i & X->Def.Tpow[2*j+1];
248  div_down = div_down/X->Def.Tpow[2*j+1];
249  if(X->Def.LocSpn[j] != ITINERANT){
250  if(X->Def.Nsite%2==1 && j==(X->Def.Nsite/2)){
251  icheck_loc= icheck_loc;
252  }
253  else{
254  icheck_loc = icheck_loc*(div_up^div_down);// exclude doubllly ocupited site
255  }
256  }
257  }
258  if(icheck_loc == 1){
259  if(X->Def.Nsite%2==1 && X->Def.LocSpn[X->Def.Nsite/2] != ITINERANT){
260  jb +=X->Def.Tpow[X->Def.Nsite-1-(X->Def.NLocSpn-num_loc)];
261  }else{
262  jb +=X->Def.Tpow[X->Def.Nsite-(X->Def.NLocSpn-num_loc)];
263  }
264  }
265  }
266 
267  icnt = 0;
268 #pragma omp parallel for default(none) reduction(+:icnt) private(ib) firstprivate(ihfbit, N2, X) shared(list_1_, list_2_1_, list_2_2_, list_jb)
269  for(ib=0;ib<X->Check.sdim;ib++){
270  icnt+=child_omp_sz_KondoGC(ib, ihfbit, X, list_1_, list_2_1_, list_2_2_, list_jb);
271  }
272  break;
273 
274  case Hubbard:
275  hacker = X->Def.read_hacker;
276  if(hacker==0){
277  // this part can not be parallelized
278  jb = 0;
279  for(ib=0;ib<X->Check.sdim;ib++){ // sdim = 2^(N/2)
280  list_jb[ib] = jb;
281  i = ib*ihfbit;
282  //[s] counting # of up and down electrons
283  num_up = 0;
284  for(j=0;j<=N2-2;j+=2){ // even -> up spin
285  div=i & X->Def.Tpow[j];
286  div=div/X->Def.Tpow[j];
287  num_up+=div;
288  }
289  num_down=0;
290  for(j=1;j<=N2-1;j+=2){ // odd -> down spin
291  div=i & X->Def.Tpow[j];
292  div=div/X->Def.Tpow[j];
293  num_down+=div;
294  }
295  //[e] counting # of up and down electrons
296  tmp_res = X->Def.Nsite%2; // even Ns-> 0, odd Ns -> 1
297  all_up = (X->Def.Nsite+tmp_res)/2;
298  all_down = (X->Def.Nsite-tmp_res)/2;
299 
300  tmp_1 = Binomial(all_up,X->Def.Nup-num_up,comb,all_up);
301  tmp_2 = Binomial(all_down,X->Def.Ndown-num_down,comb,all_down);
302  jb += tmp_1*tmp_2;
303  }
304 
305  //#pragma omp barrier
308 
309  icnt = 0;
310  for(ib=0;ib<X->Check.sdim;ib++){
311  icnt+=child_omp_sz(ib,ihfbit, X, list_1_, list_2_1_, list_2_2_, list_jb);
312  }
313  break;
314  }else if(hacker==1){
315  // this part can not be parallelized
316  jb = 0;
317 
318  for(ib=0;ib<X->Check.sdim;ib++){
319  list_jb[ib]=jb;
320 
321  i=ib*ihfbit;
322  num_up=0;
323  for(j=0;j<=N2-2;j+=2){
324  div=i & X->Def.Tpow[j];
325  div=div/X->Def.Tpow[j];
326  num_up+=div;
327  }
328  num_down=0;
329  for(j=1;j<=N2-1;j+=2){
330  div=i & X->Def.Tpow[j];
331  div=div/X->Def.Tpow[j];
332  num_down+=div;
333  }
334 
335  tmp_res = X->Def.Nsite%2; // even Ns-> 0, odd Ns -> 1
336  all_up = (X->Def.Nsite+tmp_res)/2;
337  all_down = (X->Def.Nsite-tmp_res)/2;
338 
339  tmp_1 = Binomial(all_up,X->Def.Nup-num_up,comb,all_up);
340  tmp_2 = Binomial(all_down,X->Def.Ndown-num_down,comb,all_down);
341  jb += tmp_1*tmp_2;
342  }
343 
344  //#pragma omp barrier
347 
348  icnt = 0;
349 #pragma omp parallel for default(none) reduction(+:icnt) private(ib) firstprivate(ihfbit, X) shared(list_1_, list_2_1_, list_2_2_, list_jb)
350  for(ib=0;ib<X->Check.sdim;ib++){
351  icnt+=child_omp_sz_hacker(ib,ihfbit,X,list_1_, list_2_1_, list_2_2_, list_jb);
352  }
353  break;
354  }
355  else{
356  fprintf(stderr, "Error: CalcHS in ModPara file must be 0 or 1 for Hubbard model.");
357  return -1;
358  }
359 
360  case HubbardNConserved:
361  hacker = X->Def.read_hacker;
362  if(hacker==0){
363  // this part can not be parallelized
364  jb = 0;
365  iSpnup=0;
366  iMinup=0;
367  iAllup=X->Def.Ne;
368  if(X->Def.Ne > X->Def.Nsite){
369  iMinup = X->Def.Ne-X->Def.Nsite;
370  iAllup = X->Def.Nsite;
371  }
372  for(ib=0;ib<X->Check.sdim;ib++){
373  list_jb[ib]=jb;
374  i=ib*ihfbit;
375  num_up=0;
376  for(j=0;j<=N2-2;j+=2){
377  div=i & X->Def.Tpow[j];
378  div=div/X->Def.Tpow[j];
379  num_up+=div;
380  }
381  num_down=0;
382  for(j=1;j<=N2-1;j+=2){
383  div=i & X->Def.Tpow[j];
384  div=div/X->Def.Tpow[j];
385  num_down+=div;
386  }
387  tmp_res = X->Def.Nsite%2; // even Ns-> 0, odd Ns -> 1
388  all_up = (X->Def.Nsite+tmp_res)/2;
389  all_down = (X->Def.Nsite-tmp_res)/2;
390 
391  for(iSpnup=iMinup; iSpnup<= iAllup; iSpnup++){
392  tmp_1 = Binomial(all_up, iSpnup-num_up,comb,all_up);
393  tmp_2 = Binomial(all_down, X->Def.Ne-iSpnup-num_down,comb,all_down);
394  jb += tmp_1*tmp_2;
395  }
396  }
397  //#pragma omp barrier
400 
401  icnt = 0;
402 #pragma omp parallel for default(none) reduction(+:icnt) private(ib) firstprivate(ihfbit, N2, X) shared(list_1_, list_2_1_, list_2_2_, list_jb)
403  for(ib=0;ib<X->Check.sdim;ib++){
404  icnt+=child_omp_sz(ib,ihfbit, X,list_1_, list_2_1_, list_2_2_, list_jb);
405  }
406  break;
407  }
408  else if(hacker==1){
409  // this part can not be parallelized
410  jb = 0;
411  iSpnup=0;
412  iMinup=0;
413  iAllup=X->Def.Ne;
414  if(X->Def.Ne > X->Def.Nsite){
415  iMinup = X->Def.Ne-X->Def.Nsite;
416  iAllup = X->Def.Nsite;
417  }
418  for(ib=0;ib<X->Check.sdim;ib++){
419  list_jb[ib]=jb;
420  i=ib*ihfbit;
421  num_up=0;
422  for(j=0;j<=N2-2;j+=2){
423  div=i & X->Def.Tpow[j];
424  div=div/X->Def.Tpow[j];
425  num_up+=div;
426  }
427  num_down=0;
428  for(j=1;j<=N2-1;j+=2){
429  div=i & X->Def.Tpow[j];
430  div=div/X->Def.Tpow[j];
431  num_down+=div;
432  }
433  tmp_res = X->Def.Nsite%2; // even Ns-> 0, odd Ns -> 1
434  all_up = (X->Def.Nsite+tmp_res)/2;
435  all_down = (X->Def.Nsite-tmp_res)/2;
436 
437  for(iSpnup=iMinup; iSpnup<= iAllup; iSpnup++){
438  tmp_1 = Binomial(all_up, iSpnup-num_up,comb,all_up);
439  tmp_2 = Binomial(all_down, X->Def.Ne-iSpnup-num_down,comb,all_down);
440  jb += tmp_1*tmp_2;
441  }
442  }
443  //#pragma omp barrier
446 
447  icnt = 0;
448 #pragma omp parallel for default(none) reduction(+:icnt) private(ib) firstprivate(ihfbit, N2, X) shared(list_1_, list_2_1_, list_2_2_, list_jb)
449  for(ib=0;ib<X->Check.sdim;ib++){
450  icnt+=child_omp_sz_hacker(ib,ihfbit, X,list_1_, list_2_1_, list_2_2_, list_jb);
451  }
452 
453  break;
454  }
455  else{
456  fprintf(stderr, "Error: CalcHS in ModPara file must be 0 or 1 for Hubbard model.");
457  return -1;
458  }
459 
460  case Kondo:
461  // this part can not be parallelized
462  N_all_up = X->Def.Nup;
463  N_all_down = X->Def.Ndown;
464  fprintf(stdoutMPI, cStateNupNdown, N_all_up,N_all_down);
465 
466  jb = 0;
467  num_loc=0;
468  for(j=X->Def.Nsite/2; j< X->Def.Nsite ;j++){// counting localized # of spins
469  if(X->Def.LocSpn[j] != ITINERANT){
470  num_loc += 1;
471  }
472  }
473 
474  for(ib=0;ib<X->Check.sdim;ib++){ //sdim = 2^(N/2)
475  list_jb[ib] = jb;
476  i = ib*ihfbit; // ihfbit=pow(2,((Nsite+1)/2))
477  num_up = 0;
478  num_down = 0;
479  icheck_loc = 1;
480 
481  for(j=X->Def.Nsite/2; j< X->Def.Nsite ;j++){
482  div_up = i & X->Def.Tpow[2*j];
483  div_up = div_up/X->Def.Tpow[2*j];
484  div_down = i & X->Def.Tpow[2*j+1];
485  div_down = div_down/X->Def.Tpow[2*j+1];
486  if(X->Def.LocSpn[j] == ITINERANT){
487  num_up += div_up;
488  num_down += div_down;
489  }else{
490  num_up += div_up;
491  num_down += div_down;
492  if(X->Def.Nsite%2==1 && j==(X->Def.Nsite/2)){ // odd site
493  icheck_loc= icheck_loc;
494  ihfSpinDown=div_down;
495  if(div_down ==0){
496  num_up += 1;
497  }
498  }else{
499  icheck_loc = icheck_loc*(div_up^div_down);// exclude empty or doubly occupied site
500  }
501  }
502  }
503 
504  if(icheck_loc == 1){ // itinerant of local spins without holon or doublon
505  tmp_res = X->Def.Nsite%2; // even Ns-> 0, odd Ns -> 1
506  all_loc = X->Def.NLocSpn-num_loc; // # of local spins
507  all_up = (X->Def.Nsite+tmp_res)/2-all_loc;
508  all_down = (X->Def.Nsite-tmp_res)/2-all_loc;
509  if(X->Def.Nsite%2==1 && X->Def.LocSpn[X->Def.Nsite/2] != ITINERANT){
510  all_up = (X->Def.Nsite)/2-all_loc;
511  all_down = (X->Def.Nsite)/2-all_loc;
512  }
513 
514  for(num_loc_up=0; num_loc_up <= all_loc; num_loc_up++){
515  tmp_1 = Binomial(all_loc, num_loc_up, comb, all_loc);
516  if( X->Def.Nsite%2==1 && X->Def.LocSpn[X->Def.Nsite/2] != ITINERANT){
517  if(ihfSpinDown !=0){
518  tmp_2 = Binomial(all_up, X->Def.Nup-num_up-num_loc_up, comb, all_up);
519  tmp_3 = Binomial(all_down, X->Def.Ndown-num_down-(all_loc-num_loc_up), comb, all_down);
520  }
521  else{
522  tmp_2 = Binomial(all_up, X->Def.Nup-num_up-num_loc_up, comb, all_up);
523  tmp_3 = Binomial(all_down, X->Def.Ndown-num_down-(all_loc-num_loc_up), comb, all_down);
524  }
525  }
526  else{
527  tmp_2 = Binomial(all_up, X->Def.Nup-num_up-num_loc_up, comb, all_up);
528  tmp_3 = Binomial(all_down, X->Def.Ndown-num_down-(all_loc-num_loc_up), comb, all_down);
529  }
530  jb += tmp_1*tmp_2*tmp_3;
531  }
532  }
533 
534  }
535  //#pragma omp barrier
538 
539  hacker = X->Def.read_hacker;
540  if(hacker==0){
541  icnt = 0;
542 #pragma omp parallel for default(none) reduction(+:icnt) private(ib) firstprivate(ihfbit, N2, X) shared(list_1_, list_2_1_, list_2_2_, list_jb)
543  for(ib=0;ib<X->Check.sdim;ib++){
544  icnt+=child_omp_sz_Kondo(ib,ihfbit, X, list_1_, list_2_1_, list_2_2_, list_jb);
545  }
546  }else if(hacker==1){
547  icnt = 0;
548 #pragma omp parallel for default(none) reduction(+:icnt) private(ib) firstprivate(ihfbit, N2, X) shared(list_1_, list_2_1_, list_2_2_, list_jb)
549  for(ib=0;ib<X->Check.sdim;ib++){
550  icnt+=child_omp_sz_Kondo_hacker(ib,ihfbit, X, list_1_, list_2_1_, list_2_2_, list_jb);
551  }
552  }
553  break;
554 
555  case Spin:
556  // this part can not be parallelized
557  if(X->Def.iFlgGeneralSpin==FALSE){
558  hacker = X->Def.read_hacker;
559  //printf(" rank=%d:Ne=%ld ihfbit=%ld sdim=%ld\n", myrank,X->Def.Ne,ihfbit,X->Check.sdim);
560  // using hacker's delight only + no open mp
561  if(hacker == -1){
562  icnt = 1;
563  tmp_pow = 1;
564  tmp_i = 0;
565  jb = 0;
566  ja = 0;
567  while(tmp_pow < X->Def.Tpow[X->Def.Ne]){
568  tmp_i += tmp_pow;
569  tmp_pow = tmp_pow*2;
570  }
571  //printf("DEBUG: %ld %ld %ld %ld\n",tmp_i,X->Check.sdim,X->Def.Tpow[X->Def.Ne],X->Def.Nsite);
572  if(X->Def.Nsite%2==0){
573  max_tmp_i = X->Check.sdim*X->Check.sdim;
574  }else{
575  max_tmp_i = X->Check.sdim*X->Check.sdim*2-1;
576  }
577  while(tmp_i<max_tmp_i){
578  list_1_[icnt]=tmp_i;
579 
580  ia= tmp_i & irght;
581  ib= tmp_i & ilft;
582  ib= ib/ihfbit;
583  if(ib==ibpatn){
584  ja=ja+1;
585  }else{
586  ibpatn = ib;
587  ja = 1;
588  jb = icnt-1;
589  }
590 
591  list_2_1_[ia] = ja+1;
592  list_2_2_[ib] = jb+1;
593  tmp_j = snoob(tmp_i);
594  tmp_i = tmp_j;
595  icnt += 1;
596  }
597  icnt = icnt-1;
598  // old version + hacker's delight
599  }else if(hacker == 1){
600  jb = 0;
601  for(ib=0;ib<X->Check.sdim;ib++){
602  list_jb[ib]=jb;
603  i=ib*ihfbit;
604  num_up=0;
605  for(j=0;j<N; j++){
606  div_up = i & X->Def.Tpow[j];
607  div_up = div_up/X->Def.Tpow[j];
608  num_up +=div_up;
609  }
610  all_up = (X->Def.Nsite+1)/2;
611  tmp_1 = Binomial(all_up,X->Def.Ne-num_up,comb,all_up);
612  jb += tmp_1;
613  }
614  //#pragma omp barrier
617 
618  icnt = 0;
619 #pragma omp parallel for default(none) reduction(+:icnt) private(ib) firstprivate(ihfbit, N, X, list_1_, list_2_1_, list_2_2_, list_jb)
620  for(ib=0;ib<X->Check.sdim;ib++){
621  icnt+=child_omp_sz_spin_hacker(ib,ihfbit,N,X, list_1_, list_2_1_, list_2_2_, list_jb);
622  }
623  //printf(" rank=%d ib=%ld:Ne=%d icnt=%ld :idim_max=%ld N=%d\n", myrank,ib,X->Def.Ne,icnt,X->Check.idim_max,N);
624  // old version
625  }else if(hacker == 0){
626  jb = 0;
627  for(ib=0;ib<X->Check.sdim;ib++){
628  list_jb[ib]=jb;
629  i=ib*ihfbit;
630  num_up=0;
631  for(j=0;j<N; j++){
632  div_up = i & X->Def.Tpow[j];
633  div_up = div_up/X->Def.Tpow[j];
634  num_up +=div_up;
635  }
636  all_up = (X->Def.Nsite+1)/2;
637  tmp_1 = Binomial(all_up,X->Def.Ne-num_up,comb,all_up);
638  jb += tmp_1;
639  }
640  //#pragma omp barrier
643 
644  icnt = 0;
645 #pragma omp parallel for default(none) reduction(+:icnt) private(ib) firstprivate(ihfbit, N, X) shared(list_1_, list_2_1_, list_2_2_, list_jb)
646  for(ib=0;ib<X->Check.sdim;ib++){
647  icnt+=child_omp_sz_spin(ib,ihfbit,N,X,list_1_, list_2_1_, list_2_2_, list_jb);
648  }
649  }
650  else{
651  fprintf(stderr, "Error: CalcHS in ModPara file must be -1 or 0 or 1 for Spin model.");
652  return -1;
653  }
654  }else{
655  unsigned int Max2Sz=0;
656  unsigned int irghtsite=1;
657  long unsigned int itmpSize=1;
658  int i2Sz=0;
659  for(j=0; j<X->Def.Nsite; j++){
660  itmpSize *= X->Def.SiteToBit[j];
661  if(itmpSize==ihfbit){
662  break;
663  }
664  irghtsite++;
665  }
666  for(j=0; j<X->Def.Nsite; j++){
667  Max2Sz += X->Def.LocSpn[j];
668  }
669 
670  HilbertNumToSz = lui_1d_allocate(2*Max2Sz+1);
671  for(ib=0; ib<2*Max2Sz+1; ib++){
672  HilbertNumToSz[ib]=0;
673  }
674 
675  for(ib =0; ib<ihfbit; ib++){
676  i2Sz=0;
677  for(j=1; j<= irghtsite; j++){
678  i2Sz += GetLocal2Sz(j,ib, X->Def.SiteToBit, X->Def.Tpow);
679  }
680  list_2_1_Sz[ib]=i2Sz;
681  HilbertNumToSz[i2Sz+Max2Sz]++;
682  }
683  jb = 0;
684  long unsigned int ilftdim=(X->Def.Tpow[X->Def.Nsite-1]*X->Def.SiteToBit[X->Def.Nsite-1])/ihfbit;
685  for(ib=0;ib<ilftdim;ib++){
686  list_jb[ib]=jb;
687  i2Sz=0;
688  for(j=1;j<=(N-irghtsite); j++){
689  i2Sz += GetLocal2Sz(j+irghtsite,ib*ihfbit, X->Def.SiteToBit, X->Def.Tpow);
690  }
691  list_2_2_Sz[ib]=i2Sz;
692  if((X->Def.Total2Sz- i2Sz +(int)Max2Sz)>=0 && (X->Def.Total2Sz- i2Sz) <= (int)Max2Sz){
693  jb += HilbertNumToSz[X->Def.Total2Sz- i2Sz +Max2Sz];
694  }
695  }
696 
699 
700  icnt = 0;
701 #pragma omp parallel for default(none) reduction(+:icnt) private(ib) firstprivate(ilftdim, ihfbit, X) shared(list_1_, list_2_1_, list_2_2_, list_2_1_Sz, list_2_2_Sz,list_jb)
702  for(ib=0;ib<ilftdim; ib++){
703  icnt+=child_omp_sz_GeneralSpin(ib,ihfbit,X, list_1_, list_2_1_, list_2_2_, list_2_1_Sz, list_2_2_Sz,list_jb);
704  }
705 
706  free_lui_1d_allocate(HilbertNumToSz);
707  }
708 
709  break;
710  default:
711  exitMPI(-1);
712 
713  }
714  i_max=icnt;
715  //fprintf(stdoutMPI, "Debug: Xicnt=%ld \n",icnt);
718 
719  }
720 
721  if(X->Def.iFlgCalcSpec == CALCSPEC_NOT){
722  if(X->Def.iCalcModel==HubbardNConserved){
723  X->Def.iCalcModel=Hubbard;
724  }
725  }
726 
727  //Error message
728  //i_max=i_max+1;
729  if(i_max!=X->Check.idim_max){
730  fprintf(stderr, "%s", cErrSz);
731  fprintf(stderr, cErrSz_ShowDim, i_max, X->Check.idim_max);
732  strcpy(sdt_err,cFileNameErrorSz);
733  if(childfopenMPI(sdt_err,"a",&fp_err)!=0){
734  exitMPI(-1);
735  }
736  fprintf(fp_err, "%s",cErrSz_OutFile);
737  fclose(fp_err);
738  exitMPI(-1);
739  }
740 
741  free_li_2d_allocate(comb);
742  }
743  fprintf(stdoutMPI, "%s", cProEndCalcSz);
744 
745  free(list_jb);
746  if(X->Def.iFlgGeneralSpin==TRUE){
747  free(list_2_1_Sz);
748  free(list_2_2_Sz);
749  }
750  return 0;
751 }
752 
767 long int Binomial(int n,int k,long int **comb,int Nsite){
768  // nCk, Nsite=max(n)
769  int tmp_i,tmp_j;
770 
771  if(n==0 && k==0){
772  return 1;
773  }
774  else if(n<0 || k<0 || n<k){
775  return 0;
776  }
777 
778  for(tmp_i=0;tmp_i<=Nsite;tmp_i++){
779  for(tmp_j=0;tmp_j<=Nsite;tmp_j++){
780  comb[tmp_i][tmp_j] = 0;
781  }
782  }
783 
784  comb[0][0] = 1;
785  comb[1][0] = 1;
786  comb[1][1] = 1;
787  for(tmp_i=2;tmp_i<=n;tmp_i++){
788  for(tmp_j=0;tmp_j<=tmp_i;tmp_j++){
789  if(tmp_j==0){
790  comb[tmp_i][tmp_j] = 1;
791  }else if(tmp_j==tmp_i){
792  comb[tmp_i][tmp_j] = 1;
793  }else{
794  comb[tmp_i][tmp_j] = comb[tmp_i-1][tmp_j-1]+comb[tmp_i-1][tmp_j];
795  }
796  }
797  }
798  return comb[n][k];
799 }
800 
817  long unsigned int ib,
818  long unsigned int ihfbit,
819  struct BindStruct *X,
820  long unsigned int *list_1_,
821  long unsigned int *list_2_1_,
822  long unsigned int *list_2_2_,
823  long unsigned int *list_jb_
824  )
825 {
826  long unsigned int i,j;
827  long unsigned int ia,ja,jb;
828  long unsigned int div_down, div_up;
829  long unsigned int num_up,num_down;
830  long unsigned int tmp_num_up,tmp_num_down;
831 
832  jb = list_jb_[ib];
833  i = ib*ihfbit;
834 
835  num_up = 0;
836  num_down = 0;
837  for(j=0;j< X->Def.Nsite ;j++){
838  div_up = i & X->Def.Tpow[2*j];
839  div_up = div_up/X->Def.Tpow[2*j];
840  div_down = i & X->Def.Tpow[2*j+1];
841  div_down = div_down/X->Def.Tpow[2*j+1];
842  num_up += div_up;
843  num_down += div_down;
844  }
845 
846  ja=1;
847  tmp_num_up = num_up;
848  tmp_num_down = num_down;
849 
850  if(X->Def.iCalcModel==Hubbard){
851  for(ia=0;ia<X->Check.sdim;ia++){
852  i=ia;
853  num_up = tmp_num_up;
854  num_down = tmp_num_down;
855 
856  for(j=0;j<X->Def.Nsite;j++){
857  div_up = i & X->Def.Tpow[2*j];
858  div_up = div_up/X->Def.Tpow[2*j];
859  div_down = i & X->Def.Tpow[2*j+1];
860  div_down = div_down/X->Def.Tpow[2*j+1];
861  num_up += div_up;
862  num_down += div_down;
863  }
864  if(num_up == X->Def.Nup && num_down == X->Def.Ndown){
865  list_1_[ja+jb]=ia+ib*ihfbit;
866  list_2_1_[ia]=ja+1;
867  list_2_2_[ib]=jb+1;
868  ja+=1;
869  }
870  }
871  }
872  else if(X->Def.iCalcModel==HubbardNConserved){
873  for(ia=0;ia<X->Check.sdim;ia++){
874  i=ia;
875  num_up = tmp_num_up;
876  num_down = tmp_num_down;
877 
878  for(j=0;j<X->Def.Nsite;j++){
879  div_up = i & X->Def.Tpow[2*j];
880  div_up = div_up/X->Def.Tpow[2*j];
881  div_down = i & X->Def.Tpow[2*j+1];
882  div_down = div_down/X->Def.Tpow[2*j+1];
883  num_up += div_up;
884  num_down += div_down;
885  }
886  if( (num_up+num_down) == X->Def.Ne){
887  list_1_[ja+jb]=ia+ib*ihfbit;
888  list_2_1_[ia]=ja+1;
889  list_2_2_[ib]=jb+1;
890  ja+=1;
891  }
892  }
893  }
894  ja=ja-1;
895  return ja;
896 }
912 int child_omp_sz_hacker(long unsigned int ib,
913  long unsigned int ihfbit,
914  struct BindStruct *X,
915  long unsigned int *list_1_,
916  long unsigned int *list_2_1_,
917  long unsigned int *list_2_2_,
918  long unsigned int *list_jb_
919  )
920 {
921  long unsigned int i,j;
922  long unsigned int ia,ja,jb;
923  long unsigned int div_down, div_up;
924  long unsigned int num_up,num_down;
925  long unsigned int tmp_num_up,tmp_num_down;
926 
927  jb = list_jb_[ib];
928  i = ib*ihfbit;
929 
930  num_up = 0;
931  num_down = 0;
932  for(j=0;j< X->Def.Nsite ;j++){
933  div_up = i & X->Def.Tpow[2*j];
934  div_up = div_up/X->Def.Tpow[2*j];
935  div_down = i & X->Def.Tpow[2*j+1];
936  div_down = div_down/X->Def.Tpow[2*j+1];
937  num_up += div_up;
938  num_down += div_down;
939  }
940 
941  ja=1;
942  tmp_num_up = num_up;
943  tmp_num_down = num_down;
944 
945  if(X->Def.iCalcModel==Hubbard){
946  if(tmp_num_up <= X->Def.Nup && tmp_num_down <= X->Def.Ndown){ //do not exceed Nup and Ndown
947  ia = X->Def.Tpow[X->Def.Nup+X->Def.Ndown-tmp_num_up-tmp_num_down]-1;
948  if(ia < X->Check.sdim){
949  num_up = tmp_num_up;
950  num_down = tmp_num_down;
951  for(j=0;j<X->Def.Nsite;j++){
952  div_up = ia & X->Def.Tpow[2*j];
953  div_up = div_up/X->Def.Tpow[2*j];
954  div_down = ia & X->Def.Tpow[2*j+1];
955  div_down = div_down/X->Def.Tpow[2*j+1];
956  num_up += div_up;
957  num_down += div_down;
958  }
959  if(num_up == X->Def.Nup && num_down == X->Def.Ndown){
960  list_1_[ja+jb]=ia+ib*ihfbit;
961  list_2_1_[ia]=ja+1;
962  list_2_2_[ib]=jb+1;
963  ja+=1;
964  }
965  if(ia!=0){
966  ia = snoob(ia);
967  while(ia < X->Check.sdim){
968  num_up = tmp_num_up;
969  num_down = tmp_num_down;
970  for(j=0;j<X->Def.Nsite;j++){
971  div_up = ia & X->Def.Tpow[2*j];
972  div_up = div_up/X->Def.Tpow[2*j];
973  div_down = ia & X->Def.Tpow[2*j+1];
974  div_down = div_down/X->Def.Tpow[2*j+1];
975  num_up += div_up;
976  num_down += div_down;
977  }
978  if(num_up == X->Def.Nup && num_down == X->Def.Ndown){
979  list_1_[ja+jb]=ia+ib*ihfbit;
980  list_2_1_[ia]=ja+1;
981  list_2_2_[ib]=jb+1;
982  ja+=1;
983  }
984  ia = snoob(ia);
985  }
986  }
987  }
988  }
989  }
990  else if(X->Def.iCalcModel==HubbardNConserved){
991  if(tmp_num_up+tmp_num_down <= X->Def.Ne){ //do not exceed Ne
992  ia = X->Def.Tpow[X->Def.Ne-tmp_num_up-tmp_num_down]-1;
993  if(ia < X->Check.sdim){
994  list_1_[ja+jb]=ia+ib*ihfbit;
995  list_2_1_[ia]=ja+1;
996  list_2_2_[ib]=jb+1;
997  ja+=1;
998  if(ia!=0){
999  ia = snoob(ia);
1000  while(ia < X->Check.sdim){
1001  list_1_[ja+jb]=ia+ib*ihfbit;
1002  list_2_1_[ia]=ja+1;
1003  list_2_2_[ib]=jb+1;
1004  ja+=1;
1005  ia = snoob(ia);
1006  }
1007  }
1008  }
1009  }
1010  }
1011  ja=ja-1;
1012  return ja;
1013 }
1014 
1030  long unsigned int ib, //[in]
1031  long unsigned int ihfbit, //[in]
1032  struct BindStruct *X, //[in]
1033  long unsigned int *list_1_, //[out]
1034  long unsigned int *list_2_1_,//[out]
1035  long unsigned int *list_2_2_,//[out]
1036  long unsigned int *list_jb_ //[in]
1037  )
1038 {
1039  long unsigned int i,j;
1040  long unsigned int ia,ja,jb;
1041  long unsigned int div_down, div_up;
1042  long unsigned int num_up,num_down;
1043  long unsigned int tmp_num_up,tmp_num_down;
1044  int icheck_loc;
1045 
1046  jb = list_jb_[ib];
1047  i = ib*ihfbit;
1048 
1049  num_up = 0;
1050  num_down = 0;
1051  icheck_loc=1;
1052  for(j=X->Def.Nsite/2; j< X->Def.Nsite ;j++){
1053  div_up = i & X->Def.Tpow[2*j];
1054  div_up = div_up/X->Def.Tpow[2*j];
1055  div_down = i & X->Def.Tpow[2*j+1];
1056  div_down = div_down/X->Def.Tpow[2*j+1];
1057 
1058  if(X->Def.LocSpn[j] == ITINERANT){
1059  num_up += div_up;
1060  num_down += div_down;
1061  }else{
1062  num_up += div_up;
1063  num_down += div_down;
1064  if(X->Def.Nsite%2==1 && j==(X->Def.Nsite/2)){
1065  icheck_loc= icheck_loc;
1066  }
1067  else{
1068  icheck_loc = icheck_loc*(div_up^div_down);// exclude doubllly ocupited site
1069  }
1070  }
1071  }
1072 
1073  ja=1;
1074  tmp_num_up = num_up;
1075  tmp_num_down = num_down;
1076  if(icheck_loc ==1){
1077  for(ia=0;ia<X->Check.sdim;ia++){
1078  i=ia;
1079  num_up = tmp_num_up;
1080  num_down = tmp_num_down;
1081  icheck_loc=1;
1082  for(j=0;j<(X->Def.Nsite+1)/2;j++){
1083  div_up = i & X->Def.Tpow[2*j];
1084  div_up = div_up/X->Def.Tpow[2*j];
1085  div_down = i & X->Def.Tpow[2*j+1];
1086  div_down = div_down/X->Def.Tpow[2*j+1];
1087 
1088  if(X->Def.LocSpn[j] == ITINERANT){
1089  num_up += div_up;
1090  num_down += div_down;
1091  }else{
1092  num_up += div_up;
1093  num_down += div_down;
1094  if(X->Def.Nsite%2==1 && j==(X->Def.Nsite/2)){
1095  icheck_loc= icheck_loc;
1096  }
1097  else{
1098  icheck_loc = icheck_loc*(div_up^div_down);// exclude doubllly ocupited site
1099  }
1100  }
1101  }
1102 
1103  if(icheck_loc == 1 && X->Def.LocSpn[X->Def.Nsite/2] != ITINERANT && X->Def.Nsite%2==1){
1104  div_up = ia & X->Def.Tpow[X->Def.Nsite-1];
1105  div_up = div_up/X->Def.Tpow[X->Def.Nsite-1];
1106  div_down = (ib*ihfbit) & X->Def.Tpow[X->Def.Nsite];
1107  div_down = div_down/X->Def.Tpow[X->Def.Nsite];
1108  icheck_loc= icheck_loc*(div_up^div_down);
1109  }
1110 
1111  if(num_up == X->Def.Nup && num_down == X->Def.Ndown && icheck_loc==1){
1112  list_1_[ja+jb]=ia+ib*ihfbit;
1113  /*
1114  list_2_1_[ia]=ja;
1115  list_2_2_[ib]=jb;
1116  */
1117  list_2_1_[ia]=ja+1;
1118  list_2_2_[ib]=jb+1;
1119  //printf("DEBUG: rank=%d, list_1[%d]=%d, list_2_1_[%d]=%d, list_2_2_[%d]=%d\n", myrank, ja+jb, list_1_[ja+jb], ia, list_2_1[ia], ib, list_2_2[ib]);
1120  ja+=1;
1121  }
1122  }
1123  }
1124  ja=ja-1;
1125  return ja;
1126 }
1142  long unsigned int ib,
1143  long unsigned int ihfbit,
1144  struct BindStruct *X,
1145  long unsigned int *list_1_,
1146  long unsigned int *list_2_1_,
1147  long unsigned int *list_2_2_,
1148  long unsigned int *list_jb_
1149  )
1150 {
1151  long unsigned int i,j;
1152  long unsigned int ia,ja,jb;
1153  long unsigned int div_down, div_up;
1154  long unsigned int num_up,num_down;
1155  long unsigned int tmp_num_up,tmp_num_down;
1156  int icheck_loc;
1157 
1158  jb = list_jb_[ib];
1159  i = ib*ihfbit;
1160 
1161  num_up = 0;
1162  num_down = 0;
1163  icheck_loc=1;
1164  for(j=X->Def.Nsite/2; j< X->Def.Nsite ;j++){
1165  div_up = i & X->Def.Tpow[2*j];
1166  div_up = div_up/X->Def.Tpow[2*j];
1167  div_down = i & X->Def.Tpow[2*j+1];
1168  div_down = div_down/X->Def.Tpow[2*j+1];
1169 
1170  if(X->Def.LocSpn[j] == ITINERANT){
1171  num_up += div_up;
1172  num_down += div_down;
1173  }else{
1174  num_up += div_up;
1175  num_down += div_down;
1176  if(X->Def.Nsite%2==1 && j==(X->Def.Nsite/2)){
1177  icheck_loc= icheck_loc;
1178  }
1179  else{
1180  icheck_loc = icheck_loc*(div_up^div_down);// exclude doubly occupied site
1181  }
1182  }
1183  }
1184 //[s] get ja
1185  ja = 1;
1186  tmp_num_up = num_up;
1187  tmp_num_down = num_down;
1188  if(icheck_loc ==1){
1189  //for(ia=0;ia<X->Check.sdim;ia++){
1190  ia = X->Def.Tpow[X->Def.Nup+X->Def.Ndown-tmp_num_up-tmp_num_down]-1;
1191  //ia = 1;
1192  //if(ia < X->Check.sdim && ia!=0){
1193  //ia = snoob(ia);
1194  while(ia < X->Check.sdim && ia!=0){
1195  // for(ia=0;ia<X->Check.sdim;ia++){
1196  //[s] proceed ja
1197  i = ia;
1198  num_up = tmp_num_up;
1199  num_down = tmp_num_down;
1200  icheck_loc=1;
1201  for(j=0;j<(X->Def.Nsite+1)/2;j++){
1202  div_up = i & X->Def.Tpow[2*j];
1203  div_up = div_up/X->Def.Tpow[2*j];
1204  div_down = i & X->Def.Tpow[2*j+1];
1205  div_down = div_down/X->Def.Tpow[2*j+1];
1206 
1207  if(X->Def.LocSpn[j] == ITINERANT){
1208  num_up += div_up;
1209  num_down += div_down;
1210  }else{
1211  num_up += div_up;
1212  num_down += div_down;
1213  if(X->Def.Nsite%2==1 && j==(X->Def.Nsite/2)){
1214  icheck_loc= icheck_loc;
1215  }
1216  else{
1217  icheck_loc = icheck_loc*(div_up^div_down);// exclude doubllly ocupited site
1218  }
1219  }
1220  }
1221 
1222  if(icheck_loc == 1 && X->Def.LocSpn[X->Def.Nsite/2] != ITINERANT && X->Def.Nsite%2==1){
1223  div_up = ia & X->Def.Tpow[X->Def.Nsite-1];
1224  div_up = div_up/X->Def.Tpow[X->Def.Nsite-1];
1225  div_down = (ib*ihfbit) & X->Def.Tpow[X->Def.Nsite];
1226  div_down = div_down/X->Def.Tpow[X->Def.Nsite];
1227  icheck_loc= icheck_loc*(div_up^div_down);
1228  }
1229 
1230  if(num_up == X->Def.Nup && num_down == X->Def.Ndown && icheck_loc==1){
1231  //printf("ia=%ud ja=%ud \n",ia,ja);
1232  list_1_[ja+jb]=ia+ib*ihfbit;
1233  list_2_1_[ia]=ja+1;
1234  list_2_2_[ib]=jb+1;
1235  ja+=1;
1236  }
1237  ia = snoob(ia);
1238  //[e] proceed ja
1239  //ia+=1;
1240  //}
1241  }
1242  }
1243 //[e] get ja
1244  ja=ja-1;
1245  return ja;
1246 }
1247 
1248 
1262  long unsigned int ib,
1263  long unsigned int ihfbit,
1264  struct BindStruct *X,
1265  long unsigned int *list_1_,
1266  long unsigned int *list_2_1_,
1267  long unsigned int *list_2_2_,
1268  long unsigned int *list_jb_
1269  )
1270 {
1271  long unsigned int i,j;
1272  long unsigned int ia,ja,jb;
1273  long unsigned int div_down, div_up;
1274  int icheck_loc;
1275 
1276  jb = list_jb_[ib];
1277  i = ib*ihfbit;
1278  icheck_loc=1;
1279  for(j=X->Def.Nsite/2; j< X->Def.Nsite ;j++){
1280  div_up = i & X->Def.Tpow[2*j];
1281  div_up = div_up/X->Def.Tpow[2*j];
1282  div_down = i & X->Def.Tpow[2*j+1];
1283  div_down = div_down/X->Def.Tpow[2*j+1];
1284  if(X->Def.LocSpn[j] != ITINERANT){
1285  if(X->Def.Nsite%2==1 && j==(X->Def.Nsite/2)){
1286  icheck_loc= icheck_loc;
1287  }
1288  else{
1289  icheck_loc = icheck_loc*(div_up^div_down);// exclude doubllly ocupited site
1290  }
1291  }
1292  }
1293 
1294  ja=1;
1295  if(icheck_loc ==1){
1296  for(ia=0;ia<X->Check.sdim;ia++){
1297  i=ia;
1298  icheck_loc =1;
1299  for(j=0;j<(X->Def.Nsite+1)/2;j++){
1300  div_up = i & X->Def.Tpow[2*j];
1301  div_up = div_up/X->Def.Tpow[2*j];
1302  div_down = i & X->Def.Tpow[2*j+1];
1303  div_down = div_down/X->Def.Tpow[2*j+1];
1304  if(X->Def.LocSpn[j] != ITINERANT){
1305  if(X->Def.Nsite%2==1 && j==(X->Def.Nsite/2)){
1306  icheck_loc= icheck_loc;
1307  }
1308  else{
1309  icheck_loc = icheck_loc*(div_up^div_down);// exclude doubllly ocupited site
1310  }
1311  }
1312  }
1313 
1314  if(icheck_loc == 1 && X->Def.LocSpn[X->Def.Nsite/2] != ITINERANT && X->Def.Nsite%2==1){
1315  div_up = ia & X->Def.Tpow[X->Def.Nsite-1];
1316  div_up = div_up/X->Def.Tpow[X->Def.Nsite-1];
1317  div_down = (ib*ihfbit) & X->Def.Tpow[X->Def.Nsite];
1318  div_down = div_down/X->Def.Tpow[X->Def.Nsite];
1319  icheck_loc= icheck_loc*(div_up^div_down);
1320  }
1321 
1322  if(icheck_loc==1){
1323  list_1_[ja+jb]=ia+ib*ihfbit;
1324  list_2_1_[ia]=ja+1;
1325  list_2_2_[ib]=jb+1;
1326  ja+=1;
1327  }
1328  }
1329  }
1330  ja=ja-1;
1331 
1332  return ja;
1333 }
1334 
1351  long unsigned int ib,
1352  long unsigned int ihfbit,
1353  unsigned int N,
1354  struct BindStruct *X,
1355  long unsigned int *list_1_,
1356  long unsigned int *list_2_1_,
1357  long unsigned int *list_2_2_,
1358  long unsigned int *list_jb_
1359  )
1360 {
1361  long unsigned int i,j,div;
1362  long unsigned int ia,ja,jb;
1363  long unsigned int num_up;
1364  unsigned int tmp_num_up;
1365 
1366  jb = list_jb_[ib];
1367  i = ib*ihfbit;
1368  num_up=0;
1369  for(j=0;j<N;j++){
1370  div=i & X->Def.Tpow[j];
1371  div=div/X->Def.Tpow[j];
1372  num_up+=div;
1373  }
1374  ja=1;
1375  tmp_num_up = num_up;
1376 
1377  for(ia=0;ia<ihfbit;ia++){
1378  i=ia;
1379  num_up = tmp_num_up;
1380  for(j=0;j<N;j++){
1381  div=i & X->Def.Tpow[j];
1382  div=div/X->Def.Tpow[j];
1383  num_up+=div;
1384  }
1385 
1386  if(num_up == X->Def.Ne){
1387  list_1_[ja+jb]=ia+ib*ihfbit;
1388  list_2_1_[ia]=ja+1;
1389  list_2_2_[ib]=jb+1;
1390  ja+=1;
1391  }
1392  }
1393  ja=ja-1;
1394  return ja;
1395 }
1396 
1397 
1415  long unsigned int ib,
1416  long unsigned int ihfbit,
1417  unsigned int N,
1418  struct BindStruct *X,
1419  long unsigned int *list_1_,
1420  long unsigned int *list_2_1_,
1421  long unsigned int *list_2_2_,
1422  long unsigned int *list_jb_
1423  )
1424 {
1425  long unsigned int i,j,div;
1426  long unsigned int ia,ja,jb;
1427  long unsigned int num_up;
1428  unsigned int tmp_num_up;
1429 
1430  jb = list_jb_[ib];
1431  i = ib*ihfbit;
1432  num_up=0;
1433  for(j=0;j<N;j++){
1434  div=i & X->Def.Tpow[j];
1435  div=div/X->Def.Tpow[j];
1436  num_up+=div;
1437  }
1438  ja=1;
1439  tmp_num_up = num_up;
1440 
1441  // using hacker's delight
1442  if(tmp_num_up<=X->Def.Ne && (X->Def.Ne-tmp_num_up)<= X->Def.Nsite-1){ // do not exceed Ne
1443  ia = X->Def.Tpow[X->Def.Ne-tmp_num_up]-1;
1444  if(ia<ihfbit ){ // do not exceed Ne
1445  list_1_[ja+jb] = ia+ib*ihfbit;
1446  list_2_1_[ia] = ja+1;
1447  list_2_2_[ib] = jb+1;
1448  ja += 1;
1449 
1450  if(ia!=0){
1451  ia = snoob(ia);
1452  while(ia < ihfbit){
1453  //fprintf(stdoutMPI, " X: ia= %ld ia=%ld \n", ia,ia);
1454  list_1_[ja+jb] = ia+ib*ihfbit;
1455  list_2_1_[ia] = ja+1;
1456  list_2_2_[ib] = jb+1;
1457  ja+=1;
1458  ia = snoob(ia);
1459  }
1460  }
1461  }
1462  }
1463  ja=ja-1;
1464  return ja;
1465 }
1466 
1484  long unsigned int ib,
1485  long unsigned int ihfbit,
1486  struct BindStruct *X,
1487  long unsigned int *list_1_,
1488  long unsigned int *list_2_1_,
1489  long unsigned int *list_2_2_,
1490  long int *list_2_1_Sz_,
1491  long int *list_2_2_Sz_,
1492  long unsigned int *list_jb_
1493  )
1494 {
1495  long unsigned int ia,ja,jb;
1496  int list_2_2_Sz_ib=0;
1497  int tmp_2Sz=0;
1498  jb = list_jb_[ib];
1499  list_2_2_Sz_ib =list_2_2_Sz_[ib];
1500  ja=1;
1501  for(ia=0;ia<ihfbit;ia++){
1502  tmp_2Sz=list_2_1_Sz_[ia]+list_2_2_Sz_ib;
1503  if(tmp_2Sz == X->Def.Total2Sz){
1504  list_1_[ja+jb]=ia+ib*ihfbit;
1505  list_2_1_[ia]=ja+1;
1506  list_2_2_[ib]=jb+1;
1507  ja+=1;
1508  }
1509  }
1510  ja=ja-1;
1511  return ja;
1512 }
1513 
1527 int Read_sz
1529  struct BindStruct *X,
1530  const long unsigned int irght,
1531  const long unsigned int ilft,
1532  const long unsigned int ihfbit,
1533  long unsigned int *i_max
1534  )
1535 {
1536  FILE *fp,*fp_err;
1537  char sdt[D_FileNameMax];
1538  char buf[D_FileNameMax];
1539 
1540  long unsigned int icnt=0;
1541  long unsigned int ia,ib;
1542  long unsigned int ja=0;
1543  long unsigned int jb=0;
1544  long unsigned int ibpatn=0;
1545  long unsigned int dam;
1546 
1549 
1550  switch(X->Def.iCalcModel){
1551  case Hubbard:
1552  case HubbardGC:
1553  case Spin:
1554  case SpinGC:
1555  sprintf(sdt,cFileNameListModel, X->Def.Nsite, X->Def.Nup, X->Def.Ndown);
1556  break;
1557  case Kondo:
1558  sprintf(sdt,"ListForKondo_Ns%d_Ncond%d.dat",X->Def.Nsite,X->Def.Ne);
1559  break;
1560  }
1561  if(childfopenMPI(sdt,"r", &fp)!=0){
1562  exitMPI(-1);
1563  }
1564 
1565  if(fp == NULL){
1566  if(childfopenMPI(cFileNameErrorSz,"a",&fp_err)!=0){
1567  exitMPI(-1);
1568  }
1569  fprintf(fp_err, "%s", cErrSz_NoFile);
1570  fprintf(stderr, "%s", cErrSz_NoFile);
1571  fprintf(fp_err, cErrSz_NoFile_Show,sdt);
1572  fprintf(stderr, cErrSz_NoFile_Show, sdt);
1573  fclose(fp_err);
1574  }else{
1575  while(NULL != fgetsMPI(buf,sizeof(buf),fp)){
1576  dam=atol(buf);
1577  list_1[icnt]=dam;
1578 
1579  ia= dam & irght;
1580  ib= dam & ilft;
1581  ib=ib/ihfbit;
1582 
1583  if(ib==ibpatn){
1584  ja=ja+1;
1585  }else{
1586  ibpatn=ib;
1587  ja=1;
1588  jb=icnt-1;
1589  }
1590 
1591  list_2_1[ia]=ja;
1592  list_2_2[ib]=jb;
1593  icnt+=1;
1594 
1595  }
1596  fclose(fp);
1597  *i_max=icnt-1;
1598  }
1599 
1602 
1603  return 0;
1604 }
char * cErrSz_NoFile
Definition: ErrorMessage.c:115
void exitMPI(int errorcode)
MPI Abortation wrapper.
Definition: wrapperMPI.c:86
struct DefineList Def
Definision of system (Hamiltonian) etc.
Definition: struct.h:410
const char * cProStartCalcSz
const char * cOMPSzFinish
Definition: LogMessage.c:38
unsigned int NLocSpn
Number of local spins.
Definition: struct.h:84
long unsigned int ihfbit
Used for Ogata-Lin ???
Definition: struct.h:345
unsigned long int idim_max
The dimension of the Hilbert space of this process.
Definition: struct.h:303
int child_omp_sz_spin(long unsigned int ib, long unsigned int ihfbit, unsigned int N, struct BindStruct *X, long unsigned int *list_1_, long unsigned int *list_2_1_, long unsigned int *list_2_2_, long unsigned int *list_jb_)
calculating restricted Hilbert space for spin-1/2 systems
Definition: sz.c:1350
int sz(struct BindStruct *X, long unsigned int *list_1_, long unsigned int *list_2_1_, long unsigned int *list_2_2_)
generating Hilbert space
Definition: sz.c:63
#define ITINERANT
Definition: global.h:31
char * cErrSz_ShowDim
Definition: ErrorMessage.c:117
int Total2Sz
Total in this process.
Definition: struct.h:69
int child_omp_sz_GeneralSpin(long unsigned int ib, long unsigned int ihfbit, struct BindStruct *X, long unsigned int *list_1_, long unsigned int *list_2_1_, long unsigned int *list_2_2_, long int *list_2_1_Sz_, long int *list_2_2_Sz_, long unsigned int *list_jb_)
calculating restricted Hilbert space for general spin systems (S>1/2)
Definition: sz.c:1483
#define D_FileNameMax
Definition: global.h:23
struct LargeList Large
Variables for Matrix-Vector product.
Definition: struct.h:412
int * LocSpn
[DefineList::NLocSpn] Flag (and size) of the local spin. malloc in setmem_def().
Definition: struct.h:82
int childfopenMPI(const char *_cPathChild, const char *_cmode, FILE **_fp)
Only the root process open file in output/ directory.
Definition: FileIO.c:27
unsigned int Nup
Number of spin-up electrons in this process.
Definition: struct.h:58
const char * cStateLocSpin
Definition: LogMessage.c:33
const char * cFileNameErrorSz
Definition: global.c:84
int child_omp_sz_KondoGC(long unsigned int ib, long unsigned int ihfbit, struct BindStruct *X, long unsigned int *list_1_, long unsigned int *list_2_1_, long unsigned int *list_2_2_, long unsigned int *list_jb_)
Definition: sz.c:1261
#define TRUE
Definition: global.h:26
int Read_sz(struct BindStruct *X, const long unsigned int irght, const long unsigned int ilft, const long unsigned int ihfbit, long unsigned int *i_max)
reading the list of the restricted Hilbert space
Definition: sz.c:1528
char * cErrSz_OutFile
Definition: ErrorMessage.c:118
unsigned long int sdim
Dimension for Ogata-Lin ???
Definition: struct.h:307
int GetLocal2Sz(const unsigned int isite, const long unsigned int org_bit, const long int *SiteToBit, const long unsigned int *Tpow)
get 2sz at a site for general spin
Definition: bitcalc.c:449
long int Binomial(int n, int k, long int **comb, int Nsite)
Definition: sz.c:767
int child_omp_sz_Kondo(long unsigned int ib, long unsigned int ihfbit, struct BindStruct *X, long unsigned int *list_1_, long unsigned int *list_2_1_, long unsigned int *list_2_2_, long unsigned int *list_jb_)
calculating restricted Hilbert space for Kondo systems
Definition: sz.c:1029
int child_omp_sz_hacker(long unsigned int ib, long unsigned int ihfbit, struct BindStruct *X, long unsigned int *list_1_, long unsigned int *list_2_1_, long unsigned int *list_2_2_, long unsigned int *list_jb_)
efficient version of calculating restricted Hilbert space for Hubbard systems using snoob details of ...
Definition: sz.c:912
const char * cFileNameListModel
Definition: global.c:48
unsigned int Ndown
Number of spin-down electrons in this process.
Definition: struct.h:59
Bind.
Definition: struct.h:409
unsigned int Nsite
Number of sites in the INTRA process region.
Definition: struct.h:56
const char * cStateNupNdown
Definition: LogMessage.c:34
int READ
It is ALWAYS 0 ???
Definition: struct.h:53
int read_hacker
Whether use an efficient method (=1) in sz.c or not (=0)
Definition: struct.h:52
long unsigned int * Tpow
[2 * DefineList::NsiteMPI] malloc in setmem_def().
Definition: struct.h:90
char * cErrSz
Error Message in sz.c.
Definition: ErrorMessage.c:114
int child_omp_sz_spin_hacker(long unsigned int ib, long unsigned int ihfbit, unsigned int N, struct BindStruct *X, long unsigned int *list_1_, long unsigned int *list_2_1_, long unsigned int *list_2_2_, long unsigned int *list_jb_)
efficient version of calculating restricted Hilbert space for spin-1/2 systems details of snoob is fo...
Definition: sz.c:1414
const char * cReadSzStart
Definition: LogMessage.c:39
long unsigned int ilft
Used for Ogata-Lin ???
Definition: struct.h:344
int GetSplitBitByModel(const int Nsite, const int iCalcModel, long unsigned int *irght, long unsigned int *ilft, long unsigned int *ihfbit)
function of splitting original bit into right and left spaces.
Definition: bitcalc.c:78
long unsigned int * list_2_1
Definition: global.h:49
const char * cOMPSzStart
Definition: LogMessage.c:36
int iFlgGeneralSpin
Flag for the general (Sz/=1/2) spin.
Definition: struct.h:86
#define FALSE
Definition: global.h:25
long unsigned int * list_1
Definition: global.h:47
const char * cFileNameSzTimeKeep
Definition: global.c:24
long int * SiteToBit
[DefineList::NsiteMPI] Similar to DefineList::Tpow. For general spin.
Definition: struct.h:94
const char * cFileNameTimeKeep
Definition: global.c:23
long unsigned int * list_2_2
Definition: global.h:50
unsigned int Ne
Number of electrons in this process.
Definition: struct.h:71
int child_omp_sz_Kondo_hacker(long unsigned int ib, long unsigned int ihfbit, struct BindStruct *X, long unsigned int *list_1_, long unsigned int *list_2_1_, long unsigned int *list_2_2_, long unsigned int *list_jb_)
calculating restricted Hilbert space for Kondo-GC systems
Definition: sz.c:1141
struct EDMainCalStruct X
Definition: struct.h:432
const char * cProEndCalcSz
long unsigned int irght
Used for Ogata-Lin ???
Definition: struct.h:343
const char * cReadSzEnd
Definition: LogMessage.c:40
int iCalcModel
Switch for model. 0:Hubbard, 1:Spin, 2:Kondo, 3:HubbardGC, 4:SpinGC, 5:KondoGC, 6:HubbardNConserved.
Definition: struct.h:198
char * cErrSz_NoFile_Show
Definition: ErrorMessage.c:116
int iFlgCalcSpec
Input parameter CalcSpec in teh CalcMod file.
Definition: struct.h:216
char * fgetsMPI(char *InputString, int maxcount, FILE *fp)
MPI file I/O (get a line, fgets) wrapper. Only the root node (myrank = 0) reads and broadcast string...
Definition: wrapperMPI.c:122
long int SizeOflistjb
Used for computing Sz.
Definition: struct.h:320
int child_omp_sz(long unsigned int ib, long unsigned int ihfbit, struct BindStruct *X, long unsigned int *list_1_, long unsigned int *list_2_1_, long unsigned int *list_2_2_, long unsigned int *list_jb_)
calculating restricted Hilbert space for Hubbard systems
Definition: sz.c:816
struct CheckList Check
Size of the Hilbert space.
Definition: struct.h:411
char * CDataFileHead
Read from Calcmod in readdef.h. Header of output file such as Green&#39;s function.
Definition: struct.h:42
const char * cOMPSzMid
Definition: LogMessage.c:37
const char * cInitalSz
Definition: LogMessage.c:35
unsigned long int snoob(unsigned long int x)
"finding the next higher number after a given number that has the same number of 1-bits" This method ...
Definition: bitcalc.c:474
int TimeKeeper(struct BindStruct *X, const char *cFileName, const char *cTimeKeeper_Message, const char *cWriteType)
Functions for writing a time log.
Definition: log.c:42
FILE * stdoutMPI
File pointer to the standard output defined in InitializeMPI()
Definition: global.h:165