~ubuntu-branches/ubuntu/utopic/nwchem/utopic

« back to all changes in this revision

Viewing changes to src/tools/ga-5-2/global/testing/ga-mpi.c

  • Committer: Package Import Robot
  • Author(s): Michael Banck, Daniel Leidert, Andreas Tille, Michael Banck
  • Date: 2013-07-04 12:14:55 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20130704121455-5tvsx2qabor3nrui
Tags: 6.3-1
* New upstream release.
* Fixes anisotropic properties (Closes: #696361).
* New features include:
  + Multi-reference coupled cluster (MRCC) approaches
  + Hybrid DFT calculations with short-range HF 
  + New density-functionals including Minnesota (M08, M11) and HSE hybrid
    functionals
  + X-ray absorption spectroscopy (XAS) with TDDFT
  + Analytical gradients for the COSMO solvation model
  + Transition densities from TDDFT 
  + DFT+U and Electron-Transfer (ET) methods for plane wave calculations
  + Exploitation of space group symmetry in plane wave geometry optimizations
  + Local density of states (LDOS) collective variable added to Metadynamics
  + Various new XC functionals added for plane wave calculations, including
    hybrid and range-corrected ones
  + Electric field gradients with relativistic corrections 
  + Nudged Elastic Band optimization method
  + Updated basis sets and ECPs 

[ Daniel Leidert ]
* debian/watch: Fixed.

[ Andreas Tille ]
* debian/upstream: References

[ Michael Banck ]
* debian/upstream (Name): New field.
* debian/patches/02_makefile_flags.patch: Refreshed.
* debian/patches/06_statfs_kfreebsd.patch: Likewise.
* debian/patches/07_ga_target_force_linux.patch: Likewise.
* debian/patches/05_avoid_inline_assembler.patch: Removed, no longer needed.
* debian/patches/09_backported_6.1.1_fixes.patch: Likewise.
* debian/control (Build-Depends): Added gfortran-4.7 and gcc-4.7.
* debian/patches/10_force_gcc-4.7.patch: New patch, explicitly sets
  gfortran-4.7 and gcc-4.7, fixes test suite hang with gcc-4.8 (Closes:
  #701328, #713262).
* debian/testsuite: Added tests for COSMO analytical gradients and MRCC.
* debian/rules (MRCC_METHODS): New variable, required to enable MRCC methods.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#if HAVE_CONFIG_H
 
2
#   include "config.h"
 
3
#endif
 
4
 
 
5
/****************************************************************************
 
6
* program: ga-mpi.c
 
7
* date:    Tue Oct  3 12:31:59 PDT 1995
 
8
* author:  Jarek Nieplocha
 
9
* purpose: This program demonstrates interface between GA and MPI. 
 
10
*          For a given square matrix, it creates a vector that contains maximum
 
11
*          elements for each matrix row. MPI group communication is used.
 
12
*
 
13
* notes:   The program can run in two modes:
 
14
*          1. Using TCGMSG calls available through the TCGMSG-MPI library
 
15
*             and MPI. In this mode initialization must be done with 
 
16
*             the TCGMSG PBEGIN call.
 
17
*          2. Using MPI calls only -- preprocessor symbol MPI must be defined.
 
18
*
 
19
****************************************************************************/
 
20
 
 
21
#if HAVE_STDIO_H
 
22
#   include <stdio.h>
 
23
#endif
 
24
#if HAVE_STDLIB_H
 
25
#   include <stdlib.h>
 
26
#endif
 
27
 
 
28
#include <mpi.h>
 
29
 
 
30
#include "ga.h"
 
31
#include "globalp.h"
 
32
#include "macdecls.h"
 
33
#include "mp3.h"
 
34
 
 
35
 
 
36
#define N 100           /* dimension of matrices */
 
37
 
 
38
 
 
39
void do_work()
 
40
{
 
41
int ZERO=0;   /* useful constants */
 
42
int g_a, g_b;
 
43
int n=N, ndim=2,type=MT_F_DBL,dims[2]={N,N},coord[2];
 
44
int me=GA_Nodeid(), nproc=GA_Nnodes();
 
45
int row, i, j;
 
46
 int lo[2], hi[2];
 
47
 
 
48
/* Note: on all current platforms DoublePrecision = double */
 
49
DoublePrecision buf[N], *max_row=NULL;
 
50
 
 
51
MPI_Comm ROW_COMM;
 
52
int ilo,ihi, jlo,jhi, ld, prow, pcol;
 
53
int root=0, grp_me=-1;
 
54
 
 
55
     if(me==0)printf("Creating matrix A\n");
 
56
     dims[0]=n; dims[1]=n;
 
57
     g_a = NGA_Create(type, ndim, dims, "A", NULL);
 
58
     if(!g_a) GA_Error("create failed: A",n); 
 
59
     if(me==0)printf("OK\n");
 
60
     
 
61
     if(me==0)printf("Creating matrix B\n");
 
62
     dims[0]=n;
 
63
     g_b = NGA_Create(type, 1, dims, "B", NULL);
 
64
     if(!g_b) GA_Error("create failed: B",n); 
 
65
     if(me==0)printf("OK\n");
 
66
     
 
67
     GA_Zero(g_a);   /* zero the matrix */
 
68
     
 
69
     if(me==0)printf("Initializing matrix A\n");
 
70
     /* fill in matrix A with values: A(i,j) = (i+j) */ 
 
71
     for(row=me; row<n; row+= nproc){
 
72
    /**
 
73
     * simple load balancing: 
 
74
     * each process works on a different row in MIMD style 
 
75
     */ 
 
76
    for(i=0; i<n; i++) buf[i]=(DoublePrecision)(i+row+1); 
 
77
    lo[0]=hi[0]=row;
 
78
    lo[1]=ZERO;  hi[1]=n-1; 
 
79
    NGA_Put(g_a, lo, hi, buf, &n); 
 
80
     }
 
81
     
 
82
     /* GA_print(&g_a);*/
 
83
     NGA_Distribution(g_a, me, lo, hi);
 
84
     ilo=lo[0]; ihi=hi[0];
 
85
     jlo=lo[1]; jhi=hi[1];
 
86
     
 
87
     GA_Sync(); 
 
88
     if(ihi-ilo+1 >0){
 
89
        max_row=(DoublePrecision*)malloc(sizeof(DoublePrecision)*(ihi-ilo+1));
 
90
        if (!max_row) GA_Error("malloc 3 failed",(ihi-ilo+1));
 
91
        for (i=0; i<(ihi-ilo+1); i++) {
 
92
            max_row[i] = 0.0;
 
93
        }
 
94
     }
 
95
     NGA_Proc_topology(g_a, me, coord);  /* block coordinates */
 
96
     prow = coord[0];
 
97
     pcol = coord[1];
 
98
 
 
99
     if(me==0)printf("Splitting comm according to distribution of A\n");
 
100
     
 
101
     /* GA on SP1 requires synchronization before & after message-passing !!*/
 
102
     GA_Sync(); 
 
103
     
 
104
     if(me==0)printf("Computing max row elements\n");
 
105
     /* create communicator for processes that 'own' A[:,jlo:jhi] */
 
106
     MPI_Barrier(MPI_COMM_WORLD);
 
107
     if(pcol < 0 || prow <0)
 
108
    MPI_Comm_split(MPI_COMM_WORLD,MPI_UNDEFINED,MPI_UNDEFINED, &ROW_COMM);
 
109
     else
 
110
    MPI_Comm_split(MPI_COMM_WORLD, (int)pcol, (int)prow, &ROW_COMM);
 
111
     
 
112
     if(ROW_COMM != MPI_COMM_NULL){
 
113
    double *ptr;
 
114
    MPI_Comm_rank(ROW_COMM, &grp_me);
 
115
    
 
116
    /* each process computes max elements in the block it 'owns' */
 
117
    lo[0]=ilo; hi[0]=ihi;
 
118
    lo[1]=jlo; hi[1]=jhi;
 
119
    NGA_Access(g_a, lo, hi, &ptr, &ld);
 
120
    for(i=0; i<ihi-ilo+1; i++){
 
121
       for(j=0; j<jhi-jlo+1; j++)
 
122
          if(max_row[i] < ptr[i*ld + j]){
 
123
         max_row[i] = ptr[i*ld + j];
 
124
          }
 
125
    }
 
126
    MPI_Reduce(max_row, buf, ihi-ilo+1, MPI_DOUBLE, MPI_MAX,
 
127
           root, ROW_COMM);
 
128
    
 
129
     }else fprintf(stderr,"process %d not participating\n",me);
 
130
     GA_Sync(); 
 
131
     
 
132
     /* processes with rank=root in ROW_COMM put results into g_b */
 
133
     ld = 1;
 
134
     if(grp_me == root) {
 
135
    lo[0]=ilo;  hi[0]=ihi;
 
136
    NGA_Put(g_b, lo, hi, buf, &ld); 
 
137
     }
 
138
        
 
139
     GA_Sync();
 
140
 
 
141
     if(me==0)printf("Checking the result\n");
 
142
     if(me==0){
 
143
    lo[0]=ZERO; hi[0]=n-1;
 
144
        NGA_Get(g_b, lo, hi, buf, &n); 
 
145
        for(i=0; i< n; i++)if(buf[i] != (double)n+i){
 
146
            fprintf(stderr,"error:%d max=%f should be:%d\n",i,buf[i],n+i);
 
147
            GA_Error("terminating...",1);
 
148
        }
 
149
     }
 
150
     
 
151
     if(me==0)printf("OK\n");
 
152
 
 
153
     GA_Destroy(g_a);
 
154
     GA_Destroy(g_b);
 
155
}
 
156
     
 
157
 
 
158
 
 
159
int main(argc, argv)
 
160
int argc;
 
161
char **argv;
 
162
{
 
163
int heap=20000, stack=20000;
 
164
int me, nproc;
 
165
 
 
166
    MP_INIT(argc,argv);
 
167
    GA_INIT(argc,argv);                            /* initialize GA */
 
168
    me=GA_Nodeid();
 
169
    nproc=GA_Nnodes();
 
170
    if(me==0) printf("Using %ld processes\n",(long)nproc);
 
171
 
 
172
    heap /= nproc;
 
173
    stack /= nproc;
 
174
    if(! MA_init((int)MT_F_DBL, stack, heap)) 
 
175
       GA_Error("MA_init failed",stack+heap);   /* initialize memory allocator*/ 
 
176
    do_work();
 
177
 
 
178
    if(me==0)printf("Terminating ..\n");
 
179
    GA_Terminate();
 
180
 
 
181
#   ifdef MPI
 
182
      MPI_Finalize();
 
183
#   else
 
184
      tcg_pend();
 
185
#   endif
 
186
 
 
187
    return 0;
 
188
}
 
189