~ubuntu-branches/ubuntu/saucy/nwchem/saucy

« back to all changes in this revision

Viewing changes to src/tools/ga-4-3/global/testing/ga-mpi.c

  • Committer: Package Import Robot
  • Author(s): Michael Banck, Michael Banck, Daniel Leidert
  • Date: 2012-02-09 20:02:41 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20120209200241-jgk03qfsphal4ug2
Tags: 6.1-1
* New upstream release.

[ Michael Banck ]
* debian/patches/02_makefile_flags.patch: Updated.
* debian/patches/02_makefile_flags.patch: Use internal blas and lapack code.
* debian/patches/02_makefile_flags.patch: Define GCC4 for LINUX and LINUX64
  (Closes: #632611 and LP: #791308).
* debian/control (Build-Depends): Added openssh-client.
* debian/rules (USE_SCALAPACK, SCALAPACK): Removed variables (Closes:
  #654658).
* debian/rules (LIBDIR, USE_MPIF4, ARMCI_NETWORK): New variables.
* debian/TODO: New file.
* debian/control (Build-Depends): Removed libblas-dev, liblapack-dev and
  libscalapack-mpi-dev.
* debian/patches/04_show_testsuite_diff_output.patch: New patch, shows the
  diff output for failed tests.
* debian/patches/series: Adjusted.
* debian/testsuite: Optionally run all tests if "all" is passed as option.
* debian/rules: Run debian/testsuite with "all" if DEB_BUILD_OPTIONS
  contains "checkall".

[ Daniel Leidert ]
* debian/control: Used wrap-and-sort. Added Vcs-Svn and Vcs-Browser fields.
  (Priority): Moved to extra according to policy section 2.5.
  (Standards-Version): Bumped to 3.9.2.
  (Description): Fixed a typo.
* debian/watch: Added.
* debian/patches/03_hurd-i386_define_path_max.patch: Added.
  - Define MAX_PATH if not defines to fix FTBFS on hurd.
* debian/patches/series: Adjusted.

Show diffs side-by-side

added added

removed removed

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