Statistics
| Branch: | Revision:

root / synthbench / euroben-ports / base / C-MPI / mod2f / .svn / text-base / check.c.svn-base @ 0:839f52ef7657

History | View | Annotate | Download (2.1 kB)

1
#include <math.h>
2
#include <mpi.h>
3
#include "mpiargs.h"
4

    
5
int check( int m, int n, double **a, double **b, double err )
6
//----------------------------------------------------------------------
7
//--- 'check' checks the errors made in the transformation of a
8
//    complex-to-complex FFT. 'check' is specific for the input
9
//    of this program.
10
//    The Real part is a full cycle of a cosine signal and the
11
//    Imaginary part is 0.0 everywhere.
12
//    The resulting transform should show values of N/2 for
13
//    A[1] and A[N-1]. All other entries should be 0.0.
14
//    This is checked below with a Floating-Point error
15
//    margin of ERR = ( 10.0*N Log N )*EPS, with EPS the
16
//    Floating-Point spacing of the machine tested.
17
//--- The Real part of A is stored in A[0], ..., A[N-1];
18
//    The Imaginary part in B[0], ..., B[N-1].
19
//----------------------------------------------------------------------
20
{
21
   MPI_Comm comm = MPI_COMM_WORLD;
22
   int      i, j, nlen, ok = 0, all_ok = 0;
23
//----------------------------------------------------------------------
24
   nlen = m*n*nodes;
25
   for( i = 0; i < m; i++ ) {              // Check imaginary elements.
26
      for( j = 0; j < n; j++ ) {
27
         if ( fabs( b[i][j] ) > err ) ok++;
28
      }
29
   } 
30
   if ( me == 0 )                         // Check 1st elem. in nodes 0.
31
      if ( fabs( a[0][0] ) > err ) ok++;
32
   if ( me != 0 && me != nodes - 1 ) {    // Check all real elem. in
33
      for( i = 0; i < m; i++ ) {          // nodes 1..(nodes-2).
34
         for( j = 0; j < n; j++ ) {
35
            if ( fabs( a[i][j] ) > err ) ok++;
36
         }
37
      }
38
   }
39
   if ( me == 0 ) {                      // Check real part of transform
40
      for( j = 2; j < n; j++ ) {         // in node 0 that should be 0.
41
         if ( fabs( a[0][j] ) > err ) ok++;
42
      }
43
   }
44
   if ( me == 0 )                        // Check 1st non-zero element.
45
      if( fabs( a[0][1] ) - (double)nlen/2 > err ) ok++;
46
   if ( me == ( nodes - 1 ) )                // Check 2nd non-zero element.
47
      if ( fabs( a[m-1][n-1] ) - (double)nlen/2 > err ) ok++;
48
   MPI_Reduce( &ok, &all_ok, 1, MPI_INT, MPI_SUM, 0, comm );
49
   return( all_ok );
50
}