File: TRAN_Allocate.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 (203 lines) | stat: -rw-r--r-- 4,785 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
193
194
195
196
197
198
199
200
201
202
203
/**********************************************************************
  TRAN_Allocate.c:

  TRAN_Allocate.c is a set of subroutines to allocate and deallocate 
  arrays used for the NEGF calculation.

  TRAN_Allocate_Atoms:          called from TRAN_Input_Atoms
  TRAN_Deallocate_Atoms:        called from openmx
  TRAN_Allocate_Cregion:        called from DFT
  TRAN_Deallocate_Cregion:      called from DFT
  TRAN_Allocate_Lead_Region:    called from DFT
  TRAN_Deallocate_Lead_Region:  called from DFT

  Log of TRAN_Allocate.c:

     11/Dec/2005   Released by H.Kino

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

#include <stdio.h>
#include <stdlib.h>
#include <mpi.h>
#include "tran_prototypes.h"
#include "tran_variables.h"


/* (de)allocate memory used in TRAN_Input_std_Atoms */

void TRAN_Allocate_Atoms(int atomnum)
{
  TRAN_region      = (int*)malloc(sizeof(int)*(atomnum+1));
  TRAN_Original_Id = (int*)malloc(sizeof(int)*(atomnum+1));
}

void TRAN_Deallocate_Atoms( void )
{
  free(TRAN_region);
  free(TRAN_Original_Id);
}


/* (de)allocate memory to calculate green function  */



void TRAN_Allocate_Cregion(MPI_Comm mpi_comm_level1,  
                           int SpinP_switch, 
			   int atomnum,
			   int *WhatSpecies,
			   int *Spe_Total_CNO 
			   /* no explicit output */
			   ) 
{
  int *MP; /* dummy */
  int i,k;
  int numprocs,myid;

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

  TRAN_Set_MP(0, atomnum, WhatSpecies, Spe_Total_CNO, &NUM_c, &i);

  if (myid==Host_ID){
    printf("<TRAN_Allocate_Cregion: NUM_c=%d NUM_e=%d %d>\n",NUM_c, NUM_e[0],NUM_e[1]);
  }

  /* allocate */
  SCC = (dcomplex*)malloc(sizeof(dcomplex)*NUM_c*NUM_c);
  SCL = (dcomplex*)malloc(sizeof(dcomplex)*NUM_c*NUM_e[0]);
  SCR = (dcomplex*)malloc(sizeof(dcomplex)*NUM_c*NUM_e[1]);
  HCC = (dcomplex**)malloc(sizeof(dcomplex*)*(SpinP_switch+1));
  HCL = (dcomplex**)malloc(sizeof(dcomplex*)*(SpinP_switch+1));
  HCR = (dcomplex**)malloc(sizeof(dcomplex*)*(SpinP_switch+1));
  for (k=0; k<=SpinP_switch; k++) {
    HCC[k] = (dcomplex*)malloc(sizeof(dcomplex)*NUM_c*NUM_c);
    HCL[k] = (dcomplex*)malloc(sizeof(dcomplex)*NUM_c*NUM_e[0]);
    HCR[k] = (dcomplex*)malloc(sizeof(dcomplex)*NUM_c*NUM_e[1]);
  }
}





void TRAN_Deallocate_Cregion(int SpinP_switch)
{
  int k;

  for (k=SpinP_switch; k>=0; k--) {
    free(HCR[k]);
    free(HCL[k]);
    free(HCC[k]);
  }
  free(HCR);
  free(HCL);
  free(HCC);
  free(SCR);
  free(SCL);
  free(SCC);
}








void TRAN_Allocate_Lead_Region( MPI_Comm mpi_comm_level1 ) 
{
  int *MP; /* dummy */
  int i,k,n2,iside,num[2];
  int numprocs,myid;

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

  if (myid==Host_ID){
    printf("<TRAN_Allocate_Lead_Region>\n");
  }

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

  iside = 0; 
  TRAN_Set_MP(0, atomnum_e[iside], WhatSpecies_e[iside], Spe_Total_CNO_e[iside], &num[iside], &i);

  iside = 1; 
  TRAN_Set_MP(0, atomnum_e[iside], WhatSpecies_e[iside], Spe_Total_CNO_e[iside], &num[iside], &i);

  NUM_e[0] = num[0];
  NUM_e[1] = num[1];

  /* allocate */

  S00_e = (dcomplex**)malloc(sizeof(dcomplex*)*2);
  for (iside=0; iside<=1; iside++){
    n2 = num[iside] + 1;
    S00_e[iside] = (dcomplex*)malloc(sizeof(dcomplex)*n2*n2);
  }

  S01_e = (dcomplex**)malloc(sizeof(dcomplex*)*2);
  for (iside=0; iside<=1; iside++){
    n2 = num[iside] + 1;
    S01_e[iside] = (dcomplex*)malloc(sizeof(dcomplex)*n2*n2);
  }

  H00_e = (dcomplex***)malloc(sizeof(dcomplex**)*2);
  for (iside=0; iside<=1; iside++){
    H00_e[iside] = (dcomplex**)malloc(sizeof(dcomplex*)*(SpinP_switch_e[iside]+1));
    for (k=0; k<=SpinP_switch_e[iside]; k++) {
      n2 = num[iside] + 1;
      H00_e[iside][k] = (dcomplex*)malloc(sizeof(dcomplex)*n2*n2);
    }
  }

  H01_e = (dcomplex***)malloc(sizeof(dcomplex**)*2);
  for (iside=0; iside<=1; iside++){
    H01_e[iside] = (dcomplex**)malloc(sizeof(dcomplex*)*(SpinP_switch_e[iside]+1));
    for (k=0; k<=SpinP_switch_e[iside]; k++) {
      n2 = num[iside] + 1;
      H01_e[iside][k] = (dcomplex*)malloc(sizeof(dcomplex)*n2*n2);
    }
  }
}



void TRAN_Deallocate_Lead_Region()
{
  int k,iside;

  for (iside=0; iside<=1; iside++){
    free(S00_e[iside]);
  }
  free(S00_e);

  for (iside=0; iside<=1; iside++){
    free(S01_e[iside]);
  }
  free(S01_e);

  for (iside=0; iside<=1; iside++){
    for (k=0;k<=SpinP_switch_e[iside]; k++) {
      free(H00_e[iside][k]);
    }
    free(H00_e[iside]);
  }
  free(H00_e);

  for (iside=0; iside<=1; iside++){
    for (k=0; k<=SpinP_switch_e[iside]; k++) {
      free(H01_e[iside][k]);
    }
    free(H01_e[iside]);
  }
  free(H01_e);
}