File: readfile.c

package info (click to toggle)
openmx 3.2.4.dfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: lenny, squeeze
  • size: 62,572 kB
  • ctags: 2,684
  • sloc: ansic: 130,666; python: 876; makefile: 560; xml: 63; perl: 18; sh: 4
file content (132 lines) | stat: -rw-r--r-- 3,024 bytes parent folder | download
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
/**********************************************************************
  readfile.c:

     readfile.c is a subrutine to read a input file or restart file.

  Log of readfile.c:

     22/Nov/2001  Released by T.Ozaki

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

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

#ifdef nompi
#include "mimic_mpi.h"
#else
#include "mpi.h"
#endif

#ifdef TRAN
#include "tran_prototypes.h"
#endif

double readfile(char *argv[])
{ 
  double time0;
  double TStime,TEtime;
  FILE *fp;
  int numprocs,myid; 
  char fileMemory[YOUSO10]; 
  char buf[fp_bsize];          /* setvbuf */

  dtime(&TStime);

  MPI_Comm_size(mpi_comm_level1,&numprocs);
  MPI_Comm_rank(mpi_comm_level1,&myid);

  /****************************************************
           Read a input file or restart file.
  ****************************************************/

  if ((fp = fopen(argv[1],"r")) != NULL){

#ifdef xt3
    setvbuf(fp,buf,_IOFBF,fp_bsize);  /* setvbuf */
#endif

    Input_std(argv[1]);
    fclose(fp);
  }
  else{
    printf("Failure of reading the input file.\n");
    exit(0);
  }


#if 0
  /* separate CPUs */
  if ( atomnum < numprocs )  {
    int *new_ranks; 
    int i;
    MPI_Group  new_group,old_group; 

    if (myid==Host_ID) {
       printf("****************************************\n");
       printf("Cut off CPUs, New group contains %d CPUs\n",atomnum); 
       printf("****************************************\n");

    }

    new_ranks=(int*)malloc(sizeof(int)*atomnum); 
    for (i=0;i<atomnum; i++) {
     new_ranks[i]=i; /* a new group is made of original rank=0:atomnum-1 */
    }

    MPI_Comm_group(MPI_COMM_WORLD, &old_group);
    /* define a new group */
    MPI_Group_incl(old_group,atomnum,new_ranks,&new_group);
    MPI_Comm_create(MPI_COMM_WORLD,new_group,&mpi_comm_level1);

    free(new_ranks); /* never forget cleaning! */

  }
  /* default mpi_comm_level1 is already set in main() */
#endif

  if (myid<atomnum) {

    Allocate_Arrays(2);
    Set_Allocate_Atom2CPU(0,1,0); /* for species */
    SetPara_DFT();

#ifdef TRAN 

    if ( TRAN_Check_Region_Lead(atomnum, WhatSpecies, Spe_Atom_Cut1, Gxyz, tv)==0 ) {
      printf("\n\nERROR: PAOs of lead atoms can overlap only to the next nearest region.\n\n");
      MPI_Finalize();
      exit(1);
    }
    if ( Solver==4 ) {
      if ( TRAN_Check_Region(atomnum, WhatSpecies, Spe_Atom_Cut1, Gxyz)==0 ) {
	printf("\n\nERROR: PAOs of atoms of L|C|R can overlap only to the next nearest region.\n\n");
	MPI_Finalize();
	exit(1);
      }
    }
#endif

     
    Set_Allocate_Atom2CPU(0,0,0); /* a simple division for atoms (get Matomnum) */

    if (Solver!=6) { /*  except for GDC */

    /*****************************
      final input
      0: atomnum, 
      1: the neighbor 
      2: elapsed time 
    *****************************/    

      Set_Allocate_Atom2CPU(1,0,0); 
    }
  } 

  dtime(&TEtime);
  time0 = TEtime - TStime;
  return time0;
}