1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (c) 2008 The Regents of the University of California
4 //
5 // This file is part of Qbox
6 //
7 // Qbox is distributed under the terms of the GNU General Public License
8 // as published by the Free Software Foundation, either version 2 of
9 // the License, or (at your option) any later version.
10 // See the file COPYING in the root directory of this distribution
11 // or <http://www.gnu.org/licenses/>.
12 //
13 ////////////////////////////////////////////////////////////////////////////////
14 //
15 // testBasis.cpp
16 //
17 ////////////////////////////////////////////////////////////////////////////////
18 
19 #include "Basis.h"
20 #include <iostream>
21 #include <new>
22 #include <cstdlib>
23 #include <cassert>
24 using namespace std;
25 
26 #include <mpi.h>
27 
main(int argc,char ** argv)28 int main(int argc, char **argv)
29 {
30   // use: testBasis a0x a0y a0z a1x a1y a1z a2x a2y a2z ecut kx ky kz npr npc
31   MPI_Init(&argc,&argv);
32   {
33     if ( argc !=16 )
34     {
35       cout << " use: testBasis a0x a0y a0z a1x a1y a1z a2x a2y a2z"
36            << " ecut kx ky kz npr npc" << endl;
37       return 1;
38     }
39     const D3vector a0(atof(argv[1]),atof(argv[2]),atof(argv[3]));
40     const D3vector a1(atof(argv[4]),atof(argv[5]),atof(argv[6]));
41     const D3vector a2(atof(argv[7]),atof(argv[8]),atof(argv[9]));
42 
43     double ecut = atof(argv[10]);
44     D3vector kpoint(atof(argv[11]),atof(argv[12]),atof(argv[13]));
45     int npr = atoi(argv[14]);
46     int npc = atoi(argv[15]);
47 
48     UnitCell cell(a0,a1,a2);
49 
50     // create cartesian communicator
51     int ndims=2;
52     int dims[2] = {npr, npc};
53     int periods[2] = { 0, 0};
54     int reorder = 0;
55     MPI_Comm cartcomm;
56     MPI_Cart_create(MPI_COMM_WORLD,ndims,dims,periods,reorder,&cartcomm);
57 
58     // partition the cartesian communicator in columns
59     MPI_Comm colcomm;
60     int remain_dims[2] = { 1, 0 };
61     MPI_Cart_sub(cartcomm,remain_dims,&colcomm);
62 
63     Basis basis(colcomm,kpoint);
64     try
65     {
66       basis.resize(cell,cell,ecut);
67     }
68     catch ( bad_alloc )
69     {
70       cout << " bad_alloc caught in Basis::resize" << endl;
71       throw;
72     }
73 
74     int npes, mype;
75     MPI_Comm_size(colcomm,&npes);
76     MPI_Comm_rank(colcomm,&mype);
77     for (int ipe = 0; ipe < npes; ipe++ )
78     {
79       MPI_Barrier(colcomm);
80       if ( ipe == mype )
81       {
82         cout << basis;
83         cout << endl;
84       }
85     }
86 
87     //Basis b2(basis);
88     //cout << b2;
89   }
90   MPI_Finalize();
91 }
92