File: c2pw.cpp

package info (click to toggle)
espresso 6.7-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 311,068 kB
  • sloc: f90: 447,429; ansic: 52,566; sh: 40,631; xml: 37,561; tcl: 20,077; lisp: 5,923; makefile: 4,503; python: 4,379; perl: 1,219; cpp: 761; fortran: 618; java: 568; awk: 128
file content (115 lines) | stat: -rw-r--r-- 3,150 bytes parent folder | download | duplicates (5)
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
//
// Copyright (C) 2013 Quantum ESPRESSO group
// This file is distributed under the terms of the
// GNU General Public License. See the file `License'
// in the root directory of the present distribution,
// or http://www.gnu.org/copyleft/gpl.txt .
//

#include <mpi.h>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include "libqecouple.h"

// ... Test program for Q-E library interface
int main(int argc, char **argv)
{
    int retval, pw_comm, ncpu, key, me;
    char input[81] = { ' ', '\0' };
    MPI_Comm new_comm;

    MPI_Init(&argc, &argv);
    MPI_Comm_size(MPI_COMM_WORLD,&ncpu);
    MPI_Comm_rank(MPI_COMM_WORLD,&me);

    // parse command line flags.
    int i=1;
    int nimage=1, npots=1, npools=1, ntg=1, nband=1, ndiag=1, nres=0;
    while (i < argc-1) {
        if (strncmp("-i",argv[i],2) == 0) {
            ++i;
            strncpy(input, argv[i], 80);
            input[80] = '\0';
            ++i;
            continue;
        }
        if (strncmp("-ni",argv[i],3) == 0) {
            ++i;
            nimage=std::atoi(argv[i]);
            ++i;
            continue;
        }
        if (strncmp("-npot",argv[i],5) == 0) {
            ++i;
            npots=std::atoi(argv[i]);
            ++i;
            continue;
        }
        if ((strncmp("-nk",argv[i],3) == 0)
            || (strncmp("-npoo",argv[i],5) == 0)) {
            ++i;
            ndiag=std::atoi(argv[i]);
            ++i;
            continue;
        }
        if (strncmp("-nt",argv[i],3) == 0) {
            ++i;
            ntg=std::atoi(argv[i]);
            ++i;
            continue;
        }
        if (strncmp("-nb",argv[i],3) == 0) {
            ++i;
            nband=std::atoi(argv[i]);
            ++i;
            continue;
        }
        if ((strncmp("-nd",argv[i],3) == 0)
            || (strncmp("-no",argv[i],3) == 0)
            || (strcmp("-nproc_diag",argv[i]) == 0)
            || (strcmp("-nproc_ortho",argv[i]) == 0)) {
            ++i;
            ndiag=std::atoi(argv[i]);
            ++i;
            continue;
        }
        if (strncmp("-nr",argv[i],3) == 0) {
            ++i;
            nres=std::atoi(argv[i]);
            ++i;
            continue;
        }
        std::cerr << "usage: " << argv[0] << " -flag1 <value1> -flag2 <value2>\n"
                  << std::endl;
        return -1;
    }

    if (i != argc) {
        std::cerr << "usage: " << argv[0] << " -flag1 <value1> -flag2 <value2>\n"
                  << std::endl;
        return -1;
    }

    // Create new C-style communicator and convert to Fortran
    key = MPI_UNDEFINED;
    if (me < (ncpu - nres))
        key = 1;
    
    MPI_Comm_split(MPI_COMM_WORLD, key, me, &new_comm);

    if (new_comm != MPI_COMM_NULL) {
        pw_comm = MPI_Comm_c2f(new_comm);
        // call Q-E
        c2libpwscf(pw_comm,nimage,npots,npools,ntg,nband,ndiag,&retval,input);
  
        std::cout << " rank " << me << " return value is: " << retval << std::endl;
    } else {
        std::cout << " rank " << me << " of " << ncpu -1 << " is reserved" << std::endl;
        retval = 0;
    }
    

    MPI_Finalize();
    return retval;
}