HPhi++  3.1.0
sz.cpp File Reference

Generating Hilbert spaces. More...

#include <bitcalc.hpp>
#include "common/setmemory.hpp"
#include "FileIO.hpp"
#include "sz.hpp"
#include "wrapperMPI.hpp"
#include "xsetmem.hpp"
#include <iostream>

Go to the source code of this file.

Functions

int child_omp_sz_Kondo_hacker (long int ib, long int ihfbit, struct BindStruct *X, long int *list_1_, long int *list_2_1_, long int *list_2_2_, long int *list_jb_)
 calculating restricted Hilbert space for Kondo-GC systems More...
 
long int Binomial (int n, int k, long int **comb, int Nsite)
 
int child_omp_sz (long int ib, long int ihfbit, struct BindStruct *X, long int *list_1_, long int *list_2_1_, long int *list_2_2_, long int *list_jb_)
 calculating restricted Hilbert space for Hubbard systems More...
 
int child_omp_sz_hacker (long int ib, long int ihfbit, struct BindStruct *X, long int *list_1_, long int *list_2_1_, long int *list_2_2_, long int *list_jb_)
 efficient version of calculating restricted Hilbert space for Hubbard systems using snoob details of snoob is found in S.H. Warren, Hacker’s Delight, second ed., Addison-Wesley, ISBN: 0321842685, 2012. More...
 
int child_omp_sz_Kondo (long int ib, long int ihfbit, struct BindStruct *X, long int *list_1_, long int *list_2_1_, long int *list_2_2_, long int *list_jb_)
 calculating restricted Hilbert space for Kondo systems More...
 
int child_omp_sz_KondoGC (long int ib, long int ihfbit, struct BindStruct *X, long int *list_1_, long int *list_2_1_, long int *list_2_2_, long int *list_jb_)
 
int child_omp_sz_spin (long int ib, long int ihfbit, int N, struct BindStruct *X, long int *list_1_, long int *list_2_1_, long int *list_2_2_, long int *list_jb_)
 calculating restricted Hilbert space for spin-1/2 systems More...
 
int child_omp_sz_spin_hacker (long int ib, long int ihfbit, int N, struct BindStruct *X, long int *list_1_, long int *list_2_1_, long int *list_2_2_, long int *list_jb_)
 efficient version of calculating restricted Hilbert space for spin-1/2 systems details of snoob is found in S.H. Warren, Hacker’s Delight, second ed., Addison-Wesley, ISBN: 0321842685, 2012. More...
 
int child_omp_sz_GeneralSpin (long int ib, long int ihfbit, struct BindStruct *X, long int *list_1_, long int *list_2_1_, long int *list_2_2_, long int *list_2_1_Sz_, long int *list_2_2_Sz_, long int *list_jb_)
 calculating restricted Hilbert space for general spin systems (S>1/2) More...
 
int Read_sz (struct BindStruct *X, const long int irght, const long int ilft, const long int ihfbit, long int *i_max)
 reading the list of the restricted Hilbert space More...
 
int sz (struct BindStruct *X, long int *list_1_, long int *list_2_1_, long int *list_2_2_)
 generating Hilbert space More...
 

Detailed Description

Generating Hilbert spaces.

calculating binomial coefficients

Version
0.2
0.1
Author
Takahiro Misawa (The University of Tokyo)
Kazuyoshi Yoshimi (The University of Tokyo)
Parameters
[in]nn for \(_nC_k = \frac{n!}{(n-k)!k!}\)
[in]kk for \(_nC_k = \frac{n!}{(n-k)!k!}\)
[out]combbinomial coefficients \(_nC_k\)
[in]Nsite# of sites
Returns
Author
Takahiro Misawa (The University of Tokyo)
Kazuyoshi Yoshimi (The University of Tokyo)

Definition in file sz.cpp.

Function Documentation

◆ Binomial()

long int Binomial ( int  n,
int  k,
long int **  comb,
int  Nsite 
)

Definition at line 178 of file sz.cpp.

Referenced by check(), and sz().

178  {
179  // nCk, Nsite=max(n)
180  int tmp_i,tmp_j;
181 
182  if(n==0 && k==0){
183  return 1;
184  }
185  else if(n<0 || k<0 || n<k){
186  return 0;
187  }
188 
189  for(tmp_i=0;tmp_i<=Nsite;tmp_i++){
190  for(tmp_j=0;tmp_j<=Nsite;tmp_j++){
191  comb[tmp_i][tmp_j] = 0;
192  }
193  }
194 
195  comb[0][0] = 1;
196  comb[1][0] = 1;
197  comb[1][1] = 1;
198  for(tmp_i=2;tmp_i<=n;tmp_i++){
199  for(tmp_j=0;tmp_j<=tmp_i;tmp_j++){
200  if(tmp_j==0){
201  comb[tmp_i][tmp_j] = 1;
202  }else if(tmp_j==tmp_i){
203  comb[tmp_i][tmp_j] = 1;
204  }else{
205  comb[tmp_i][tmp_j] = comb[tmp_i-1][tmp_j-1]+comb[tmp_i-1][tmp_j];
206  }
207  }
208  }
209  return comb[n][k];
210 }

◆ child_omp_sz()

int child_omp_sz ( long int  ib,
long int  ihfbit,
struct BindStruct X,
long int *  list_1_,
long int *  list_2_1_,
long int *  list_2_2_,
long int *  list_jb_ 
)

calculating restricted Hilbert space for Hubbard systems

Parameters
[in]ibupper half bit of i
[in]ihfbit2^(Ns/2)
[in]X
[out]list_1_list_1_[icnt] = i : i is divided into ia and ib (i=ib*ihfbit+ia)
[out]list_2_1_list_2_1_[ib] = jb
[out]list_2_2_list_2_2_[ia] = ja : icnt=jb+ja
[in]list_jb_list_jb_[ib] = jb
Returns
Author
Takahiro Misawa (The University of Tokyo)
Kazuyoshi Yoshimi (The University of Tokyo)
Parameters
[in]ib
[in]ihfbit
[in]X
[out]list_1_
[out]list_2_1_
[out]list_2_2_
[in]list_jb_

Definition at line 227 of file sz.cpp.

References BindStruct::Check, BindStruct::Def, DefineList::iCalcModel, DefineList::Ndown, DefineList::Ne, DefineList::Nsite, DefineList::Nup, CheckList::sdim, and DefineList::Tpow.

Referenced by sz().

236 {
237  long int i,j;
238  long int ia,ja,jb;
239  long int div_down, div_up;
240  long int num_up,num_down;
241  long int tmp_num_up,tmp_num_down;
242 
243  jb = list_jb_[ib];
244  i = ib*ihfbit;
245 
246  num_up = 0;
247  num_down = 0;
248  for(j=0;j< X->Def.Nsite ;j++){
249  div_up = i & X->Def.Tpow[2*j];
250  div_up = div_up/X->Def.Tpow[2*j];
251  div_down = i & X->Def.Tpow[2*j+1];
252  div_down = div_down/X->Def.Tpow[2*j+1];
253  num_up += div_up;
254  num_down += div_down;
255  }
256 
257  ja=1;
258  tmp_num_up = num_up;
259  tmp_num_down = num_down;
260 
261  if(X->Def.iCalcModel==Hubbard){
262  for(ia=0;ia<X->Check.sdim;ia++){
263  i=ia;
264  num_up = tmp_num_up;
265  num_down = tmp_num_down;
266 
267  for(j=0;j<X->Def.Nsite;j++){
268  div_up = i & X->Def.Tpow[2*j];
269  div_up = div_up/X->Def.Tpow[2*j];
270  div_down = i & X->Def.Tpow[2*j+1];
271  div_down = div_down/X->Def.Tpow[2*j+1];
272  num_up += div_up;
273  num_down += div_down;
274  }
275  if(num_up == X->Def.Nup && num_down == X->Def.Ndown){
276  list_1_[ja+jb]=ia+ib*ihfbit;
277  list_2_1_[ia]=ja+1;
278  list_2_2_[ib]=jb+1;
279  ja+=1;
280  }
281  }
282  }
283  else if(X->Def.iCalcModel==HubbardNConserved){
284  for(ia=0;ia<X->Check.sdim;ia++){
285  i=ia;
286  num_up = tmp_num_up;
287  num_down = tmp_num_down;
288 
289  for(j=0;j<X->Def.Nsite;j++){
290  div_up = i & X->Def.Tpow[2*j];
291  div_up = div_up/X->Def.Tpow[2*j];
292  div_down = i & X->Def.Tpow[2*j+1];
293  div_down = div_down/X->Def.Tpow[2*j+1];
294  num_up += div_up;
295  num_down += div_down;
296  }
297  if( (num_up+num_down) == X->Def.Ne){
298  list_1_[ja+jb]=ia+ib*ihfbit;
299  list_2_1_[ia]=ja+1;
300  list_2_2_[ib]=jb+1;
301  ja+=1;
302  }
303  }
304  }
305  ja=ja-1;
306  return ja;
307 }
int Nup
Number of spin-up electrons in this process.
Definition: struct.hpp:58
struct DefineList Def
Definision of system (Hamiltonian) etc.
Definition: struct.hpp:395
int Nsite
Number of sites in the INTRA process region.
Definition: struct.hpp:56
int Ne
Number of electrons in this process.
Definition: struct.hpp:71
long int * Tpow
[2 * DefineList::NsiteMPI] malloc in setmem_def().
Definition: struct.hpp:90
int iCalcModel
Switch for model. 0:Hubbard, 1:Spin, 2:Kondo, 3:HubbardGC, 4:SpinGC, 5:KondoGC, 6:HubbardNConserved.
Definition: struct.hpp:200
int Ndown
Number of spin-down electrons in this process.
Definition: struct.hpp:59
struct CheckList Check
Size of the Hilbert space.
Definition: struct.hpp:396
long int sdim
Dimension for Ogata-Lin ???
Definition: struct.hpp:309

◆ child_omp_sz_GeneralSpin()

int child_omp_sz_GeneralSpin ( long int  ib,
long int  ihfbit,
struct BindStruct X,
long int *  list_1_,
long int *  list_2_1_,
long int *  list_2_2_,
long int *  list_2_1_Sz_,
long int *  list_2_2_Sz_,
long int *  list_jb_ 
)

calculating restricted Hilbert space for general spin systems (S>1/2)

Parameters
[in]ibupper half bit of i
[in]ihfbit2^(Ns/2)
[in]X
[out]list_1_list_1_[icnt] = i : i is divided into ia and ib (i=ib*ihfbit+ia)
[out]list_2_1_list_2_1_[ib] = jb
[out]list_2_2_list_2_2_[ia] = ja : icnt=jb+ja
[out]list_2_1_Sz_
[out]list_2_2_Sz_
[in]list_jb_list_jb_[ib] = jb
Returns
Author
Takahiro Misawa (The University of Tokyo)

Definition at line 772 of file sz.cpp.

References BindStruct::Def, Read_sz(), and DefineList::Total2Sz.

Referenced by sz().

783 {
784  long int ia,ja,jb;
785  int list_2_2_Sz_ib=0;
786  int tmp_2Sz=0;
787  jb = list_jb_[ib];
788  list_2_2_Sz_ib =list_2_2_Sz_[ib];
789  ja=1;
790  for(ia=0;ia<ihfbit;ia++){
791  tmp_2Sz=list_2_1_Sz_[ia]+list_2_2_Sz_ib;
792  if(tmp_2Sz == X->Def.Total2Sz){
793  list_1_[ja+jb]=ia+ib*ihfbit;
794  list_2_1_[ia]=ja+1;
795  list_2_2_[ib]=jb+1;
796  ja+=1;
797  }
798  }
799  ja=ja-1;
800  return ja;
801 }
struct DefineList Def
Definision of system (Hamiltonian) etc.
Definition: struct.hpp:395
int Total2Sz
Total in this process.
Definition: struct.hpp:69

◆ child_omp_sz_hacker()

int child_omp_sz_hacker ( long int  ib,
long int  ihfbit,
struct BindStruct X,
long int *  list_1_,
long int *  list_2_1_,
long int *  list_2_2_,
long int *  list_jb_ 
)

efficient version of calculating restricted Hilbert space for Hubbard systems using snoob details of snoob is found in S.H. Warren, Hacker’s Delight, second ed., Addison-Wesley, ISBN: 0321842685, 2012.

Parameters
[in]ibupper half bit of i
[in]ihfbit2^(Ns/2)
[in]X
[out]list_1_list_1_[icnt] = i : i is divided into ia and ib (i=ib*ihfbit+ia)
[out]list_2_1_list_2_1_[ib] = jb
[out]list_2_2_list_2_2_[ia] = ja : icnt=jb+ja
[in]list_jb_list_jb_[ib] = jb
Returns
Author
Takahiro Misawa (The University of Tokyo)

Definition at line 323 of file sz.cpp.

References BindStruct::Check, BindStruct::Def, DefineList::iCalcModel, DefineList::Ndown, DefineList::Ne, DefineList::Nsite, DefineList::Nup, CheckList::sdim, snoob(), and DefineList::Tpow.

Referenced by sz().

331 {
332  long int j;
333  unsigned long int i;
334  unsigned long int ia, ja, jb;
335  unsigned long int div_down, div_up;
336  unsigned long int num_up, num_down;
337  unsigned long int tmp_num_up, tmp_num_down;
338 
339  jb = list_jb_[ib];
340  i = ib * ihfbit;
341 
342  num_up = 0;
343  num_down = 0;
344  for (j = 0; j < X->Def.Nsite; j++) {
345  div_up = i & X->Def.Tpow[2 * j];
346  div_up = div_up / X->Def.Tpow[2 * j];
347  div_down = i & X->Def.Tpow[2 * j + 1];
348  div_down = div_down / X->Def.Tpow[2 * j + 1];
349  num_up += div_up;
350  num_down += div_down;
351  }
352 
353  ja = 1;
354  tmp_num_up = num_up;
355  tmp_num_down = num_down;
356 
357  if (X->Def.iCalcModel == Hubbard) {
358  if (tmp_num_up <= (unsigned long)X->Def.Nup
359  && tmp_num_down <= (unsigned long)X->Def.Ndown) { //do not exceed Nup and Ndown
360  ia = X->Def.Tpow[X->Def.Nup + X->Def.Ndown - tmp_num_up - tmp_num_down] - 1;
361  if (ia < (unsigned long)X->Check.sdim) {
362  num_up = tmp_num_up;
363  num_down = tmp_num_down;
364  for (j = 0; j < X->Def.Nsite; j++) {
365  div_up = ia & X->Def.Tpow[2 * j];
366  div_up = div_up / X->Def.Tpow[2 * j];
367  div_down = ia & X->Def.Tpow[2 * j + 1];
368  div_down = div_down / X->Def.Tpow[2 * j + 1];
369  num_up += div_up;
370  num_down += div_down;
371  }
372  if (num_up == (unsigned long)X->Def.Nup && num_down == (unsigned long)X->Def.Ndown) {
373  list_1_[ja + jb] = ia + ib * ihfbit;
374  list_2_1_[ia] = ja + 1;
375  list_2_2_[ib] = jb + 1;
376  ja += 1;
377  }
378  if (ia != 0) {
379  ia = snoob(ia);
380  while (ia < (unsigned long)X->Check.sdim) {
381  num_up = tmp_num_up;
382  num_down = tmp_num_down;
383  for (j = 0; j < X->Def.Nsite; j++) {
384  div_up = ia & X->Def.Tpow[2 * j];
385  div_up = div_up / X->Def.Tpow[2 * j];
386  div_down = ia & X->Def.Tpow[2 * j + 1];
387  div_down = div_down / X->Def.Tpow[2 * j + 1];
388  num_up += div_up;
389  num_down += div_down;
390  }
391  if (num_up == (unsigned long)X->Def.Nup && num_down == (unsigned long)X->Def.Ndown) {
392  list_1_[ja + jb] = ia + ib * ihfbit;
393  list_2_1_[ia] = ja + 1;
394  list_2_2_[ib] = jb + 1;
395  ja += 1;
396  }
397  ia = snoob(ia);
398  }
399  }
400  }
401  }
402  }
403  else if (X->Def.iCalcModel == HubbardNConserved) {
404  if (tmp_num_up + tmp_num_down <= (unsigned long)X->Def.Ne) { //do not exceed Ne
405  ia = X->Def.Tpow[X->Def.Ne - tmp_num_up - tmp_num_down] - 1;
406  if (ia < (unsigned long)X->Check.sdim) {
407  list_1_[ja + jb] = ia + ib * ihfbit;
408  list_2_1_[ia] = ja + 1;
409  list_2_2_[ib] = jb + 1;
410  ja += 1;
411  if (ia != 0) {
412  ia = snoob(ia);
413  while (ia < (unsigned long)X->Check.sdim) {
414  list_1_[ja + jb] = ia + ib * ihfbit;
415  list_2_1_[ia] = ja + 1;
416  list_2_2_[ib] = jb + 1;
417  ja += 1;
418  ia = snoob(ia);
419  }
420  }
421  }
422  }
423  }
424  ja = ja - 1;
425  return ja;
426 }
int Nup
Number of spin-up electrons in this process.
Definition: struct.hpp:58
struct DefineList Def
Definision of system (Hamiltonian) etc.
Definition: struct.hpp:395
int Nsite
Number of sites in the INTRA process region.
Definition: struct.hpp:56
int Ne
Number of electrons in this process.
Definition: struct.hpp:71
long int snoob(long int x)
"finding the next higher number after a given number that has the same number of 1-bits" This method ...
Definition: bitcalc.cpp:473
long int * Tpow
[2 * DefineList::NsiteMPI] malloc in setmem_def().
Definition: struct.hpp:90
int iCalcModel
Switch for model. 0:Hubbard, 1:Spin, 2:Kondo, 3:HubbardGC, 4:SpinGC, 5:KondoGC, 6:HubbardNConserved.
Definition: struct.hpp:200
int Ndown
Number of spin-down electrons in this process.
Definition: struct.hpp:59
struct CheckList Check
Size of the Hilbert space.
Definition: struct.hpp:396
long int sdim
Dimension for Ogata-Lin ???
Definition: struct.hpp:309

◆ child_omp_sz_Kondo()

int child_omp_sz_Kondo ( long int  ib,
long int  ihfbit,
struct BindStruct X,
long int *  list_1_,
long int *  list_2_1_,
long int *  list_2_2_,
long int *  list_jb_ 
)

calculating restricted Hilbert space for Kondo systems

Parameters
[in]ibupper half bit of i
[in]ihfbit2^(Ns/2)
[in]X
[out]list_1_list_1_[icnt] = i : i is divided into ia and ib (i=ib*ihfbit+ia)
[out]list_2_1_list_2_1_[ib] = jb
[out]list_2_2_list_2_2_[ia] = ja : icnt=jb+ja
[in]list_jb_list_jb_[ib] = jb
Returns
Author
Takahiro Misawa (The University of Tokyo)

Definition at line 441 of file sz.cpp.

References BindStruct::Check, BindStruct::Def, DefineList::LocSpn, DefineList::Ndown, DefineList::Nsite, DefineList::Nup, CheckList::sdim, and DefineList::Tpow.

Referenced by sz().

450 {
451  long int i,j;
452  long int ia,ja,jb;
453  long int div_down, div_up;
454  long int num_up,num_down;
455  long int tmp_num_up,tmp_num_down;
456  int icheck_loc;
457 
458  jb = list_jb_[ib];
459  i = ib*ihfbit;
460 
461  num_up = 0;
462  num_down = 0;
463  icheck_loc=1;
464  for(j=X->Def.Nsite/2; j< X->Def.Nsite ;j++){
465  div_up = i & X->Def.Tpow[2*j];
466  div_up = div_up/X->Def.Tpow[2*j];
467  div_down = i & X->Def.Tpow[2*j+1];
468  div_down = div_down/X->Def.Tpow[2*j+1];
469 
470  if(X->Def.LocSpn[j] == ITINERANT){
471  num_up += div_up;
472  num_down += div_down;
473  }else{
474  num_up += div_up;
475  num_down += div_down;
476  if(X->Def.Nsite%2==1 && j==(X->Def.Nsite/2)){
477  icheck_loc= icheck_loc;
478  }
479  else{
480  icheck_loc = icheck_loc*(div_up^div_down);// exclude doubllly ocupited site
481  }
482  }
483  }
484 
485  ja=1;
486  tmp_num_up = num_up;
487  tmp_num_down = num_down;
488  if(icheck_loc ==1){
489  for(ia=0;ia<X->Check.sdim;ia++){
490  i=ia;
491  num_up = tmp_num_up;
492  num_down = tmp_num_down;
493  icheck_loc=1;
494  for(j=0;j<(X->Def.Nsite+1)/2;j++){
495  div_up = i & X->Def.Tpow[2*j];
496  div_up = div_up/X->Def.Tpow[2*j];
497  div_down = i & X->Def.Tpow[2*j+1];
498  div_down = div_down/X->Def.Tpow[2*j+1];
499 
500  if(X->Def.LocSpn[j] == ITINERANT){
501  num_up += div_up;
502  num_down += div_down;
503  }else{
504  num_up += div_up;
505  num_down += div_down;
506  if(X->Def.Nsite%2==1 && j==(X->Def.Nsite/2)){
507  icheck_loc= icheck_loc;
508  }
509  else{
510  icheck_loc = icheck_loc*(div_up^div_down);// exclude doubllly ocupited site
511  }
512  }
513  }
514 
515  if(icheck_loc == 1 && X->Def.LocSpn[X->Def.Nsite/2] != ITINERANT && X->Def.Nsite%2==1){
516  div_up = ia & X->Def.Tpow[X->Def.Nsite-1];
517  div_up = div_up/X->Def.Tpow[X->Def.Nsite-1];
518  div_down = (ib*ihfbit) & X->Def.Tpow[X->Def.Nsite];
519  div_down = div_down/X->Def.Tpow[X->Def.Nsite];
520  icheck_loc= icheck_loc*(div_up^div_down);
521  }
522 
523  if(num_up == X->Def.Nup && num_down == X->Def.Ndown && icheck_loc==1){
524  list_1_[ja+jb]=ia+ib*ihfbit;
525  /*
526  list_2_1_[ia]=ja;
527  list_2_2_[ib]=jb;
528  */
529  list_2_1_[ia]=ja+1;
530  list_2_2_[ib]=jb+1;
531  //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]);
532  ja+=1;
533  }
534  }
535  }
536  ja=ja-1;
537  return ja;
538 }
int Nup
Number of spin-up electrons in this process.
Definition: struct.hpp:58
struct DefineList Def
Definision of system (Hamiltonian) etc.
Definition: struct.hpp:395
int Nsite
Number of sites in the INTRA process region.
Definition: struct.hpp:56
int * LocSpn
[DefineList::NLocSpn] Flag (and size) of the local spin. malloc in setmem_def().
Definition: struct.hpp:82
long int * Tpow
[2 * DefineList::NsiteMPI] malloc in setmem_def().
Definition: struct.hpp:90
int Ndown
Number of spin-down electrons in this process.
Definition: struct.hpp:59
struct CheckList Check
Size of the Hilbert space.
Definition: struct.hpp:396
long int sdim
Dimension for Ogata-Lin ???
Definition: struct.hpp:309

◆ child_omp_sz_Kondo_hacker()

int child_omp_sz_Kondo_hacker ( long int  ib,
long int  ihfbit,
struct BindStruct X,
long int *  list_1_,
long int *  list_2_1_,
long int *  list_2_2_,
long int *  list_jb_ 
)

calculating restricted Hilbert space for Kondo-GC systems

Parameters
[in]ibupper half bit of i
[in]ihfbit2^(Ns/2)
[in]X
[out]list_1_list_1_[icnt] = i : i is divided into ia and ib (i=ib*ihfbit+ia)
[out]list_2_1_list_2_1_[ib] = jb
[out]list_2_2_list_2_2_[ia] = ja : icnt=jb+ja
[in]list_jb_list_jb_[ib] = jb
Returns
Author
Takahiro Misawa (The University of Tokyo)

Definition at line 54 of file sz.cpp.

References BindStruct::Check, BindStruct::Def, DefineList::LocSpn, DefineList::Ndown, DefineList::Nsite, DefineList::Nup, CheckList::sdim, snoob(), and DefineList::Tpow.

Referenced by sz().

63 {
64  long int j;
65  unsigned long int i;
66  unsigned long int ia, ja, jb;
67  unsigned long int div_down, div_up;
68  unsigned long int num_up, num_down;
69  unsigned long int tmp_num_up, tmp_num_down;
70  unsigned int icheck_loc;
71 
72  jb = list_jb_[ib];
73  i = ib * ihfbit;
74 
75  num_up = 0;
76  num_down = 0;
77  icheck_loc = 1;
78  for (j = X->Def.Nsite / 2; j < X->Def.Nsite; j++) {
79  div_up = i & X->Def.Tpow[2 * j];
80  div_up = div_up / X->Def.Tpow[2 * j];
81  div_down = i & X->Def.Tpow[2 * j + 1];
82  div_down = div_down / X->Def.Tpow[2 * j + 1];
83 
84  if (X->Def.LocSpn[j] == ITINERANT) {
85  num_up += div_up;
86  num_down += div_down;
87  }
88  else {
89  num_up += div_up;
90  num_down += div_down;
91  if (X->Def.Nsite % 2 == 1 && j == (X->Def.Nsite / 2)) {
92  icheck_loc = icheck_loc;
93  }
94  else {
95  icheck_loc = icheck_loc * (div_up^div_down);// exclude doubly occupied site
96  }
97  }
98  }
99  //[s] get ja
100  ja = 1;
101  tmp_num_up = num_up;
102  tmp_num_down = num_down;
103  if (icheck_loc == 1) {
104  //for(ia=0;ia<X->Check.sdim;ia++){
105  ia = X->Def.Tpow[X->Def.Nup + X->Def.Ndown - tmp_num_up - tmp_num_down] - 1;
106  //ia = 1;
107  //if(ia < X->Check.sdim && ia!=0){
108  //ia = snoob(ia);
109  while (ia < (unsigned long)X->Check.sdim && ia != 0) {
110  // for(ia=0;ia<X->Check.sdim;ia++){
111  //[s] proceed ja
112  i = ia;
113  num_up = tmp_num_up;
114  num_down = tmp_num_down;
115  icheck_loc = 1;
116  for (j = 0; j < (X->Def.Nsite + 1) / 2; j++) {
117  div_up = i & X->Def.Tpow[2 * j];
118  div_up = div_up / X->Def.Tpow[2 * j];
119  div_down = i & X->Def.Tpow[2 * j + 1];
120  div_down = div_down / X->Def.Tpow[2 * j + 1];
121 
122  if (X->Def.LocSpn[j] == ITINERANT) {
123  num_up += div_up;
124  num_down += div_down;
125  }
126  else {
127  num_up += div_up;
128  num_down += div_down;
129  if (X->Def.Nsite % 2 == 1 && j == (X->Def.Nsite / 2)) {
130  icheck_loc = icheck_loc;
131  }
132  else {
133  icheck_loc = icheck_loc * (div_up^div_down);// exclude doubllly ocupited site
134  }
135  }
136  }
137 
138  if (icheck_loc == 1 && X->Def.LocSpn[X->Def.Nsite / 2] != ITINERANT && X->Def.Nsite % 2 == 1) {
139  div_up = ia & X->Def.Tpow[X->Def.Nsite - 1];
140  div_up = div_up / X->Def.Tpow[X->Def.Nsite - 1];
141  div_down = (ib*ihfbit) & X->Def.Tpow[X->Def.Nsite];
142  div_down = div_down / X->Def.Tpow[X->Def.Nsite];
143  icheck_loc = icheck_loc * (div_up^div_down);
144  }
145 
146  if (num_up == (unsigned long)X->Def.Nup
147  && num_down == (unsigned long)X->Def.Ndown && icheck_loc == 1) {
148  //printf("ia=%ud ja=%ud \n",ia,ja);
149  list_1_[ja + jb] = ia + ib * ihfbit;
150  list_2_1_[ia] = ja + 1;
151  list_2_2_[ib] = jb + 1;
152  ja += 1;
153  }
154  ia = snoob(ia);
155  //[e] proceed ja
156  //ia+=1;
157  //}
158  }
159  }
160  //[e] get ja
161  ja = ja - 1;
162  return ja;
163 }
int Nup
Number of spin-up electrons in this process.
Definition: struct.hpp:58
struct DefineList Def
Definision of system (Hamiltonian) etc.
Definition: struct.hpp:395
int Nsite
Number of sites in the INTRA process region.
Definition: struct.hpp:56
int * LocSpn
[DefineList::NLocSpn] Flag (and size) of the local spin. malloc in setmem_def().
Definition: struct.hpp:82
long int snoob(long int x)
"finding the next higher number after a given number that has the same number of 1-bits" This method ...
Definition: bitcalc.cpp:473
long int * Tpow
[2 * DefineList::NsiteMPI] malloc in setmem_def().
Definition: struct.hpp:90
int Ndown
Number of spin-down electrons in this process.
Definition: struct.hpp:59
struct CheckList Check
Size of the Hilbert space.
Definition: struct.hpp:396
long int sdim
Dimension for Ogata-Lin ???
Definition: struct.hpp:309

◆ child_omp_sz_KondoGC()

int child_omp_sz_KondoGC ( long int  ib,
long int  ihfbit,
struct BindStruct X,
long int *  list_1_,
long int *  list_2_1_,
long int *  list_2_2_,
long int *  list_jb_ 
)
Parameters
ib
ihfbit
N2
X
Returns
Author
Takahiro Misawa (The University of Tokyo)
Kazuyoshi Yoshimi (The University of Tokyo)
Parameters
[in]ib
[in]ihfbit
[in]X
[out]list_1_
[out]list_2_1_
[out]list_2_2_
[in]list_jb_

Definition at line 551 of file sz.cpp.

References BindStruct::Check, BindStruct::Def, DefineList::LocSpn, DefineList::Nsite, CheckList::sdim, and DefineList::Tpow.

Referenced by sz().

560 {
561  long int i,j;
562  long int ia,ja,jb;
563  long int div_down, div_up;
564  int icheck_loc;
565 
566  jb = list_jb_[ib];
567  i = ib*ihfbit;
568  icheck_loc=1;
569  for(j=X->Def.Nsite/2; j< X->Def.Nsite ;j++){
570  div_up = i & X->Def.Tpow[2*j];
571  div_up = div_up/X->Def.Tpow[2*j];
572  div_down = i & X->Def.Tpow[2*j+1];
573  div_down = div_down/X->Def.Tpow[2*j+1];
574  if(X->Def.LocSpn[j] != ITINERANT){
575  if(X->Def.Nsite%2==1 && j==(X->Def.Nsite/2)){
576  icheck_loc= icheck_loc;
577  }
578  else{
579  icheck_loc = icheck_loc*(div_up^div_down);// exclude doubllly ocupited site
580  }
581  }
582  }
583 
584  ja=1;
585  if(icheck_loc ==1){
586  for(ia=0;ia<X->Check.sdim;ia++){
587  i=ia;
588  icheck_loc =1;
589  for(j=0;j<(X->Def.Nsite+1)/2;j++){
590  div_up = i & X->Def.Tpow[2*j];
591  div_up = div_up/X->Def.Tpow[2*j];
592  div_down = i & X->Def.Tpow[2*j+1];
593  div_down = div_down/X->Def.Tpow[2*j+1];
594  if(X->Def.LocSpn[j] != ITINERANT){
595  if(X->Def.Nsite%2==1 && j==(X->Def.Nsite/2)){
596  icheck_loc= icheck_loc;
597  }
598  else{
599  icheck_loc = icheck_loc*(div_up^div_down);// exclude doubllly ocupited site
600  }
601  }
602  }
603 
604  if(icheck_loc == 1 && X->Def.LocSpn[X->Def.Nsite/2] != ITINERANT && X->Def.Nsite%2==1){
605  div_up = ia & X->Def.Tpow[X->Def.Nsite-1];
606  div_up = div_up/X->Def.Tpow[X->Def.Nsite-1];
607  div_down = (ib*ihfbit) & X->Def.Tpow[X->Def.Nsite];
608  div_down = div_down/X->Def.Tpow[X->Def.Nsite];
609  icheck_loc= icheck_loc*(div_up^div_down);
610  }
611 
612  if(icheck_loc==1){
613  list_1_[ja+jb]=ia+ib*ihfbit;
614  list_2_1_[ia]=ja+1;
615  list_2_2_[ib]=jb+1;
616  ja+=1;
617  }
618  }
619  }
620  ja=ja-1;
621 
622  return ja;
623 }
struct DefineList Def
Definision of system (Hamiltonian) etc.
Definition: struct.hpp:395
int Nsite
Number of sites in the INTRA process region.
Definition: struct.hpp:56
int * LocSpn
[DefineList::NLocSpn] Flag (and size) of the local spin. malloc in setmem_def().
Definition: struct.hpp:82
long int * Tpow
[2 * DefineList::NsiteMPI] malloc in setmem_def().
Definition: struct.hpp:90
struct CheckList Check
Size of the Hilbert space.
Definition: struct.hpp:396
long int sdim
Dimension for Ogata-Lin ???
Definition: struct.hpp:309

◆ child_omp_sz_spin()

int child_omp_sz_spin ( long int  ib,
long int  ihfbit,
int  N,
struct BindStruct X,
long int *  list_1_,
long int *  list_2_1_,
long int *  list_2_2_,
long int *  list_jb_ 
)

calculating restricted Hilbert space for spin-1/2 systems

Parameters
[in]ibupper half bit of i
[in]ihfbit2^(Ns/2)
[in]X
[in]N???
[out]list_1_list_1_[icnt] = i : i is divided into ia and ib (i=ib*ihfbit+ia)
[out]list_2_1_list_2_1_[ib] = jb
[out]list_2_2_list_2_2_[ia] = ja : icnt=jb+ja
[in]list_jb_list_jb_[ib] = jb
Returns
Author
Takahiro Misawa (The University of Tokyo)

Definition at line 640 of file sz.cpp.

References BindStruct::Def, DefineList::Ne, and DefineList::Tpow.

Referenced by sz().

650 {
651  long int i, j, div;
652  long int ia, ja, jb;
653  long int num_up;
654  int tmp_num_up;
655 
656  jb = list_jb_[ib];
657  i = ib * ihfbit;
658  num_up = 0;
659  for (j = 0; j < N; j++) {
660  div = i & X->Def.Tpow[j];
661  div = div / X->Def.Tpow[j];
662  num_up += div;
663  }
664  ja = 1;
665  tmp_num_up = num_up;
666 
667  for (ia = 0; ia < ihfbit; ia++) {
668  i = ia;
669  num_up = tmp_num_up;
670  for (j = 0; j < N; j++) {
671  div = i & X->Def.Tpow[j];
672  div = div / X->Def.Tpow[j];
673  num_up += div;
674  }
675 
676  if (num_up == X->Def.Ne) {
677  list_1_[ja + jb] = ia + ib * ihfbit;
678  list_2_1_[ia] = ja + 1;
679  list_2_2_[ib] = jb + 1;
680  ja += 1;
681  }
682  }
683  ja = ja - 1;
684  return ja;
685 }
struct DefineList Def
Definision of system (Hamiltonian) etc.
Definition: struct.hpp:395
int Ne
Number of electrons in this process.
Definition: struct.hpp:71
long int * Tpow
[2 * DefineList::NsiteMPI] malloc in setmem_def().
Definition: struct.hpp:90

◆ child_omp_sz_spin_hacker()

int child_omp_sz_spin_hacker ( long int  ib,
long int  ihfbit,
int  N,
struct BindStruct X,
long int *  list_1_,
long int *  list_2_1_,
long int *  list_2_2_,
long int *  list_jb_ 
)

efficient version of calculating restricted Hilbert space for spin-1/2 systems details of snoob is found in S.H. Warren, Hacker’s Delight, second ed., Addison-Wesley, ISBN: 0321842685, 2012.

Parameters
[in]ibupper half bit of i
[in]ihfbit2^(Ns/2)
[in]X
[in]N???
[out]list_1_list_1_[icnt] = i : i is divided into ia and ib (i=ib*ihfbit+ia)
[out]list_2_1_list_2_1_[ib] = jb
[out]list_2_2_list_2_2_[ia] = ja : icnt=jb+ja
[in]list_jb_list_jb_[ib] = jb
Returns
Author
Takahiro Misawa (The University of Tokyo)

Definition at line 702 of file sz.cpp.

References BindStruct::Def, DefineList::Ne, DefineList::Nsite, snoob(), and DefineList::Tpow.

Referenced by sz().

712 {
713  long int j;
714  unsigned long int i, div;
715  unsigned long int ia, ja, jb;
716  unsigned long int num_up;
717  unsigned int tmp_num_up;
718 
719  jb = list_jb_[ib];
720  i = ib * ihfbit;
721  num_up = 0;
722  for (j = 0; j < N; j++) {
723  div = i & X->Def.Tpow[j];
724  div = div / X->Def.Tpow[j];
725  num_up += div;
726  }
727  ja = 1;
728  tmp_num_up = num_up;
729 
730  // using hacker's delight
731  if (tmp_num_up <= (unsigned long)X->Def.Ne
732  && ((unsigned long)X->Def.Ne - tmp_num_up) <= (unsigned long)X->Def.Nsite - 1) { // do not exceed Ne
733  ia = X->Def.Tpow[X->Def.Ne - tmp_num_up] - 1;
734  if (ia < (unsigned long)ihfbit) { // do not exceed Ne
735  list_1_[ja + jb] = ia + ib * ihfbit;
736  list_2_1_[ia] = ja + 1;
737  list_2_2_[ib] = jb + 1;
738  ja += 1;
739 
740  if (ia != 0) {
741  ia = snoob(ia);
742  while (ia < (unsigned long)ihfbit) {
743  //fprintf(stdoutMPI, " X: ia= %ld ia=%ld \n", ia,ia);
744  list_1_[ja + jb] = ia + ib * ihfbit;
745  list_2_1_[ia] = ja + 1;
746  list_2_2_[ib] = jb + 1;
747  ja += 1;
748  ia = snoob(ia);
749  }
750  }
751  }
752  }
753  ja = ja - 1;
754  return ja;
755 }
struct DefineList Def
Definision of system (Hamiltonian) etc.
Definition: struct.hpp:395
int Nsite
Number of sites in the INTRA process region.
Definition: struct.hpp:56
int Ne
Number of electrons in this process.
Definition: struct.hpp:71
long int snoob(long int x)
"finding the next higher number after a given number that has the same number of 1-bits" This method ...
Definition: bitcalc.cpp:473
long int * Tpow
[2 * DefineList::NsiteMPI] malloc in setmem_def().
Definition: struct.hpp:90

◆ Read_sz()

int Read_sz ( struct BindStruct X,
const long int  irght,
const long int  ilft,
const long int  ihfbit,
long int *  i_max 
)

reading the list of the restricted Hilbert space

Parameters
[in]X
[in]irght
[in]ilft
[in]ihfbit
[in]i_max
Returns
Author
Takahiro Misawa (The University of Tokyo)
Kazuyoshi Yoshimi (The University of Tokyo)

Definition at line 817 of file sz.cpp.

References childfopenMPI(), BindStruct::Def, exitMPI(), fgetsMPI(), DefineList::iCalcModel, list_1, list_2_1, list_2_2, DefineList::Ndown, DefineList::Ne, DefineList::Nsite, DefineList::Nup, sz(), and TimeKeeper().

Referenced by child_omp_sz_GeneralSpin(), and sz().

824 {
825  FILE *fp,*fp_err;
826  char sdt[D_FileNameMax];
827  char buf[D_FileNameMax];
828 
829  long int icnt=0;
830  long int ia,ib;
831  long int ja=0;
832  long int jb=0;
833  long int ibpatn=0;
834  long int dam;
835 
836  TimeKeeper(X,"%s_sz_TimeKeeper.dat","READ = 1: read starts: %s", "a");
837  TimeKeeper(X,"%s_TimeKeeper.dat","READ = 1: read starts: %s", "a");
838 
839  switch(X->Def.iCalcModel){
840  case Hubbard:
841  case HubbardGC:
842  case Spin:
843  case SpinGC:
844  sprintf(sdt,"ListForModel_Ns%d_Nup%dNdown%d.dat", X->Def.Nsite, X->Def.Nup, X->Def.Ndown);
845  break;
846  case Kondo:
847  sprintf(sdt,"ListForKondo_Ns%d_Ncond%d.dat",X->Def.Nsite,X->Def.Ne);
848  break;
849  }
850  if(childfopenMPI(sdt,"r", &fp)!=0){
851  exitMPI(-1);
852  }
853 
854  if(fp == NULL){
855  if(childfopenMPI("Err_sz.dat","a",&fp_err)!=0){
856  exitMPI(-1);
857  }
858  fprintf(fp_err, "%s", "No file. Please set READ=0.\n");
859  fprintf(stderr, "%s", "No file. Please set READ=0.\n");
860  fprintf(fp_err, " %s does not exist. \n",sdt);
861  fprintf(stderr, " %s does not exist. \n", sdt);
862  fclose(fp_err);
863  }else{
864  while(NULL != fgetsMPI(buf,sizeof(buf),fp)){
865  dam=atol(buf);
866  list_1[icnt]=dam;
867 
868  ia= dam & irght;
869  ib= dam & ilft;
870  ib=ib/ihfbit;
871 
872  if(ib==ibpatn){
873  ja=ja+1;
874  }else{
875  ibpatn=ib;
876  ja=1;
877  jb=icnt-1;
878  }
879 
880  list_2_1[ia]=ja;
881  list_2_2[ib]=jb;
882  icnt+=1;
883 
884  }
885  fclose(fp);
886  *i_max=icnt-1;
887  }
888 
889  TimeKeeper(X, "%s_sz_TimeKeeper.dat", "READ = 1: read finishes: %s", "a");
890  TimeKeeper(X, "%s_TimeKeeper.dat", "READ = 1: read finishes: %s", "a");
891 
892  return 0;
893 }
void exitMPI(int errorcode)
MPI Abortation wrapper.
Definition: wrapperMPI.cpp:86
int Nup
Number of spin-up electrons in this process.
Definition: struct.hpp:58
struct DefineList Def
Definision of system (Hamiltonian) etc.
Definition: struct.hpp:395
long int * list_2_1
Definition: global.cpp:27
long int * list_2_2
Definition: global.cpp:28
int Nsite
Number of sites in the INTRA process region.
Definition: struct.hpp:56
int Ne
Number of electrons in this process.
Definition: struct.hpp:71
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.cpp:122
int TimeKeeper(struct BindStruct *X, const char *cFileName, const char *cTimeKeeper_Message, const char *cWriteType)
Functions for writing a time log.
Definition: log.cpp:42
int iCalcModel
Switch for model. 0:Hubbard, 1:Spin, 2:Kondo, 3:HubbardGC, 4:SpinGC, 5:KondoGC, 6:HubbardNConserved.
Definition: struct.hpp:200
int Ndown
Number of spin-down electrons in this process.
Definition: struct.hpp:59
long int * list_1
Definition: global.cpp:25
int childfopenMPI(const char *_cPathChild, const char *_cmode, FILE **_fp)
Only the root process open file in output/ directory.
Definition: FileIO.cpp:27

◆ sz()

int sz ( struct BindStruct X,
long int *  list_1_,
long int *  list_2_1_,
long int *  list_2_2_ 
)

generating Hilbert space

Parameters
[in,out]X
[out]list_1_list_1[icnt] = i (index of full Hilbert space) : icnt = index in the restricted Hilbert space
[out]list_2_1_icnt=list_2_1[]+list_2_2[]
[out]list_2_2_
Returns
Author
Takahiro Misawa (The University of Tokyo)
Kazuyoshi Yoshimi (The University of Tokyo)

Definition at line 908 of file sz.cpp.

References Binomial(), DefineList::CDataFileHead, BindStruct::Check, child_omp_sz(), child_omp_sz_GeneralSpin(), child_omp_sz_hacker(), child_omp_sz_Kondo(), child_omp_sz_Kondo_hacker(), child_omp_sz_KondoGC(), child_omp_sz_spin(), child_omp_sz_spin_hacker(), childfopenMPI(), BindStruct::Def, exitMPI(), GetLocal2Sz(), GetSplitBitByModel(), DefineList::iCalcModel, CheckList::idim_max, DefineList::iFlgCalcSpec, DefineList::iFlgGeneralSpin, LargeList::ihfbit, LargeList::ilft, LargeList::irght, BindStruct::Large, DefineList::LocSpn, DefineList::Ndown, DefineList::Ne, DefineList::NLocSpn, DefineList::Nsite, DefineList::Nup, DefineList::READ, DefineList::read_hacker, Read_sz(), CheckList::sdim, DefineList::SiteToBit, LargeList::SizeOflistjb, snoob(), stdoutMPI, TimeKeeper(), DefineList::Total2Sz, and DefineList::Tpow.

Referenced by main(), MakeExcitedList(), and Read_sz().

914 {
915  FILE *fp, *fp_err;
916  char sdt[D_FileNameMax], sdt_err[D_FileNameMax];
917  long int *HilbertNumToSz;
918  long int i, icnt;
919  long int ib, jb;
920 
921  long int j;
922  long int div;
923  long int num_up, num_down;
924  long int irght, ilft, ihfbit;
925 
926  //*[s] for omp parall
927  int all_up, all_down, tmp_res, num_threads;
928  long int tmp_1, tmp_2, tmp_3;
929  long int **comb;
930  //*[e] for omp parall
931 
932  // [s] for Kondo
933  int N_all_up, N_all_down;
934  int all_loc;
935  long int num_loc, div_down;
936  int num_loc_up;
937  int icheck_loc;
938  int ihfSpinDown = 0;
939  // [e] for Kondo
940 
941  long int i_max = 0;
942  double idim = 0.0;
943  long int div_up;
944 
945  // [s] for general spin
946  long int *list_2_1_Sz;
947  long int *list_2_2_Sz;
948  if (X->Def.iFlgGeneralSpin == TRUE) {
949  list_2_1_Sz = li_1d_allocate(X->Check.sdim + 2);
950  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);
951  for (j = 0; j < X->Check.sdim + 2; j++) {
952  list_2_1_Sz[j] = 0;
953  }
954  for (j = 0; j < (X->Def.Tpow[X->Def.Nsite - 1] * X->Def.SiteToBit[X->Def.Nsite - 1] / X->Check.sdim) + 2; j++) {
955  list_2_2_Sz[j] = 0;
956  }
957  }
958  // [e] for general spin
959 
960  long int *list_jb;
961  list_jb = li_1d_allocate(X->Large.SizeOflistjb);
962  for (i = 0; i < X->Large.SizeOflistjb; i++) {
963  list_jb[i] = 0;
964  }
965 
966  //hacker
967  int hacker;
968  long int tmp_i, tmp_j, tmp_pow, max_tmp_i;
969  long int ia, ja;
970  long int ibpatn = 0;
971  //hacker
972 
973  int iSpnup, iMinup, iAllup;
974  int N2 = 0;
975  int N = 0;
976  fprintf(stdoutMPI, "%s", " Start: Calculate HilbertNum for fixed Sz. \n");
977  TimeKeeper(X, "%s_sz_TimeKeeper.dat", "initial sz : %s", "w");
978  TimeKeeper(X, "%s_TimeKeeper.dat", "initial sz : %s", "a");
979 
980  if (X->Check.idim_max != 0) {
981  switch (X->Def.iCalcModel) {
982  case HubbardGC:
983  case HubbardNConserved:
984  case Hubbard:
985  N2 = 2 * X->Def.Nsite;
986  idim = pow(2.0, N2);
987  break;
988  case KondoGC:
989  case Kondo:
990  N2 = 2 * X->Def.Nsite;
991  N = X->Def.Nsite;
992  idim = pow(2.0, N2);
993  for (j = 0; j < N; j++) {
994  fprintf(stdoutMPI, " j = %ld loc %d \n", j, X->Def.LocSpn[j]);
995  }
996  break;
997  case SpinGC:
998  case Spin:
999  N = X->Def.Nsite;
1000  if (X->Def.iFlgGeneralSpin == FALSE) {
1001  idim = pow(2.0, N);
1002  }
1003  else {
1004  idim = 1;
1005  for (j = 0; j < N; j++) {
1006  idim *= X->Def.SiteToBit[j];
1007  }
1008  }
1009  break;
1010  }
1011  comb = li_2d_allocate(X->Def.Nsite + 1, X->Def.Nsite + 1);
1012  i_max = X->Check.idim_max;
1013 
1014  switch (X->Def.iCalcModel) {
1015  case HubbardNConserved:
1016  case Hubbard:
1017  case KondoGC:
1018  case Kondo:
1019  case Spin:
1020  if (X->Def.iFlgGeneralSpin == FALSE) {
1021  if (GetSplitBitByModel(X->Def.Nsite, X->Def.iCalcModel, &irght, &ilft, &ihfbit) != 0) {
1022  exitMPI(-1);
1023  }
1024  X->Large.irght = irght;
1025  X->Large.ilft = ilft;
1026  X->Large.ihfbit = ihfbit;
1027  //fprintf(stdoutMPI, "idim=%lf irght=%ld ilft=%ld ihfbit=%ld \n",idim,irght,ilft,ihfbit);
1028  }
1029  else {
1030  ihfbit = X->Check.sdim;
1031  //fprintf(stdoutMPI, "idim=%lf ihfbit=%ld \n",idim, ihfbit);
1032  }
1033  break;
1034  default:
1035  break;
1036  }
1037 
1038  icnt = 1;
1039  jb = 0;
1040 
1041  if (X->Def.READ == 1) {
1042  if (Read_sz(X, irght, ilft, ihfbit, &i_max) != 0) {
1043  exitMPI(-1);
1044  }
1045  }
1046  else {
1047  sprintf(sdt, "%s_sz_TimeKeeper.dat", X->Def.CDataFileHead);
1048 #ifdef _OPENMP
1049  num_threads = omp_get_max_threads();
1050 #else
1051  num_threads = 1;
1052 #endif
1053  childfopenMPI(sdt, "a", &fp);
1054  fprintf(fp, "num_threads==%d\n", num_threads);
1055  fclose(fp);
1056 
1057  //*[s] omp parallel
1058 
1059  TimeKeeper(X, "%s_sz_TimeKeeper.dat", "omp parallel sz starts: %s", "a");
1060  TimeKeeper(X, "%s_TimeKeeper.dat", "omp parallel sz starts: %s", "a");
1061  switch (X->Def.iCalcModel) {
1062  case HubbardGC:
1063  icnt = X->Def.Tpow[2 * X->Def.Nsite - 1] * 2 + 0;/*Tpow[2*X->Def.Nsit]=1*/
1064  break;
1065 
1066  case SpinGC:
1067  if (X->Def.iFlgGeneralSpin == FALSE) {
1068  icnt = X->Def.Tpow[X->Def.Nsite - 1] * 2 + 0;/*Tpow[X->Def.Nsit]=1*/
1069  }
1070  else {
1071  icnt = X->Def.Tpow[X->Def.Nsite - 1] * X->Def.SiteToBit[X->Def.Nsite - 1];
1072  }
1073  break;
1074 
1075  case KondoGC:
1076  // this part can not be parallelized
1077  jb = 0;
1078  num_loc = 0;
1079  for (j = X->Def.Nsite / 2; j < X->Def.Nsite; j++) { // counting # of localized spins
1080  if (X->Def.LocSpn[j] != ITINERANT) { // //ITINERANT ==0 -> itinerant
1081  num_loc += 1;
1082  }
1083  }
1084 
1085  for (ib = 0; ib < X->Check.sdim; ib++) {
1086  list_jb[ib] = jb;
1087  i = ib * ihfbit;
1088  icheck_loc = 1;
1089  for (j = (X->Def.Nsite + 1) / 2; j < X->Def.Nsite; j++) {
1090  div_up = i & X->Def.Tpow[2 * j];
1091  div_up = div_up / X->Def.Tpow[2 * j];
1092  div_down = i & X->Def.Tpow[2 * j + 1];
1093  div_down = div_down / X->Def.Tpow[2 * j + 1];
1094  if (X->Def.LocSpn[j] != ITINERANT) {
1095  if (X->Def.Nsite % 2 == 1 && j == (X->Def.Nsite / 2)) {
1096  icheck_loc = icheck_loc;
1097  }
1098  else {
1099  icheck_loc = icheck_loc * (div_up^div_down);// exclude doubllly ocupited site
1100  }
1101  }
1102  }
1103  if (icheck_loc == 1) {
1104  if (X->Def.Nsite % 2 == 1 && X->Def.LocSpn[X->Def.Nsite / 2] != ITINERANT) {
1105  jb += X->Def.Tpow[X->Def.Nsite - 1 - (X->Def.NLocSpn - num_loc)];
1106  }
1107  else {
1108  jb += X->Def.Tpow[X->Def.Nsite - (X->Def.NLocSpn - num_loc)];
1109  }
1110  }
1111  }
1112 
1113  icnt = 0;
1114 #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)
1115  for (ib = 0; ib < X->Check.sdim; ib++) {
1116  icnt += child_omp_sz_KondoGC(ib, ihfbit, X, list_1_, list_2_1_, list_2_2_, list_jb);
1117  }
1118  break;
1119 
1120  case Hubbard:
1121  hacker = X->Def.read_hacker;
1122  if (hacker == 0) {
1123  // this part can not be parallelized
1124  jb = 0;
1125  for (ib = 0; ib < X->Check.sdim; ib++) { // sdim = 2^(N/2)
1126  list_jb[ib] = jb;
1127  i = ib * ihfbit;
1128  //[s] counting # of up and down electrons
1129  num_up = 0;
1130  for (j = 0; j <= N2 - 2; j += 2) { // even -> up spin
1131  div = i & X->Def.Tpow[j];
1132  div = div / X->Def.Tpow[j];
1133  num_up += div;
1134  }
1135  num_down = 0;
1136  for (j = 1; j <= N2 - 1; j += 2) { // odd -> down spin
1137  div = i & X->Def.Tpow[j];
1138  div = div / X->Def.Tpow[j];
1139  num_down += div;
1140  }
1141  //[e] counting # of up and down electrons
1142  tmp_res = X->Def.Nsite % 2; // even Ns-> 0, odd Ns -> 1
1143  all_up = (X->Def.Nsite + tmp_res) / 2;
1144  all_down = (X->Def.Nsite - tmp_res) / 2;
1145 
1146  tmp_1 = Binomial(all_up, X->Def.Nup - num_up, comb, all_up);
1147  tmp_2 = Binomial(all_down, X->Def.Ndown - num_down, comb, all_down);
1148  jb += tmp_1 * tmp_2;
1149  }
1150 
1151  //#pragma omp barrier
1152  TimeKeeper(X, "%s_sz_TimeKeeper.dat", "mid omp parallel sz : %s", "a");
1153  TimeKeeper(X, "%s_TimeKeeper.dat", "mid omp parallel sz : %s", "a");
1154 
1155  icnt = 0;
1156  for (ib = 0; ib < X->Check.sdim; ib++) {
1157  icnt += child_omp_sz(ib, ihfbit, X, list_1_, list_2_1_, list_2_2_, list_jb);
1158  }
1159  break;
1160  }
1161  else if (hacker == 1) {
1162  // this part can not be parallelized
1163  jb = 0;
1164 
1165  for (ib = 0; ib < X->Check.sdim; ib++) {
1166  list_jb[ib] = jb;
1167 
1168  i = ib * ihfbit;
1169  num_up = 0;
1170  for (j = 0; j <= N2 - 2; j += 2) {
1171  div = i & X->Def.Tpow[j];
1172  div = div / X->Def.Tpow[j];
1173  num_up += div;
1174  }
1175  num_down = 0;
1176  for (j = 1; j <= N2 - 1; j += 2) {
1177  div = i & X->Def.Tpow[j];
1178  div = div / X->Def.Tpow[j];
1179  num_down += div;
1180  }
1181 
1182  tmp_res = X->Def.Nsite % 2; // even Ns-> 0, odd Ns -> 1
1183  all_up = (X->Def.Nsite + tmp_res) / 2;
1184  all_down = (X->Def.Nsite - tmp_res) / 2;
1185 
1186  tmp_1 = Binomial(all_up, X->Def.Nup - num_up, comb, all_up);
1187  tmp_2 = Binomial(all_down, X->Def.Ndown - num_down, comb, all_down);
1188  jb += tmp_1 * tmp_2;
1189  }
1190 
1191  //#pragma omp barrier
1192  TimeKeeper(X, "%s_sz_TimeKeeper.dat", "mid omp parallel sz : %s", "a");
1193  TimeKeeper(X, "%s_TimeKeeper.dat", "mid omp parallel sz : %s", "a");
1194 
1195  icnt = 0;
1196 #pragma omp parallel for default(none) reduction(+:icnt) private(ib) firstprivate(ihfbit, X) shared(list_1_, list_2_1_, list_2_2_, list_jb)
1197  for (ib = 0; ib < X->Check.sdim; ib++) {
1198  icnt += child_omp_sz_hacker(ib, ihfbit, X, list_1_, list_2_1_, list_2_2_, list_jb);
1199  }
1200  break;
1201  }
1202  else {
1203  fprintf(stderr, "Error: CalcHS in ModPara file must be 0 or 1 for Hubbard model.");
1204  return -1;
1205  }
1206 
1207  case HubbardNConserved:
1208  hacker = X->Def.read_hacker;
1209  if (hacker == 0) {
1210  // this part can not be parallelized
1211  jb = 0;
1212  iSpnup = 0;
1213  iMinup = 0;
1214  iAllup = X->Def.Ne;
1215  if (X->Def.Ne > X->Def.Nsite) {
1216  iMinup = X->Def.Ne - X->Def.Nsite;
1217  iAllup = X->Def.Nsite;
1218  }
1219  for (ib = 0; ib < X->Check.sdim; ib++) {
1220  list_jb[ib] = jb;
1221  i = ib * ihfbit;
1222  num_up = 0;
1223  for (j = 0; j <= N2 - 2; j += 2) {
1224  div = i & X->Def.Tpow[j];
1225  div = div / X->Def.Tpow[j];
1226  num_up += div;
1227  }
1228  num_down = 0;
1229  for (j = 1; j <= N2 - 1; j += 2) {
1230  div = i & X->Def.Tpow[j];
1231  div = div / X->Def.Tpow[j];
1232  num_down += div;
1233  }
1234  tmp_res = X->Def.Nsite % 2; // even Ns-> 0, odd Ns -> 1
1235  all_up = (X->Def.Nsite + tmp_res) / 2;
1236  all_down = (X->Def.Nsite - tmp_res) / 2;
1237 
1238  for (iSpnup = iMinup; iSpnup <= iAllup; iSpnup++) {
1239  tmp_1 = Binomial(all_up, iSpnup - num_up, comb, all_up);
1240  tmp_2 = Binomial(all_down, X->Def.Ne - iSpnup - num_down, comb, all_down);
1241  jb += tmp_1 * tmp_2;
1242  }
1243  }
1244  //#pragma omp barrier
1245  TimeKeeper(X, "%s_sz_TimeKeeper.dat", "mid omp parallel sz : %s", "a");
1246  TimeKeeper(X, "%s_TimeKeeper.dat", "mid omp parallel sz : %s", "a");
1247 
1248  icnt = 0;
1249 #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)
1250  for (ib = 0; ib < X->Check.sdim; ib++) {
1251  icnt += child_omp_sz(ib, ihfbit, X, list_1_, list_2_1_, list_2_2_, list_jb);
1252  }
1253  break;
1254  }
1255  else if (hacker == 1) {
1256  // this part can not be parallelized
1257  jb = 0;
1258  iSpnup = 0;
1259  iMinup = 0;
1260  iAllup = X->Def.Ne;
1261  if (X->Def.Ne > X->Def.Nsite) {
1262  iMinup = X->Def.Ne - X->Def.Nsite;
1263  iAllup = X->Def.Nsite;
1264  }
1265  for (ib = 0; ib < X->Check.sdim; ib++) {
1266  list_jb[ib] = jb;
1267  i = ib * ihfbit;
1268  num_up = 0;
1269  for (j = 0; j <= N2 - 2; j += 2) {
1270  div = i & X->Def.Tpow[j];
1271  div = div / X->Def.Tpow[j];
1272  num_up += div;
1273  }
1274  num_down = 0;
1275  for (j = 1; j <= N2 - 1; j += 2) {
1276  div = i & X->Def.Tpow[j];
1277  div = div / X->Def.Tpow[j];
1278  num_down += div;
1279  }
1280  tmp_res = X->Def.Nsite % 2; // even Ns-> 0, odd Ns -> 1
1281  all_up = (X->Def.Nsite + tmp_res) / 2;
1282  all_down = (X->Def.Nsite - tmp_res) / 2;
1283 
1284  for (iSpnup = iMinup; iSpnup <= iAllup; iSpnup++) {
1285  tmp_1 = Binomial(all_up, iSpnup - num_up, comb, all_up);
1286  tmp_2 = Binomial(all_down, X->Def.Ne - iSpnup - num_down, comb, all_down);
1287  jb += tmp_1 * tmp_2;
1288  }
1289  }
1290  //#pragma omp barrier
1291  TimeKeeper(X, "%s_sz_TimeKeeper.dat", "mid omp parallel sz : %s", "a");
1292  TimeKeeper(X, "%s_TimeKeeper.dat", "mid omp parallel sz : %s", "a");
1293 
1294  icnt = 0;
1295 #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)
1296  for (ib = 0; ib < X->Check.sdim; ib++) {
1297  icnt += child_omp_sz_hacker(ib, ihfbit, X, list_1_, list_2_1_, list_2_2_, list_jb);
1298  }
1299 
1300  break;
1301  }
1302  else {
1303  fprintf(stderr, "Error: CalcHS in ModPara file must be 0 or 1 for Hubbard model.");
1304  return -1;
1305  }
1306 
1307  case Kondo:
1308  // this part can not be parallelized
1309  N_all_up = X->Def.Nup;
1310  N_all_down = X->Def.Ndown;
1311  fprintf(stdoutMPI, " N_all_up = %d N_all_down = %d \n", N_all_up, N_all_down);
1312 
1313  jb = 0;
1314  num_loc = 0;
1315  for (j = X->Def.Nsite / 2; j < X->Def.Nsite; j++) {// counting localized # of spins
1316  if (X->Def.LocSpn[j] != ITINERANT) {
1317  num_loc += 1;
1318  }
1319  }
1320 
1321  for (ib = 0; ib < X->Check.sdim; ib++) { //sdim = 2^(N/2)
1322  list_jb[ib] = jb;
1323  i = ib * ihfbit; // ihfbit=pow(2,((Nsite+1)/2))
1324  num_up = 0;
1325  num_down = 0;
1326  icheck_loc = 1;
1327 
1328  for (j = X->Def.Nsite / 2; j < X->Def.Nsite; j++) {
1329  div_up = i & X->Def.Tpow[2 * j];
1330  div_up = div_up / X->Def.Tpow[2 * j];
1331  div_down = i & X->Def.Tpow[2 * j + 1];
1332  div_down = div_down / X->Def.Tpow[2 * j + 1];
1333  if (X->Def.LocSpn[j] == ITINERANT) {
1334  num_up += div_up;
1335  num_down += div_down;
1336  }
1337  else {
1338  num_up += div_up;
1339  num_down += div_down;
1340  if (X->Def.Nsite % 2 == 1 && j == (X->Def.Nsite / 2)) { // odd site
1341  icheck_loc = icheck_loc;
1342  ihfSpinDown = div_down;
1343  if (div_down == 0) {
1344  num_up += 1;
1345  }
1346  }
1347  else {
1348  icheck_loc = icheck_loc * (div_up^div_down);// exclude empty or doubly occupied site
1349  }
1350  }
1351  }
1352 
1353  if (icheck_loc == 1) { // itinerant of local spins without holon or doublon
1354  tmp_res = X->Def.Nsite % 2; // even Ns-> 0, odd Ns -> 1
1355  all_loc = X->Def.NLocSpn - num_loc; // # of local spins
1356  all_up = (X->Def.Nsite + tmp_res) / 2 - all_loc;
1357  all_down = (X->Def.Nsite - tmp_res) / 2 - all_loc;
1358  if (X->Def.Nsite % 2 == 1 && X->Def.LocSpn[X->Def.Nsite / 2] != ITINERANT) {
1359  all_up = (X->Def.Nsite) / 2 - all_loc;
1360  all_down = (X->Def.Nsite) / 2 - all_loc;
1361  }
1362 
1363  for (num_loc_up = 0; num_loc_up <= all_loc; num_loc_up++) {
1364  tmp_1 = Binomial(all_loc, num_loc_up, comb, all_loc);
1365  if (X->Def.Nsite % 2 == 1 && X->Def.LocSpn[X->Def.Nsite / 2] != ITINERANT) {
1366  if (ihfSpinDown != 0) {
1367  tmp_2 = Binomial(all_up, X->Def.Nup - num_up - num_loc_up, comb, all_up);
1368  tmp_3 = Binomial(all_down, X->Def.Ndown - num_down - (all_loc - num_loc_up), comb, all_down);
1369  }
1370  else {
1371  tmp_2 = Binomial(all_up, X->Def.Nup - num_up - num_loc_up, comb, all_up);
1372  tmp_3 = Binomial(all_down, X->Def.Ndown - num_down - (all_loc - num_loc_up), comb, all_down);
1373  }
1374  }
1375  else {
1376  tmp_2 = Binomial(all_up, X->Def.Nup - num_up - num_loc_up, comb, all_up);
1377  tmp_3 = Binomial(all_down, X->Def.Ndown - num_down - (all_loc - num_loc_up), comb, all_down);
1378  }
1379  jb += tmp_1 * tmp_2*tmp_3;
1380  }
1381  }
1382 
1383  }
1384  //#pragma omp barrier
1385  TimeKeeper(X, "%s_sz_TimeKeeper.dat", "mid omp parallel sz : %s", "a");
1386  TimeKeeper(X, "%s_TimeKeeper.dat", "mid omp parallel sz : %s", "a");
1387 
1388  hacker = X->Def.read_hacker;
1389  if (hacker == 0) {
1390  icnt = 0;
1391 #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)
1392  for (ib = 0; ib < X->Check.sdim; ib++) {
1393  icnt += child_omp_sz_Kondo(ib, ihfbit, X, list_1_, list_2_1_, list_2_2_, list_jb);
1394  }
1395  }
1396  else if (hacker == 1) {
1397  icnt = 0;
1398 #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)
1399  for (ib = 0; ib < X->Check.sdim; ib++) {
1400  icnt += child_omp_sz_Kondo_hacker(ib, ihfbit, X, list_1_, list_2_1_, list_2_2_, list_jb);
1401  }
1402  }
1403  break;
1404 
1405  case Spin:
1406  // this part can not be parallelized
1407  if (X->Def.iFlgGeneralSpin == FALSE) {
1408  hacker = X->Def.read_hacker;
1409  //printf(" rank=%d:Ne=%ld ihfbit=%ld sdim=%ld\n", myrank,X->Def.Ne,ihfbit,X->Check.sdim);
1410  // using hacker's delight only + no open mp
1411  if (hacker == -1) {
1412  icnt = 1;
1413  tmp_pow = 1;
1414  tmp_i = 0;
1415  jb = 0;
1416  ja = 0;
1417  while (tmp_pow < X->Def.Tpow[X->Def.Ne]) {
1418  tmp_i += tmp_pow;
1419  tmp_pow = tmp_pow * 2;
1420  }
1421  //printf("DEBUG: %ld %ld %ld %ld\n",tmp_i,X->Check.sdim,X->Def.Tpow[X->Def.Ne],X->Def.Nsite);
1422  if (X->Def.Nsite % 2 == 0) {
1423  max_tmp_i = X->Check.sdim*X->Check.sdim;
1424  }
1425  else {
1426  max_tmp_i = X->Check.sdim*X->Check.sdim * 2 - 1;
1427  }
1428  while (tmp_i < max_tmp_i) {
1429  list_1_[icnt] = tmp_i;
1430 
1431  ia = tmp_i & irght;
1432  ib = tmp_i & ilft;
1433  ib = ib / ihfbit;
1434  if (ib == ibpatn) {
1435  ja = ja + 1;
1436  }
1437  else {
1438  ibpatn = ib;
1439  ja = 1;
1440  jb = icnt - 1;
1441  }
1442 
1443  list_2_1_[ia] = ja + 1;
1444  list_2_2_[ib] = jb + 1;
1445  tmp_j = snoob(tmp_i);
1446  tmp_i = tmp_j;
1447  icnt += 1;
1448  }
1449  icnt = icnt - 1;
1450  // old version + hacker's delight
1451  }
1452  else if (hacker == 1) {
1453  jb = 0;
1454  for (ib = 0; ib < X->Check.sdim; ib++) {
1455  list_jb[ib] = jb;
1456  i = ib * ihfbit;
1457  num_up = 0;
1458  for (j = 0; j < N; j++) {
1459  div_up = i & X->Def.Tpow[j];
1460  div_up = div_up / X->Def.Tpow[j];
1461  num_up += div_up;
1462  }
1463  all_up = (X->Def.Nsite + 1) / 2;
1464  tmp_1 = Binomial(all_up, X->Def.Ne - num_up, comb, all_up);
1465  jb += tmp_1;
1466  }
1467  //#pragma omp barrier
1468  TimeKeeper(X, "%s_sz_TimeKeeper.dat", "mid omp parallel sz : %s", "a");
1469  TimeKeeper(X, "%s_TimeKeeper.dat", "mid omp parallel sz : %s", "a");
1470 
1471  icnt = 0;
1472 #pragma omp parallel for default(none) reduction(+:icnt) private(ib) firstprivate(ihfbit, N, X, list_1_, list_2_1_, list_2_2_, list_jb)
1473  for (ib = 0; ib < X->Check.sdim; ib++) {
1474  icnt += child_omp_sz_spin_hacker(ib, ihfbit, N, X, list_1_, list_2_1_, list_2_2_, list_jb);
1475  }
1476  //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);
1477  // old version
1478  }
1479  else if (hacker == 0) {
1480  jb = 0;
1481  for (ib = 0; ib < X->Check.sdim; ib++) {
1482  list_jb[ib] = jb;
1483  i = ib * ihfbit;
1484  num_up = 0;
1485  for (j = 0; j < N; j++) {
1486  div_up = i & X->Def.Tpow[j];
1487  div_up = div_up / X->Def.Tpow[j];
1488  num_up += div_up;
1489  }
1490  all_up = (X->Def.Nsite + 1) / 2;
1491  tmp_1 = Binomial(all_up, X->Def.Ne - num_up, comb, all_up);
1492  jb += tmp_1;
1493  }
1494  //#pragma omp barrier
1495  TimeKeeper(X, "%s_sz_TimeKeeper.dat", "mid omp parallel sz : %s", "a");
1496  TimeKeeper(X, "%s_TimeKeeper.dat", "mid omp parallel sz : %s", "a");
1497 
1498  icnt = 0;
1499 #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)
1500  for (ib = 0; ib < X->Check.sdim; ib++) {
1501  icnt += child_omp_sz_spin(ib, ihfbit, N, X, list_1_, list_2_1_, list_2_2_, list_jb);
1502  }
1503  }
1504  else {
1505  fprintf(stderr, "Error: CalcHS in ModPara file must be -1 or 0 or 1 for Spin model.");
1506  return -1;
1507  }
1508  }
1509  else {
1510  int Max2Sz = 0;
1511  int irghtsite = 1;
1512  long int itmpSize = 1;
1513  int i2Sz = 0;
1514  for (j = 0; j < X->Def.Nsite; j++) {
1515  itmpSize *= X->Def.SiteToBit[j];
1516  if (itmpSize == ihfbit) {
1517  break;
1518  }
1519  irghtsite++;
1520  }
1521  for (j = 0; j < X->Def.Nsite; j++) {
1522  Max2Sz += X->Def.LocSpn[j];
1523  }
1524 
1525  HilbertNumToSz = li_1d_allocate(2 * Max2Sz + 1);
1526  for (ib = 0; ib < 2 * Max2Sz + 1; ib++) {
1527  HilbertNumToSz[ib] = 0;
1528  }
1529 
1530  for (ib = 0; ib < ihfbit; ib++) {
1531  i2Sz = 0;
1532  for (j = 1; j <= irghtsite; j++) {
1533  i2Sz += GetLocal2Sz(j, ib, X->Def.SiteToBit, X->Def.Tpow);
1534  }
1535  list_2_1_Sz[ib] = i2Sz;
1536  HilbertNumToSz[i2Sz + Max2Sz]++;
1537  }
1538  jb = 0;
1539  long int ilftdim = (X->Def.Tpow[X->Def.Nsite - 1] * X->Def.SiteToBit[X->Def.Nsite - 1]) / ihfbit;
1540  for (ib = 0; ib < ilftdim; ib++) {
1541  list_jb[ib] = jb;
1542  i2Sz = 0;
1543  for (j = 1; j <= (N - irghtsite); j++) {
1544  i2Sz += GetLocal2Sz(j + irghtsite, ib*ihfbit, X->Def.SiteToBit, X->Def.Tpow);
1545  }
1546  list_2_2_Sz[ib] = i2Sz;
1547  if ((X->Def.Total2Sz - i2Sz + (int)Max2Sz) >= 0 && (X->Def.Total2Sz - i2Sz) <= (int)Max2Sz) {
1548  jb += HilbertNumToSz[X->Def.Total2Sz - i2Sz + Max2Sz];
1549  }
1550  }
1551 
1552  TimeKeeper(X, "%s_sz_TimeKeeper.dat", "mid omp parallel sz : %s", "a");
1553  TimeKeeper(X, "%s_TimeKeeper.dat", "mid omp parallel sz : %s", "a");
1554 
1555  icnt = 0;
1556 #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)
1557  for (ib = 0; ib < ilftdim; ib++) {
1558  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);
1559  }
1560 
1561  free_li_1d_allocate(HilbertNumToSz);
1562  }
1563 
1564  break;
1565  default:
1566  exitMPI(-1);
1567 
1568  }
1569  i_max = icnt;
1570  //fprintf(stdoutMPI, "Debug: Xicnt=%ld \n",icnt);
1571  TimeKeeper(X, "%s_sz_TimeKeeper.dat", "omp parallel sz finishes: %s", "a");
1572  TimeKeeper(X, "%s_TimeKeeper.dat", "omp parallel sz finishes: %s", "a");
1573 
1574  }
1575 
1576  if (X->Def.iFlgCalcSpec == CALCSPEC_NOT) {
1577  if (X->Def.iCalcModel == HubbardNConserved) {
1578  X->Def.iCalcModel = Hubbard;
1579  }
1580  }
1581 
1582  //Error message
1583  //i_max=i_max+1;
1584  if (i_max != X->Check.idim_max) {
1585  fprintf(stderr, "%s", "Error: in sz. \n");
1586  fprintf(stderr, "imax = %ld, Check.idim_max=%ld \n", i_max, X->Check.idim_max);
1587  strcpy(sdt_err, "Err_sz.dat");
1588  if (childfopenMPI(sdt_err, "a", &fp_err) != 0) {
1589  exitMPI(-1);
1590  }
1591  fprintf(fp_err, "%s", "Caution!! Error in sz !!!! idim_max is not correct \n");
1592  fclose(fp_err);
1593  exitMPI(-1);
1594  }
1595 
1596  free_li_2d_allocate(comb);
1597  }
1598  fprintf(stdoutMPI, "%s", " End : Calculate HilbertNum for fixed Sz. \n\n");
1599 
1600  free(list_jb);
1601  if (X->Def.iFlgGeneralSpin == TRUE) {
1602  free(list_2_1_Sz);
1603  free(list_2_2_Sz);
1604  }
1605  return 0;
1606 }
void exitMPI(int errorcode)
MPI Abortation wrapper.
Definition: wrapperMPI.cpp:86
long int Binomial(int n, int k, long int **comb, int Nsite)
Definition: sz.cpp:178
int Nup
Number of spin-up electrons in this process.
Definition: struct.hpp:58
struct DefineList Def
Definision of system (Hamiltonian) etc.
Definition: struct.hpp:395
FILE * stdoutMPI
File pointer to the standard output defined in InitializeMPI()
Definition: global.cpp:75
int GetSplitBitByModel(const int Nsite, const int iCalcModel, long int *irght, long int *ilft, long int *ihfbit)
function of splitting original bit into right and left spaces.
Definition: bitcalc.cpp:78
int child_omp_sz_Kondo_hacker(long int ib, long int ihfbit, struct BindStruct *X, long int *list_1_, long int *list_2_1_, long int *list_2_2_, long int *list_jb_)
calculating restricted Hilbert space for Kondo-GC systems
Definition: sz.cpp:54
int Total2Sz
Total in this process.
Definition: struct.hpp:69
int Nsite
Number of sites in the INTRA process region.
Definition: struct.hpp:56
struct LargeList Large
Variables for Matrix-Vector product.
Definition: struct.hpp:397
int * LocSpn
[DefineList::NLocSpn] Flag (and size) of the local spin. malloc in setmem_def().
Definition: struct.hpp:82
int Read_sz(struct BindStruct *X, const long int irght, const long int ilft, const long int ihfbit, long int *i_max)
reading the list of the restricted Hilbert space
Definition: sz.cpp:817
int child_omp_sz_spin(long int ib, long int ihfbit, int N, struct BindStruct *X, long int *list_1_, long int *list_2_1_, long int *list_2_2_, long int *list_jb_)
calculating restricted Hilbert space for spin-1/2 systems
Definition: sz.cpp:640
int child_omp_sz_Kondo(long int ib, long int ihfbit, struct BindStruct *X, long int *list_1_, long int *list_2_1_, long int *list_2_2_, long int *list_jb_)
calculating restricted Hilbert space for Kondo systems
Definition: sz.cpp:441
int child_omp_sz(long int ib, long int ihfbit, struct BindStruct *X, long int *list_1_, long int *list_2_1_, long int *list_2_2_, long int *list_jb_)
calculating restricted Hilbert space for Hubbard systems
Definition: sz.cpp:227
long int irght
Used for Ogata-Lin ???
Definition: struct.hpp:344
int Ne
Number of electrons in this process.
Definition: struct.hpp:71
long int ilft
Used for Ogata-Lin ???
Definition: struct.hpp:345
int READ
It is ALWAYS 0 ???
Definition: struct.hpp:53
int read_hacker
Whether use an efficient method (=1) in sz.c or not (=0)
Definition: struct.hpp:52
long int ihfbit
Used for Ogata-Lin ???
Definition: struct.hpp:346
int child_omp_sz_KondoGC(long int ib, long int ihfbit, struct BindStruct *X, long int *list_1_, long int *list_2_1_, long int *list_2_2_, long int *list_jb_)
Definition: sz.cpp:551
int GetLocal2Sz(const int isite, const long int org_bit, const long int *SiteToBit, const long int *Tpow)
get 2sz at a site for general spin
Definition: bitcalc.cpp:448
int iFlgGeneralSpin
Flag for the general (Sz/=1/2) spin.
Definition: struct.hpp:86
int child_omp_sz_hacker(long int ib, long int ihfbit, struct BindStruct *X, long int *list_1_, long int *list_2_1_, long int *list_2_2_, long int *list_jb_)
efficient version of calculating restricted Hilbert space for Hubbard systems using snoob details of ...
Definition: sz.cpp:323
int child_omp_sz_GeneralSpin(long int ib, long int ihfbit, struct BindStruct *X, long int *list_1_, long int *list_2_1_, long int *list_2_2_, long int *list_2_1_Sz_, long int *list_2_2_Sz_, long int *list_jb_)
calculating restricted Hilbert space for general spin systems (S>1/2)
Definition: sz.cpp:772
int child_omp_sz_spin_hacker(long int ib, long int ihfbit, int N, struct BindStruct *X, long int *list_1_, long int *list_2_1_, long int *list_2_2_, long int *list_jb_)
efficient version of calculating restricted Hilbert space for spin-1/2 systems details of snoob is fo...
Definition: sz.cpp:702
long int * SiteToBit
[DefineList::NsiteMPI] Similar to DefineList::Tpow. For general spin.
Definition: struct.hpp:94
long int snoob(long int x)
"finding the next higher number after a given number that has the same number of 1-bits" This method ...
Definition: bitcalc.cpp:473
long int * Tpow
[2 * DefineList::NsiteMPI] malloc in setmem_def().
Definition: struct.hpp:90
int TimeKeeper(struct BindStruct *X, const char *cFileName, const char *cTimeKeeper_Message, const char *cWriteType)
Functions for writing a time log.
Definition: log.cpp:42
int iCalcModel
Switch for model. 0:Hubbard, 1:Spin, 2:Kondo, 3:HubbardGC, 4:SpinGC, 5:KondoGC, 6:HubbardNConserved.
Definition: struct.hpp:200
int iFlgCalcSpec
Input parameter CalcSpec in teh CalcMod file.
Definition: struct.hpp:218
int Ndown
Number of spin-down electrons in this process.
Definition: struct.hpp:59
long int SizeOflistjb
Used for computing Sz.
Definition: struct.hpp:321
int NLocSpn
Number of local spins.
Definition: struct.hpp:84
struct CheckList Check
Size of the Hilbert space.
Definition: struct.hpp:396
char * CDataFileHead
Read from Calcmod in readdef.h. Header of output file such as Green&#39;s function.
Definition: struct.hpp:42
long int sdim
Dimension for Ogata-Lin ???
Definition: struct.hpp:309
long int idim_max
The dimension of the Hilbert space of this process.
Definition: struct.hpp:305
int childfopenMPI(const char *_cPathChild, const char *_cmode, FILE **_fp)
Only the root process open file in output/ directory.
Definition: FileIO.cpp:27