File: chapter_10_mpi2.cc

package info (click to toggle)
lam 7.1.2-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 54,668 kB
  • ctags: 17,034
  • sloc: ansic: 156,264; sh: 9,976; cpp: 7,699; makefile: 5,590; perl: 476; fortran: 260; asm: 83
file content (109 lines) | stat: -rw-r--r-- 2,450 bytes parent folder | download | duplicates (9)
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
// -*- c++ -*-
//
// $Id: chapter_10_mpi2.cc,v 1.4 2002/11/23 04:06:44 jsquyres Exp $
//
// Copyright (c) 2001-2002 The Trustees of Indiana University.  
//                         All rights reserved.
// Copyright (c) 1998-2001 University of Notre Dame. 
//                         All rights reserved.
// Copyright (c) 1994-1998 The Ohio State University.  
//                         All rights reserved.
// 
// This file is part of the LAM/MPI software package.  For license
// information, see the LICENSE file in the top level directory of the
// LAM/MPI source distribution.
// 
// $HEADER$
// 

#include <iostream>
#include <mpi.h>

using namespace std;


void example10_2(void);
void example10_3(void);
void example10_4(void);
void example10_5(void);

// Example 10.1 - Please note foocomm is not foo_comm as on Page 273
// so it will not conflict with later uses of foo_comm.

class foocomm : public MPI::Intracomm {
public:
  void Send(const void* buf, int count, const MPI::Datatype& type,
	    int dest, int tag) const
  {
    // Class library functionality
    MPI::Intracomm::Send(buf, count, type, dest, tag);
    // More class library functionality
  }
};

int
main(int argc, char *argv[])
{
  MPI::Init(argc, argv);

  example10_2();
  
  example10_3();
  
  example10_4();

  example10_5();

  MPI::Finalize();
  return 0;
}
  
// Example 10.2

void
example10_2()
{
  MPI::Intracomm bar;
  if (bar == MPI::COMM_NULL)
    cout << "bar is MPI::COMM_NULL" << endl;
}

// Example 10.3

void
example10_3()
{
  MPI::Intracomm foo_comm, bar_comm, baz_comm;
  foo_comm = MPI::COMM_WORLD;
  bar_comm = MPI::COMM_WORLD.Dup();
  baz_comm = bar_comm;
  cout << "Is foocomm equal barcomm? " << (foo_comm == bar_comm) << endl;
  cout << "Is bazcomm equal barcomm? " << (baz_comm == bar_comm) << endl;
}

// Example 10.4 Erroneous Code

void
example10_4()
{
  MPI::Intracomm intra = MPI::COMM_WORLD.Dup();

  // This will show up as an unused variable if compiled with full
  // warnings on, but we keep it here a) because it's in Chapter 10,
  // and b) to show that it works and compiles properly

  MPI::Cartcomm cart(intra);
}

// Example 10.5

void
example10_5()
{
  MPI::Intercomm comm;
  comm = MPI::COMM_NULL;            // assign with COMM_NULL
  if (comm == MPI::COMM_NULL)       // true
    cout << "comm is NULL" << endl;
  if (MPI::COMM_NULL == comm)       // note -- a different function
    cout << "comm is still NULL" << endl;
}