~james-page/ubuntu/precise/openmpi1.5/new

« back to all changes in this revision

Viewing changes to orte/test/mpi/simple_spawn.c

  • Committer: Bazaar Package Importer
  • Author(s): Manuel Prinz
  • Date: 2009-04-23 14:01:21 UTC
  • mfrom: (1.1.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20090423140121-vsi3pqa6g30j4qiy
Tags: 1.3.2-1
* New upstream release. (Closes: #520597, #515116)
  - Manpage and VampirTrace patches removed, included upstream.
* Fixed build issues on Alpha. Huge thanks to Arthur Loiret for providing
  access to his machines for testing! (Closes: #510845, #517543)
* Fixed build issues on Sparc. (Closes: #519725)
* Fixed manpage-has-errors-from-man lintian warnings.
* Faked SONAME change by renaming library package. (Closes: #512616)
* Made libopenmpi-dev depend on libibverbs-dev. (Closes: #522153)
* Support for "nocheck" build option in debian/rules.
* Updated Standards-Version in debian/control.
* Changed section of libopenmpi-dbg to "debug".
* Updated debian/copyright.

* Dirk Eddelbuettel removed himself from Uploaders. The team thanks Dirk
  for his long-term contribution and effort to get Open MPI back to life.
  I personally thank Dirk for encouraging me to become a Debian Developer
  and his support and mentoring on that way and beyond.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <stdio.h>
 
2
#include <sys/types.h>
 
3
 
 
4
#include <mpi.h>
 
5
 
 
6
int main(int argc, char* argv[])
 
7
{
 
8
    int msg, rc;
 
9
    MPI_Comm parent, child;
 
10
    int rank, size;
 
11
    char hostname[512];
 
12
    pid_t pid;
 
13
 
 
14
        pid = getpid();
 
15
        printf("Parent [pid %ld] starting up!\n", (long)pid);
 
16
    MPI_Init(NULL, NULL);
 
17
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
 
18
printf("%d completed MPI_Init\n", rank);
 
19
    MPI_Comm_size(MPI_COMM_WORLD, &size);
 
20
    MPI_Comm_get_parent(&parent);
 
21
    /* If we get COMM_NULL back, then we're the parent */
 
22
    if (MPI_COMM_NULL == parent) {
 
23
        pid = getpid();
 
24
        printf("Parent [pid %ld] about to spawn!\n", (long)pid);
 
25
        if (MPI_SUCCESS != (rc = MPI_Comm_spawn(argv[0], MPI_ARGV_NULL, 3, MPI_INFO_NULL, 
 
26
                       0, MPI_COMM_WORLD, &child, MPI_ERRCODES_IGNORE))) {
 
27
            printf("Child failed to spawn\n");
 
28
            return rc;
 
29
        }
 
30
        printf("Parent done with spawn\n");
 
31
        if (0 == rank) {
 
32
            msg = 38;
 
33
            printf("Parent sending message to child\n");
 
34
            MPI_Send(&msg, 1, MPI_INT, 0, 1, child);
 
35
        }
 
36
        MPI_Comm_disconnect(&child);
 
37
        printf("Parent disconnected\n");
 
38
    } 
 
39
    /* Otherwise, we're the child */
 
40
    else {
 
41
        MPI_Comm_rank(MPI_COMM_WORLD, &rank);
 
42
        MPI_Comm_size(MPI_COMM_WORLD, &size);
 
43
        gethostname(hostname, 512);
 
44
        pid = getpid();
 
45
        printf("Hello from the child %d of %d on host %s pid %ld\n", rank, 3, hostname, (long)pid);
 
46
        if (0 == rank) {
 
47
            MPI_Recv(&msg, 1, MPI_INT, 0, 1, parent, MPI_STATUS_IGNORE);
 
48
            printf("Child %d received msg: %d\n", rank, msg);
 
49
        }
 
50
        MPI_Comm_disconnect(&parent);
 
51
        printf("Child %d disconnected\n", rank);
 
52
    }
 
53
 
 
54
    MPI_Finalize();
 
55
    return 0;
 
56
}