~ubuntu-branches/ubuntu/raring/simgrid/raring

« back to all changes in this revision

Viewing changes to teshsuite/smpi/mpich-test/coll/scattern.c

  • Committer: Package Import Robot
  • Author(s): Martin Quinson
  • Date: 2013-01-31 00:24:51 UTC
  • mfrom: (10.1.6 sid)
  • Revision ID: package-import@ubuntu.com-20130131002451-krejhf7w7h24lpsc
Tags: 3.9~rc1-1
* New upstream release: the "Grasgory" release. Major changes:
  - Gras was completely removed from this version.
  - Documentation reorganization to ease browsing it.
  - New default value for the TCP_gamma parameter: 4MiB

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "mpi.h"
 
2
#include <stdlib.h>
 
3
#include <stdio.h>
 
4
#include "test.h" 
 
5
 
 
6
/* This example sends a vector and receives individual elements */
 
7
 
 
8
int main( int argc, char **argv )
 
9
{
 
10
    MPI_Datatype vec;
 
11
    double *vecin, *vecout, ivalue;
 
12
    int    root, i, n, stride, err = 0;
 
13
    int    rank, size;
 
14
 
 
15
    MPI_Init( &argc, &argv );
 
16
    
 
17
    MPI_Comm_size( MPI_COMM_WORLD, &size );
 
18
    MPI_Comm_rank( MPI_COMM_WORLD, &rank );
 
19
 
 
20
    n = 12;
 
21
    stride = 10;
 
22
    vecin = (double *)malloc( n * stride * size * sizeof(double) );
 
23
    vecout = (double *)malloc( n * sizeof(double) );
 
24
    
 
25
    MPI_Type_vector( n, 1, stride, MPI_DOUBLE, &vec );
 
26
    MPI_Type_commit( &vec );
 
27
 
 
28
    for (i=0; i<n*stride*size; i++) vecin[i] = (double)i;
 
29
    for (root=0; root<size; root++) {
 
30
        for (i=0; i<n; i++) vecout[i] = -1.0;
 
31
        MPI_Scatter( vecin, 1, vec, vecout, n, MPI_DOUBLE, root, 
 
32
                     MPI_COMM_WORLD );
 
33
        ivalue = rank * ((n-1) * stride + 1);
 
34
        for (i=0; i<n; i++) {
 
35
            if (vecout[i] != ivalue) {
 
36
                printf( "Expected %f but found %f\n", 
 
37
                        ivalue, vecout[i] );
 
38
                err++;
 
39
            }
 
40
            ivalue += stride;
 
41
        }
 
42
    }
 
43
    i = err;
 
44
    MPI_Allreduce( &i, &err, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD );
 
45
    if (rank == 0) {
 
46
        if (err > 0) printf( "Found %d errors!\n", err );
 
47
        else         printf( " No Errors\n" );
 
48
    }
 
49
    MPI_Type_free( &vec );
 
50
    MPI_Finalize();
 
51
    return 0;
 
52
       
 
53
}
 
54