File: Hamiltonian_Cluster_SO.c

package info (click to toggle)
openmx 3.7.6-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, stretch
  • size: 325,856 kB
  • ctags: 3,575
  • sloc: ansic: 152,655; f90: 2,080; python: 876; makefile: 675; sh: 25; perl: 18
file content (192 lines) | stat: -rw-r--r-- 4,561 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
/**********************************************************************
  Hamiltonian_Cluster_SO.c:

     Hamiltonian_Cluster_SO.c is a subroutine to make a Hamiltonian
     matrix in spin-collinear with spin-orbit coupling for cluster
     or molecular systems.

  Log of Hamiltonian_Cluster_SO.c:

     8/Jan/2004  Released by T.Ozaki

***********************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include "openmx_common.h"
#include "mpi.h"


void Hamiltonian_Cluster_SO(double ****RH, double ****IH, dcomplex **H, int *MP)
{
  static int firsttime=1;
  int i,j,n2;
  int MA_AN,GA_AN,LB_AN,GB_AN;
  int wanA,wanB,tnoA,tnoB,Anum,Bnum,NUM;
  int ID,myid,numprocs,tag=999;
  double **H1,**H2;

  MPI_Status stat;
  MPI_Request request;

  /* MPI */
  MPI_Comm_size(mpi_comm_level1,&numprocs);
  MPI_Comm_rank(mpi_comm_level1,&myid);
  MPI_Barrier(mpi_comm_level1);

  /* set MP */
  Anum = 1;
  for (i=1; i<=atomnum; i++){
    MP[i] = Anum;
    wanA = WhatSpecies[i];
    Anum = Anum + Spe_Total_CNO[wanA];
  }
  NUM = Anum - 1;
  H[0][0].r = NUM;

  /****************************************************
    allocation of arrays
  ****************************************************/

  n2 = NUM + 2;

  H1 = (double**)malloc(sizeof(double*)*n2);
  for (i=0; i<n2; i++){
    H1[i] = (double*)malloc(sizeof(double)*n2);
  }

  H2 = (double**)malloc(sizeof(double*)*n2);
  for (i=0; i<n2; i++){
    H2[i] = (double*)malloc(sizeof(double)*n2);
  }

  for (i=0; i<=NUM; i++){
    for (j=0; j<=NUM; j++){
      H1[i][j] = 0.0;
      H2[i][j] = 0.0;
    }
  }

  /* for PrintMemory */
  if (firsttime) {
    PrintMemory("Hamiltonian_Cluster_SO: H1",sizeof(double)*n2*n2,NULL);
    PrintMemory("Hamiltonian_Cluster_SO: H2",sizeof(double)*n2*n2,NULL);
  }
  firsttime=0;


  /* set full H */
  for (MA_AN=1; MA_AN<=Matomnum; MA_AN++){
    GA_AN = M2G[MA_AN];    
    wanA = WhatSpecies[GA_AN];
    tnoA = Spe_Total_CNO[wanA];
    Anum = MP[GA_AN];
    for (LB_AN=0; LB_AN<=FNAN[GA_AN]; LB_AN++){
      GB_AN = natn[GA_AN][LB_AN];
      wanB = WhatSpecies[GB_AN];
      tnoB = Spe_Total_CNO[wanB];
      Bnum = MP[GB_AN];
      for (i=0; i<tnoA; i++){
	for (j=0; j<tnoB; j++){
	  H1[Anum+i][Bnum+j] = RH[MA_AN][LB_AN][i][j];
	  H2[Anum+i][Bnum+j] = IH[MA_AN][LB_AN][i][j];
	}
      }
    }
  }

  /******************************************************
    MPI:
  ******************************************************/

  /* H1 */
  if (myid!=Host_ID){
    for (MA_AN=1; MA_AN<=Matomnum; MA_AN++){
      GA_AN = M2G[MA_AN];    
      wanA = WhatSpecies[GA_AN];
      tnoA = Spe_Total_CNO[wanA];
      Anum = MP[GA_AN];

      tag = 999;
      for (i=0; i<tnoA; i++){
        MPI_Isend(&H1[Anum+i][0], NUM+1, MPI_DOUBLE, Host_ID,
                   tag, mpi_comm_level1, &request);
        MPI_Wait(&request,&stat);
      }
    }
  }
  else{
    for (GA_AN=1; GA_AN<=atomnum; GA_AN++){
      wanA = WhatSpecies[GA_AN];
      tnoA = Spe_Total_CNO[wanA];
      Anum = MP[GA_AN];
      ID = G2ID[GA_AN];
      if (ID!=Host_ID){
        tag = 999;
        for (i=0; i<tnoA; i++){
          MPI_Recv(&H1[Anum+i][0], NUM+1, MPI_DOUBLE, ID, tag, mpi_comm_level1, &stat);
	}
      }    
    }
  }  

  /* H2 */
  if (myid!=Host_ID){
    for (MA_AN=1; MA_AN<=Matomnum; MA_AN++){
      GA_AN = M2G[MA_AN];    
      wanA = WhatSpecies[GA_AN];
      tnoA = Spe_Total_CNO[wanA];
      Anum = MP[GA_AN];
      tag = 999;
      for (i=0; i<tnoA; i++){
        MPI_Isend(&H2[Anum+i][0], NUM+1, MPI_DOUBLE, Host_ID,
                   tag, mpi_comm_level1, &request);
        MPI_Wait(&request,&stat);
      }
    }
  }
  else{
    for (GA_AN=1; GA_AN<=atomnum; GA_AN++){
      wanA = WhatSpecies[GA_AN];
      tnoA = Spe_Total_CNO[wanA];
      Anum = MP[GA_AN];
      ID = G2ID[GA_AN];
      if (ID!=Host_ID){
        tag = 999;
        for (i=0; i<tnoA; i++){
          MPI_Recv(&H2[Anum+i][0], NUM+1, MPI_DOUBLE, ID, tag, mpi_comm_level1, &stat);
	}
      }    
    }
  }  

  /****************************************************
    putting to H1 and H2 to H
  ****************************************************/

  for (i=1; i<=NUM; i++){
    for (j=1; j<=NUM; j++){
      H[i][j].r = H1[i][j];
      H[i][j].i = H2[i][j];
    }
  }

  /****************************************************
    freeing of arrays
  ****************************************************/

  for (i=0; i<n2; i++){
    free(H1[i]);
  }
  free(H1);

  for (i=0; i<n2; i++){
    free(H2[i]);
  }
  free(H2);

}