IPCC  1.0
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
KNGeometricConstructionLaunch.cpp
Go to the documentation of this file.
1 #include "stdafx.h"
3 #include "KNGeometricAtom.h"
4 #include "KNGeometicAtomFactory.h"
5 #include "KNMPIManager.h"
6 
7 #include "CKNGlobal.h"
8 #include "KNMatrixDebug.h"
9 #include <mpi.h>
10 
11 
13 {
14 }
15 
16 
18 {
19 }
20 
21 void getCurrentTime(char *pszBuffer)
22 {
23  time_t timer;
24  struct tm *t;
25 
26  timer = time(NULL);
27  t = localtime(&timer);
28 
29  sprintf(pszBuffer, "%d:%d:%d", t->tm_hour, t->tm_min, t->tm_sec);
30 }
31 
32 void CKNGeometricConstructionLaunch::LaunchingGeometricConstructionMPI(char*pszInputCommnadFileName, CKNGeometricShape *pShape, bool bReturnCSR)
33 {
34  NEIGHBOR_MAP_INFO mapInfo;
35  PERIODIC_INFO periodicInfo;
36  CKNMatrixOperation::CKNCSR *pResult = NULL;
38  if (NULL == lpParam)
39  return;
40  char szMsg[1024];
41  CKNGeometricShape shape, *pShapeOperand;
42 
43  if (NULL != pShape)
44  pShapeOperand = pShape;
45  else
46  pShapeOperand = &shape;
47 
48  MPI_Init(NULL, NULL);
49 
50  int world_size;
51  MPI_Comm_size(MPI_COMM_WORLD, &world_size);
52 
53  int rank;
54  MPI_Comm_rank(MPI_COMM_WORLD, &rank);
55 
56  CKNMPIManager::SetMPIEnviroment(rank, world_size);
59 
61  {
62  char szTime[1024];
63  getCurrentTime(szTime);
64  sprintf(szMsg, "\n-Start Geomatric Construction - [%s]\n", szTime);
66  }
67 
69 
70  lpParam->fUnitcellLength[CKNGeometricShape::LX] = 1;
71  lpParam->fUnitcellLength[CKNGeometricShape::LY] = 1;
72  lpParam->fUnitcellLength[CKNGeometricShape::LZ] = 1;
73  //lpParam->fUnitcellLength = 0.5430950;
74  lpParam->bConsiderBoundaryCondition[CKNGeometricShape::LX] = false;
75  lpParam->bConsiderBoundaryCondition[CKNGeometricShape::LY] = false;
76  lpParam->bConsiderBoundaryCondition[CKNGeometricShape::LZ] = false;
77  lpParam->bConsiderBoundaryCondition[CKNGeometricShape::LX] = true;
78  lpParam->bConsiderBoundaryCondition[CKNGeometricShape::LY] = true;
79  lpParam->bConsiderBoundaryCondition[CKNGeometricShape::LZ] = true;
80  lpParam->fShapeLength[CKNGeometricShape::LX] = 6.;
81  lpParam->fShapeLength[CKNGeometricShape::LY] = 6.;
82  lpParam->fShapeLength[CKNGeometricShape::LZ] = 6.;
84 
85  try{
86  SetShapeInformation(*pShapeOperand, lpParam);
87  SetUnitCellInformation(lpParam);
88  pShapeOperand->FillUnitcell();
90 #ifndef DISABLE_MPI_ROUTINE
91  pShapeOperand->ExchangeAtomInfoBetweenNode();
92 #endif //DISABLE_MPI_ROUTINE
93  pShapeOperand->PeriodicUnitCellNumbering();
94  pShapeOperand->BuildNeighborMap();
95  pShapeOperand->BuildNeighborMapInfo(&mapInfo, false);
96  if (bReturnCSR)
97  {
98  pShapeOperand->BuildHamiltonian(lpParam, &mapInfo, pResult);
99  }
100  }
101  catch (unsigned long dwError)
102  {
103  switch (dwError)
104  {
105  case ERROR_LOAD_BLANCING_FAIL:
106  CKNMatrixDebug::ShowMsg("Rank is too much for current shape!\n");
107  break;
108  }
109  }
110 
111  free(lpParam);
112 
114  MPI_Finalize();
115 }
116 
118 {
119  NEIGHBOR_MAP_INFO mapInfo;
120  PERIODIC_INFO periodicInfo;
121  CKNMatrixOperation::CKNCSR *pResult = NULL;
122  CKNGeometricShape shape, *pShapeOperand;
123 
124  *lpParam = CKNCommandFileParser::ParsingInputCommand(pszInputCommnadFileName);
125 
126 
127  /*CKNMatrixOperation::CKNCSR *pCSR = new CKNMatrixOperation::CKNCSR();
128  if (NULL == pCSR)
129  return pResult;*/
130 
131  if (NULL == *lpParam)
132  return pResult;
133 
134  if (NULL != pShape)
135  pShapeOperand = pShape;
136  else
137  pShapeOperand = &shape;
138 
139  SetShapeInformation(*pShapeOperand, *lpParam);
140  SetUnitCellInformation(*lpParam);
141  pShapeOperand->FillUnitcell();
143  pShapeOperand->PeriodicUnitCellNumbering();
144  pShapeOperand->BuildNeighborMap();
145  mapInfo.fItemCount = 0;
146  pShapeOperand->BuildNeighborMapInfo(&mapInfo, true);
147  if (bReturnCSR)
148  {
149 #ifdef DISABLE_MPI_ROUTINE
150  //pResult = BuildDumyMatrix(mapInfo.fItemCount * 10, mapInfo.fItemCount * 10);
151  pResult = new CKNMatrixOperation::CKNCSR();
152 
153  pResult->SetRowCount(mapInfo.fItemCount * 10);
154  pResult->SetColumnCount(mapInfo.fItemCount * 10);
155  pResult->BuildDataBuffer();
156 #else //DISABLE_MPI_ROUTINE
157 #endif //DISABLE_MPI_ROUTINE
158  if (NULL == pResult)
159  return pResult;
160  pShapeOperand->BuildHamiltonian(*lpParam, &mapInfo, pResult);
161  }
162 
163  pShapeOperand->FreeMapInfo(&mapInfo);
164  //free(lpParam);
165 
166  return pResult;
167 }
168 
170 {
171 
172  shape.SetDirection(1, 0, 0);
173  shape.SetLength(lpParam->fShapeLength[CKNGeometricShape::LX], lpParam->fShapeLength[CKNGeometricShape::LY], lpParam->fShapeLength[CKNGeometricShape::LZ]);
174  shape.SetOriginCoordination(lpParam->fOrigin[CKNGeometricShape::LX], lpParam->fOrigin[CKNGeometricShape::LY], lpParam->fOrigin[CKNGeometricShape::LZ]);
175  shape.SetMaterialType(lpParam->szDomainMat);
176  shape.SetShapeForm(CKNGeometricShape::BOX);
177  shape.SetConsideringBoundaryCondition(lpParam->bConsiderBoundaryCondition[CKNGeometricShape::LX], CKNGeometricShape::LX);
178  shape.SetConsideringBoundaryCondition(lpParam->bConsiderBoundaryCondition[CKNGeometricShape::LY], CKNGeometricShape::LY);
179  shape.SetConsideringBoundaryCondition(lpParam->bConsiderBoundaryCondition[CKNGeometricShape::LZ], CKNGeometricShape::LZ);
180 #ifdef DISABLE_MPI_ROUTINE
181  shape.SetFrontFace(true);
182  shape.SetBackendFace(true);
183 #else //DISABLE_MPI_ROUTINE
185  shape.SetFrontFace(true);
187  shape.SetBackendFace(true);
188 #endif //DISABLE_MPI_ROUTINE
189 }
190 
192 {
194 
199 
204 
209 
214 
216 
217 }
static void InitCommunicationBufferMetric()
Initializing MPI Communication buffer for MVMul.
static void FinalizeManager()
Get Root rank.
static void SetNeighborCoordination(CKNGeometricAtom::NEIGHOR_RELATION type, double x, double y, double z)
Setting neighbor coordination.
void ExchangeAtomInfoBetweenNode()
Get start index of atom in shape, using in MPI running enviroment.
void SetMaterialType(MATERIAL_INDEX type)
Get maetrial typpe of shap.
static void SetMPIEnviroment(int nRank, int nTotalNode)
Set MPI Enviroment.
void SetConsideringBoundaryCondition(bool bConsider, AXIS_DEFINE direction)
Get bondary condition of shape.
void getCurrentTime(char *pszBuffer)
static void FreeMapInfo(LPNEIGHBOR_MAP_INFO lpMapInfo)
Release mapinfo data.
static void SetShapeInformation(CKNGeometricShape &shape, CKNCommandFileParser::LPINPUT_CMD_PARAM lpParam)
void SetOriginCoordination(double x, double y, double z)
Building Geometric part.
Data and operation representation of CSR(Compressed Sparse Row)
void SetDirection(double x_axis, double y_axis, double z_axis)
Set direciton of shape.
void SetLength(double lx, double ly, double lz)
Set length of shape.
static int GetTotalNodeCount()
Definition: KNMPIManager.h:44
static void SetAtomCoordination(CKNGeometricAtom::ATOM_TYPE type, double x, double y, double z)
Setting atom coordination.
Class for Atom.
void BuildDataBuffer()
Allocating memory for class member variable.
static LPINPUT_CMD_PARAM ParsingInputCommand(char *pszInputCommnadFileName)
Parsing Commaind file.
Class for Geometric shape.
static void SetUnitCellInformation(CKNCommandFileParser::LPINPUT_CMD_PARAM lpParam)
static void LaunchingGeometricConstructionMPI(char *pszInputCommnadFileName, CKNGeometricShape *pShape, bool bReturnCSR)
Common definition for Solver.
Structure for save input command file parsing result.
double fShapeLength[NMAXDOMAIN][3]
Shap length x, y, z, direction.
double fItemCount
Item count at atom map.
char szDomainMat[NMAXDOMAIN][1024]
Material type.
bool FillUnitcell(CKNCommandFileParser::LPINPUT_CMD_PARAM lpParam)
Set bondary condition of shape.
double fUnitcellLength[3]
Unitcell length x, y, z direction.
void SetBackendFace(bool bBackendFace)
Check is this back end face side in MPI running enviroment.
static void ShowMsg(char *pszBuffer)
Show message.
This class includes functions for matrix debugging.
static void SetLength(double fLength[3], double fOriginLength[3])
Set unit cell length.
void SetShapeForm(unsigned int form)
Get form type of shape.
void SetFrontFace(bool bFrontFace)
Check is this front face side in MPI running enviroment.
static int GetCurrentRank()
Definition: KNMPIManager.h:42
void PeriodicUnitCellNumbering(bool bXAxis=false)
Numbering to periodic unitcell.
MPI Mangement class.
void SetRowCount(unsigned int nRow)
Settting row size of matrix.
static CKNMatrixOperation::CKNCSR * LaunchingGeometricConstruction(char *pszInputCommnadFileName, CKNGeometricShape *pShape, CKNCommandFileParser::LPINPUT_CMD_PARAM *lpParam, bool bReturnCSR)
static void LoadBlancingForLanczos(int nRowCount)
Load blancing for MPI, this function only for lanczos solving without geometric constrcution.
void SetColumnCount(unsigned int nColumn)
Settting column size of matrix.
static bool IsRootRank()
Get Total node count.
int nMatrixDemension
Hamiltonian matrix demension.
Structure for neighbor information.
bool bConsiderBoundaryCondition[3]
Considering bondary condition or not x, y, z direction.
double fOrigin[NMAXDOMAIN][3]
Coordinator original coordinate.