diff --git a/docs.it4i/software/mpi/ompi-examples.md b/docs.it4i/software/mpi/ompi-examples.md new file mode 100644 index 0000000000000000000000000000000000000000..912f7d3487bdac5fb729a87ed34bb022385a689d --- /dev/null +++ b/docs.it4i/software/mpi/ompi-examples.md @@ -0,0 +1,108 @@ +# OpenMPI Sample Applications + +Sample MPI applications provided both as a trivial primer to MPI as well as simple tests to ensure that your Open MPI installation is working properly. + +## Examples + +There are two MPI examples, each using one of six different MPI interfaces: + +**Hello world** + +* C: [hello_c.c](../../src/ompi/hello_c.c) +* C++: [hello_cxx.cc](../../src/ompi/hello_cxx.cc) +* Fortran mpif.h: [hello_mpifh.f](../../src/ompi/hello_mpifh.f) +* Fortran use mpi: [hello_usempi.f90](../../src/ompi/hello_usempi.f90) +* Fortran use mpi_f08: [hello_usempif08.f90](../../src/ompi/hello_usempif08.f90) +* Java: [Hello.java](../../src/ompi/Hello.java) +* C shmem.h: [hello_oshmem_c.c](../../src/ompi/hello_oshmem_c.c) +* Fortran shmem.fh: [hello_oshmemfh.f90](../../src/ompi/hello_oshmemfh.f90) + +**Send a trivial message around in a ring** + +* C: [ring_c.c](../../src/ompi/ring_c.c) +* C++: [ring_cxx.cc](../../src/ompi/ring_cxx.cc) +* Fortran mpif.h: [ring_mpifh.f](../../src/ompi/ring_mpifh.f) +* Fortran use mpi: [ring_usempi.f90](../../src/ompi/ring_usempi.f90) +* Fortran use mpi_f08: [ring_usempif08.f90](../../src/ompi/ring_usempif08.f90) +* Java: [Ring.java](../../src/ompi/Ring.java) +* C shmem.h: [ring_oshmem_c.c](../../src/ompi/ring_oshmem_c.c) +* Fortran shmem.fh: [ring_oshmemfh.f90](../../src/ompi/ring_oshmemfh.f90) + +Additionally, there's one further example application, but this one only uses the MPI C bindings: + +**Test the connectivity between all processes** + +* C: [connectivity_c.c](../../src/ompi/connectivity_c.c) + +## Build Examples + +Download [examples](../../src/ompi/ompi.tar.gz). + +The Makefile in this directory will build the examples for the supported languages (e.g., if you do not have the Fortran "use mpi" bindings compiled as part of Open MPI, those examples will be skipped). + +The Makefile assumes that the wrapper compilers mpicc, mpic++, and mpifort are in your path. + +Although the Makefile is tailored for Open MPI (e.g., it checks the *mpi_info* command to see if you have support for C++, mpif.h, use mpi, and use mpi_f08 F90), all of the example programs are pure MPI, and therefore not specific to Open MPI. Hence, you can use a different MPI implementation to compile and run these programs if you wish. + +```console +[login@cn204.anselm ]$ tar xvf ompi.tar.gz +./ +./connectivity_c.c +./Hello.java +./ring_mpifh.f +./hello_oshmem_cxx.cc +... +... +./hello_cxx.cc +[login@cn204.anselm ]$ ml OpenMPI/2.1.1-GCC-6.3.0-2.27 +[login@cn204.anselm ]$ make +mpicc -g hello_c.c -o hello_c +mpicc -g ring_c.c -o ring_c +mpicc -g connectivity_c.c -o connectivity_c +mpicc -g spc_example.c -o spc_example +mpic++ -g hello_cxx.cc -o hello_cxx +mpic++ -g ring_cxx.cc -o ring_cxx +mpifort -g hello_mpifh.f -o hello_mpifh +mpifort -g ring_mpifh.f -o ring_mpifh +mpifort -g hello_usempi.f90 -o hello_usempi +mpifort -g ring_usempi.f90 -o ring_usempi +mpifort -g hello_usempif08.f90 -o hello_usempif08 +mpifort -g ring_usempif08.f90 -o ring_usempif08 +mpijavac Hello.java +mpijavac Ring.java +shmemcc -g hello_oshmem_c.c -o hello_oshmem +shmemc++ -g hello_oshmem_cxx.cc -o hello_oshmemcxx +shmemcc -g ring_oshmem_c.c -o ring_oshmem +shmemcc -g oshmem_shmalloc.c -o oshmem_shmalloc +shmemcc -g oshmem_circular_shift.c -o oshmem_circular_shift +shmemcc -g oshmem_max_reduction.c -o oshmem_max_reduction +shmemcc -g oshmem_strided_puts.c -o oshmem_strided_puts +shmemcc -g oshmem_strided_puts.c -o oshmem_strided_puts +shmemcc -g oshmem_symmetric_data.c -o oshmem_symmetric_data +shmemfort -g hello_oshmemfh.f90 -o hello_oshmemfh +shmemfort -g ring_oshmemfh.f90 -o ring_oshmemfh +[login@cn204.anselm ]$ find . -executable -type f +./hello_oshmem +./dtrace/myppriv.sh +./dtrace/partrace.sh +./oshmem_shmalloc +./ring_cxx +./ring_usempi +./hello_mpifh +./hello_cxx +./oshmem_max_reduction +./oshmem_symmetric_data +./oshmem_strided_puts +./hello_usempif08 +./ring_usempif08 +./spc_example +./hello_oshmemfh +./ring_oshmem +./oshmem_circular_shift +./hello_c +./ring_c +./hello_usempi +./ring_oshmemfh +./connectivity_c +./ring_mpifh +``` diff --git a/docs.it4i/src/ompi/Hello.java b/docs.it4i/src/ompi/Hello.java new file mode 100644 index 0000000000000000000000000000000000000000..4f2ac4cfb15b0edd31e35e74ecce307e41a631be --- /dev/null +++ b/docs.it4i/src/ompi/Hello.java @@ -0,0 +1,39 @@ +/* + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ +/* + * Author of revised version: Franklyn Pinedo + * + * Adapted from Source Code in C of Tutorial/User's Guide for MPI by + * Peter Pacheco. + */ +/* + * Copyright (c) 2011 Cisco Systems, Inc. All rights reserved. + * + */ + +import mpi.*; + +class Hello { + static public void main(String[] args) throws MPIException { + + + MPI.Init(args); + + int myrank = MPI.COMM_WORLD.getRank(); + int size = MPI.COMM_WORLD.getSize() ; + System.out.println("Hello world from rank " + myrank + " of " + size); + + MPI.Finalize(); + } +} diff --git a/docs.it4i/src/ompi/Ring.java b/docs.it4i/src/ompi/Ring.java new file mode 100644 index 0000000000000000000000000000000000000000..08cd864663e6cde304ec4adc509662ff2854b7de --- /dev/null +++ b/docs.it4i/src/ompi/Ring.java @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2011 Cisco Systems, Inc. All rights reserved. + * + * Simple ring test program + */ + +import mpi.* ; + +class Ring { + static public void main(String[] args) throws MPIException { + + + MPI.Init(args) ; + + int source; // Rank of sender + int dest; // Rank of receiver + int tag=50; // Tag for messages + int next; + int prev; + int message[] = new int [1]; + + int myrank = MPI.COMM_WORLD.getRank() ; + int size = MPI.COMM_WORLD.getSize() ; + + /* Calculate the rank of the next process in the ring. Use the + modulus operator so that the last process "wraps around" to + rank zero. */ + + next = (myrank + 1) % size; + prev = (myrank + size - 1) % size; + + /* If we are the "master" process (i.e., MPI_COMM_WORLD rank 0), + put the number of times to go around the ring in the + message. */ + + if (0 == myrank) { + message[0] = 10; + + System.out.println("Process 0 sending " + message[0] + " to rank " + next + " (" + size + " processes in ring)"); + MPI.COMM_WORLD.send(message, 1, MPI.INT, next, tag); + } + + /* Pass the message around the ring. The exit mechanism works as + follows: the message (a positive integer) is passed around the + ring. Each time it passes rank 0, it is decremented. When + each processes receives a message containing a 0 value, it + passes the message on to the next process and then quits. By + passing the 0 message first, every process gets the 0 message + and can quit normally. */ + + while (true) { + MPI.COMM_WORLD.recv(message, 1, MPI.INT, prev, tag); + + if (0 == myrank) { + --message[0]; + System.out.println("Process 0 decremented value: " + message[0]); + } + + MPI.COMM_WORLD.send(message, 1, MPI.INT, next, tag); + if (0 == message[0]) { + System.out.println("Process " + myrank + " exiting"); + break; + } + } + + /* The last process does one extra send to process 0, which needs + to be received before the program can exit */ + + if (0 == myrank) { + MPI.COMM_WORLD.recv(message, 1, MPI.INT, prev, tag); + } + + MPI.Finalize(); + } +} diff --git a/docs.it4i/src/ompi/connectivity_c.c b/docs.it4i/src/ompi/connectivity_c.c new file mode 100644 index 0000000000000000000000000000000000000000..14f3f546d532f0f1fa59d33e0a5b0a89eed8f0fa --- /dev/null +++ b/docs.it4i/src/ompi/connectivity_c.c @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved. + */ + +/* + * Test the connectivity between all processes. + */ + +#include <errno.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <netdb.h> +#include <unistd.h> +#include <mpi.h> + +int +main(int argc, char **argv) +{ + MPI_Status status; + int verbose = 0; + int rank; + int np; /* number of processes in job */ + int peer; + int i; + int j; + int length; + char name[MPI_MAX_PROCESSOR_NAME+1]; + + MPI_Init(&argc, &argv); + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &np); + + /* + * If we cannot get the name for whatever reason, just + * set it to unknown. */ + if (MPI_SUCCESS != MPI_Get_processor_name(name, &length)) { + strcpy(name, "unknown"); + } + + if (argc>1 && strcmp(argv[1], "-v")==0) + verbose = 1; + + for (i=0; i<np; i++) { + if (rank==i) { + /* rank i sends to and receives from each higher rank */ + for(j=i+1; j<np; j++) { + if (verbose) + printf("checking connection between rank %d on %s and rank %-4d\n", + i, name, j); + MPI_Send(&rank, 1, MPI_INT, j, rank, MPI_COMM_WORLD); + MPI_Recv(&peer, 1, MPI_INT, j, j, MPI_COMM_WORLD, &status); + } + } else if (rank>i) { + /* receive from and reply to rank i */ + MPI_Recv(&peer, 1, MPI_INT, i, i, MPI_COMM_WORLD, &status); + MPI_Send(&rank, 1, MPI_INT, i, rank, MPI_COMM_WORLD); + } + } + + MPI_Barrier(MPI_COMM_WORLD); + if (rank==0) + printf("Connectivity test on %d processes PASSED.\n", np); + + MPI_Finalize(); + return 0; +} diff --git a/docs.it4i/src/ompi/hello_c.c b/docs.it4i/src/ompi/hello_c.c new file mode 100644 index 0000000000000000000000000000000000000000..e44f684370214442829f92adbb4455e7a559474f --- /dev/null +++ b/docs.it4i/src/ompi/hello_c.c @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2004-2006 The Trustees of Indiana University and Indiana + * University Research and Technology + * Corporation. All rights reserved. + * Copyright (c) 2006 Cisco Systems, Inc. All rights reserved. + * + * Sample MPI "hello world" application in C + */ + +#include <stdio.h> +#include "mpi.h" + +int main(int argc, char* argv[]) +{ + int rank, size, len; + char version[MPI_MAX_LIBRARY_VERSION_STRING]; + + MPI_Init(&argc, &argv); + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &size); + MPI_Get_library_version(version, &len); + printf("Hello, world, I am %d of %d, (%s, %d)\n", + rank, size, version, len); + MPI_Finalize(); + + return 0; +} diff --git a/docs.it4i/src/ompi/hello_cxx.cc b/docs.it4i/src/ompi/hello_cxx.cc new file mode 100644 index 0000000000000000000000000000000000000000..b2253bfb8e58699a8c8ffec24e71cdd4a8e0609e --- /dev/null +++ b/docs.it4i/src/ompi/hello_cxx.cc @@ -0,0 +1,34 @@ +// +// Copyright (c) 2004-2006 The Trustees of Indiana University and Indiana +// University Research and Technology +// Corporation. All rights reserved. +// Copyright (c) 2006 Cisco Systems, Inc. All rights reserved. +// +// Sample MPI "hello world" application in C++ +// +// NOTE: The MPI C++ bindings were deprecated in MPI-2.2 and removed +// from the standard in MPI-3. Open MPI still provides C++ MPI +// bindings, but they are no longer built by default (and may be +// removed in a future version of Open MPI). You must +// --enable-mpi-cxx when configuring Open MPI to enable the MPI C++ +// bindings. +// + +#include "mpi.h" +#include <iostream> + +int main(int argc, char **argv) +{ + int rank, size, len; + char version[MPI_MAX_LIBRARY_VERSION_STRING]; + + MPI::Init(); + rank = MPI::COMM_WORLD.Get_rank(); + size = MPI::COMM_WORLD.Get_size(); + MPI_Get_library_version(version, &len); + std::cout << "Hello, world! I am " << rank << " of " << size + << "(" << version << ", " << len << ")" << std::endl; + MPI::Finalize(); + + return 0; +} diff --git a/docs.it4i/src/ompi/hello_mpifh.f b/docs.it4i/src/ompi/hello_mpifh.f new file mode 100644 index 0000000000000000000000000000000000000000..a2ff38f964007c02aa4642249bb40b695695bf44 --- /dev/null +++ b/docs.it4i/src/ompi/hello_mpifh.f @@ -0,0 +1,27 @@ +C +C Copyright (c) 2004-2006 The Trustees of Indiana University and Indiana +C University Research and Technology +C Corporation. All rights reserved. +C Copyright (c) 2006-2015 Cisco Systems, Inc. All rights reserved. +C $COPYRIGHT$ +C +C Sample MPI "hello world" application using the Fortran mpif.h +C bindings. +C + program main + implicit none + include 'mpif.h' + integer ierr, rank, size, len + character(len=MPI_MAX_LIBRARY_VERSION_STRING) version + + call MPI_INIT(ierr) + call MPI_COMM_RANK(MPI_COMM_WORLD, rank, ierr) + call MPI_COMM_SIZE(MPI_COMM_WORLD, size, ierr) + call MPI_GET_LIBRARY_VERSION(version, len, ierr) + + write(*, '("Hello, world, I am ", i2, " of ", i2, ": ", a)') + & rank, size, version + + call MPI_FINALIZE(ierr) + + end diff --git a/docs.it4i/src/ompi/hello_oshmem_c.c b/docs.it4i/src/ompi/hello_oshmem_c.c new file mode 100644 index 0000000000000000000000000000000000000000..6bb0d08c06255d29dc4883195c325542c0dbedd4 --- /dev/null +++ b/docs.it4i/src/ompi/hello_oshmem_c.c @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2014 Mellanox Technologies, Inc. + * All rights reserved. + * Copyright (c) 2015 Cisco Systems, Inc. All rights reserved. + * $COPYRIGHT$ + * + * Additional copyrights may follow + * + * $HEADER$ + */ + +#include <stdio.h> +#include "shmem.h" + +#if !defined(OSHMEM_SPEC_VERSION) || OSHMEM_SPEC_VERSION < 10200 +#error This application uses API 1.2 and up +#endif + +int main(int argc, char* argv[]) +{ + int proc, nproc; + char name[SHMEM_MAX_NAME_LEN]; + int major, minor; + + shmem_init(); + nproc = shmem_n_pes(); + proc = shmem_my_pe(); + shmem_info_get_name(name); + shmem_info_get_version(&major, &minor); + + printf("Hello, world, I am %d of %d: %s (version: %d.%d)\n", + proc, nproc, name, major, minor); + shmem_finalize(); + + return 0; +} diff --git a/docs.it4i/src/ompi/hello_oshmem_cxx.cc b/docs.it4i/src/ompi/hello_oshmem_cxx.cc new file mode 100644 index 0000000000000000000000000000000000000000..99d8565c8a53b2b0a23bc32edf1637f1ead10748 --- /dev/null +++ b/docs.it4i/src/ompi/hello_oshmem_cxx.cc @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2014 Mellanox Technologies, Inc. + * All rights reserved. + * Copyright (c) 2015 Cisco Systems, Inc. All rights reserved. + * Copyright (c) 2017 Research Organization for Information Science + * and Technology (RIST). All rights reserved. + * $COPYRIGHT$ + * + * Additional copyrights may follow + * + * $HEADER$ + */ + +#include <iostream> +#include "shmem.h" + +#if !defined(OSHMEM_SPEC_VERSION) || OSHMEM_SPEC_VERSION < 10200 +#error This application uses API 1.2 and up +#endif + +int main(int argc, char* argv[]) +{ + int proc, nproc; + char name[SHMEM_MAX_NAME_LEN]; + int major, minor; + + shmem_init(); + nproc = shmem_n_pes(); + proc = shmem_my_pe(); + shmem_info_get_name(name); + shmem_info_get_version(&major, &minor); + + std::cout << "Hello, world, I am " << proc << " of " << nproc << ": " << name + << " (version: " << major << "." << minor << ")" << std::endl; + + shmem_finalize(); + + return 0; +} diff --git a/docs.it4i/src/ompi/hello_oshmemfh.f90 b/docs.it4i/src/ompi/hello_oshmemfh.f90 new file mode 100644 index 0000000000000000000000000000000000000000..09404c3bb8aa650a63c7a72e177a3cb6a61e88a0 --- /dev/null +++ b/docs.it4i/src/ompi/hello_oshmemfh.f90 @@ -0,0 +1,29 @@ +! +! Copyright (c) 2014 Mellanox Technologies, Inc. +! All rights reserved. +! Copyright (c) 2014-2015 Cisco Systems, Inc. All rights reserved. +! $COPYRIGHT$ +! +! Additional copyrights may follow +! +! $HEADER$ +! +program hello_oshmem + implicit none + include 'shmem.fh' + + integer proc, nproc + integer shmem_my_pe, shmem_n_pes + integer major, minor, len + character(len=SHMEM_MAX_NAME_LEN) name + + call SHMEM_INIT() + proc = SHMEM_MY_PE() + nproc = SHMEM_N_PES() + call SHMEM_INFO_GET_VERSION(major, minor) + call SHMEM_INFO_GET_NAME(name) + + write(*, '("Hello, world, I am ", i2, " of ", i2, ": (version: ", i0, ".", i0, ")")') proc, nproc, major, minor + call SHMEM_FINALIZE() + +end program hello_oshmem diff --git a/docs.it4i/src/ompi/hello_usempi.f90 b/docs.it4i/src/ompi/hello_usempi.f90 new file mode 100644 index 0000000000000000000000000000000000000000..3fc7a9be31bc3902db58b2d3000e3a7bf870b642 --- /dev/null +++ b/docs.it4i/src/ompi/hello_usempi.f90 @@ -0,0 +1,28 @@ +! +! Copyright (c) 2004-2006 The Trustees of Indiana University and Indiana +! University Research and Technology +! Corporation. All rights reserved. +! Copyright (c) 2004-2005 The Regents of the University of California. +! All rights reserved. +! Copyright (c) 2006-2015 Cisco Systems, Inc. All rights reserved. +! $COPYRIGHT$ +! +! Sample MPI "hello world" application using the Fortran mpi module +! bindings. +! +program main + use mpi + implicit none + integer :: ierr, rank, size, len + character(len=MPI_MAX_LIBRARY_VERSION_STRING) :: version + + call MPI_INIT(ierr) + call MPI_COMM_RANK(MPI_COMM_WORLD, rank, ierr) + call MPI_COMM_SIZE(MPI_COMM_WORLD, size, ierr) + call MPI_GET_LIBRARY_VERSION(version, len, ierr) + + write(*, '("Hello, world, I am ", i2, " of ", i2, ": ", a)') & + rank, size, version + + call MPI_FINALIZE(ierr) +end diff --git a/docs.it4i/src/ompi/hello_usempif08.f90 b/docs.it4i/src/ompi/hello_usempif08.f90 new file mode 100644 index 0000000000000000000000000000000000000000..e4af17bb6aefe4e982ab3a668ff13b97ddf2247f --- /dev/null +++ b/docs.it4i/src/ompi/hello_usempif08.f90 @@ -0,0 +1,31 @@ +! -*- f90 -*- +! +! Copyright (c) 2004-2006 The Trustees of Indiana University and Indiana +! University Research and Technology +! Corporation. All rights reserved. +! Copyright (c) 2004-2005 The Regents of the University of California. +! All rights reserved. +! Copyright (c) 2006-2015 Cisco Systems, Inc. All rights reserved. +! Copyright (c) 2009-2012 Los Alamos National Security, LLC. +! All rights reserved. +! $COPYRIGHT$ +! +! Sample MPI "hello world" application using the Fortran mpi_f08 +! module bindings. +! +program main + use mpi_f08 + implicit none + integer :: rank, size, len + character(len=MPI_MAX_LIBRARY_VERSION_STRING) :: version + + call MPI_INIT() + call MPI_COMM_RANK(MPI_COMM_WORLD, rank) + call MPI_COMM_SIZE(MPI_COMM_WORLD, size) + call MPI_GET_LIBRARY_VERSION(version, len) + + write(*, '("Hello, world, I am ", i2, " of ", i2, ": ", a)') & + rank, size, version + + call MPI_FINALIZE() +end diff --git a/docs.it4i/src/ompi/ompi.tar.gz b/docs.it4i/src/ompi/ompi.tar.gz new file mode 100644 index 0000000000000000000000000000000000000000..8963b12eb39167bf1357a6c8877b8d6bd160ed5d Binary files /dev/null and b/docs.it4i/src/ompi/ompi.tar.gz differ diff --git a/docs.it4i/src/ompi/oshmem_circular_shift.c b/docs.it4i/src/ompi/oshmem_circular_shift.c new file mode 100644 index 0000000000000000000000000000000000000000..3ff2d6d0c87d85dfe3777c934c00fc8f85e799ae --- /dev/null +++ b/docs.it4i/src/ompi/oshmem_circular_shift.c @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2014-2016 Mellanox Technologies, Inc. + * All rights reserved. + * $COPYRIGHT$ + * + * Additional copyrights may follow + * + * $HEADER$ + */ + +#include <stdio.h> +#include <shmem.h> + +int main (void) +{ + static int aaa, bbb; + int num_pes, my_pe, peer; + + shmem_init(); + + num_pes = shmem_n_pes(); + my_pe = shmem_my_pe(); + + peer = (my_pe + 1) % num_pes; + + printf("Process %d gets message from %d (%d processes in ring)\n", my_pe, peer, num_pes); + shmem_int_get(&aaa, &bbb, 1, peer); + + shmem_barrier_all(); + printf("Process %d exiting\n", my_pe); + shmem_finalize(); + + return 0; +} + diff --git a/docs.it4i/src/ompi/oshmem_max_reduction.c b/docs.it4i/src/ompi/oshmem_max_reduction.c new file mode 100644 index 0000000000000000000000000000000000000000..d0dec673af2a331fe7bcd3388478a18c253b007f --- /dev/null +++ b/docs.it4i/src/ompi/oshmem_max_reduction.c @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2014-2016 Mellanox Technologies, Inc. + * All rights reserved. + * $COPYRIGHT$ + * + * Additional copyrights may follow + * + * $HEADER$ + * + * reduce [0,1,2] + _my_pe() across 4 PEs with MAX() + */ + +#include <stdio.h> +#include <string.h> + +#include <shmem.h> + +long pSync[_SHMEM_BCAST_SYNC_SIZE]; + +#define N 3 + +long src[N]; +long dst[N]; +long pWrk[_SHMEM_REDUCE_SYNC_SIZE]; + +int main(void) +{ + int i; + int my_pe, num_pes; + + for (i = 0; i < SHMEM_BCAST_SYNC_SIZE; i += 1) { + pSync[i] = _SHMEM_SYNC_VALUE; + } + + shmem_init(); + + my_pe = shmem_my_pe(); + num_pes = shmem_n_pes(); + + for (i = 0; i < N; i += 1) { + src[i] = my_pe + i; + } + + shmem_barrier_all(); + + shmem_long_max_to_all(dst, src, N, 0, 0, num_pes, pWrk, pSync); + + printf("%d/%d dst =", my_pe, num_pes); + + for (i = 0; i < N; i+= 1) { + printf(" %ld", dst[i]); + } + + printf("\n"); + shmem_finalize(); + + return 0; +} + diff --git a/docs.it4i/src/ompi/oshmem_shmalloc.c b/docs.it4i/src/ompi/oshmem_shmalloc.c new file mode 100644 index 0000000000000000000000000000000000000000..e5f9ab9090738a64623bd16e2147e3dc82fbd584 --- /dev/null +++ b/docs.it4i/src/ompi/oshmem_shmalloc.c @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2014-2016 Mellanox Technologies, Inc. + * All rights reserved. + * $COPYRIGHT$ + * + * Additional copyrights may follow + * + * $HEADER$ + * + * This sample allocates (shmalloc) symmetric memory (1 long integer), + * and then frees it. Success of allocation is not checked. + * + * Produces no output. + */ + +#include <shmem.h> + +int main(void) +{ + long *x; + + shmem_init(); + + x = (long *) shmem_malloc(sizeof(*x)); + + shmem_free(x); + + shmem_finalize(); +} + diff --git a/docs.it4i/src/ompi/oshmem_strided_puts.c b/docs.it4i/src/ompi/oshmem_strided_puts.c new file mode 100644 index 0000000000000000000000000000000000000000..e9f31ddb74915812db8460d3bfee4ea1d5efded2 --- /dev/null +++ b/docs.it4i/src/ompi/oshmem_strided_puts.c @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2014-2016 Mellanox Technologies, Inc. + * All rights reserved. + * $COPYRIGHT$ + * + * Additional copyrights may follow + * + * $HEADER$ + * + * This program is an adaptation of examples found in the man pages + * of SGI’s SHMEM implementation. + * + * In this program, iput is used to select 5 elements from array source separated by + * a stride of 2 and write them to array target using a stride of 1. + * + * Given the array source = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 } + * iput will select 5 elements from array source on PE 0, using a stride of 2: + * + * selected elements = { 1, 3, 5, 7, 9 } + * + * These elements will then be written to the array source on PE 1 using a stride of 1: + * + * target = { 1, 3, 5, 7, 9 } + * + */ + +#include <stdio.h> +#include <shmem.h> + +int main(void) +{ + short source[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; + static short target[10]; + int me; + + shmem_init(); + me = shmem_my_pe(); + + if (me == 0) { + /* put 10 words into target on PE 1 */ + shmem_short_iput(target, source, 1, 2, 5, 1); + } + + shmem_barrier_all(); /* sync sender and receiver */ + + if (me == 1) { + printf("target on PE %d is %hd %hd %hd %hd %hd\n", me, + target[0], target[1], target[2], + target[3], target[4] ); + } + shmem_barrier_all(); /* sync before exiting */ + shmem_finalize(); + + return 0; +} diff --git a/docs.it4i/src/ompi/oshmem_symmetric_data.c b/docs.it4i/src/ompi/oshmem_symmetric_data.c new file mode 100644 index 0000000000000000000000000000000000000000..7c5a1db6b5344e82b6b6fed4cb3bcdc531cc6894 --- /dev/null +++ b/docs.it4i/src/ompi/oshmem_symmetric_data.c @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2014-2016 Mellanox Technologies, Inc. + * All rights reserved. + * $COPYRIGHT$ + * + * Additional copyrights may follow + * + * $HEADER$ + */ + +#include <stdio.h> +#include <shmem.h> + +#define SIZE 16 + +int main(int argc, char* argv[]) +{ + short source[SIZE]; + static short target[SIZE]; + int i; + int num_pe, my_pe; + + shmem_init(); + + num_pe = shmem_n_pes(); + my_pe = shmem_my_pe(); + + if (my_pe == 0) { + /* initialize array */ + for(i = 0; i < SIZE; i++) { + source[i] = i; + } + /* local, not symmetric */ + /* static makes it symmetric */ + /* put "size" words into target on each PE */ + for(i = 1; i < num_pe; i++) { + shmem_short_put(target, source, SIZE, i); + } + } + + shmem_barrier_all(); /* sync sender and receiver */ + + if (my_pe != 0) { + printf("Target on PE %d is \t", my_pe); + + for(i = 0; i < SIZE; i++) { + printf("%hd \t", target[i]); + } + printf("\n"); + } + + shmem_barrier_all(); /* sync before exiting */ + shmem_finalize(); + + return 0; +} diff --git a/docs.it4i/src/ompi/ring_c.c b/docs.it4i/src/ompi/ring_c.c new file mode 100644 index 0000000000000000000000000000000000000000..86c205b3d21633c60607ce33f3f8c4d540ac8987 --- /dev/null +++ b/docs.it4i/src/ompi/ring_c.c @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2004-2006 The Trustees of Indiana University and Indiana + * University Research and Technology + * Corporation. All rights reserved. + * Copyright (c) 2006 Cisco Systems, Inc. All rights reserved. + * + * Simple ring test program in C. + */ + +#include <stdio.h> +#include "mpi.h" + +int main(int argc, char *argv[]) +{ + int rank, size, next, prev, message, tag = 201; + + /* Start up MPI */ + + MPI_Init(&argc, &argv); + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &size); + + /* Calculate the rank of the next process in the ring. Use the + modulus operator so that the last process "wraps around" to + rank zero. */ + + next = (rank + 1) % size; + prev = (rank + size - 1) % size; + + /* If we are the "master" process (i.e., MPI_COMM_WORLD rank 0), + put the number of times to go around the ring in the + message. */ + + if (0 == rank) { + message = 10; + + printf("Process 0 sending %d to %d, tag %d (%d processes in ring)\n", + message, next, tag, size); + MPI_Send(&message, 1, MPI_INT, next, tag, MPI_COMM_WORLD); + printf("Process 0 sent to %d\n", next); + } + + /* Pass the message around the ring. The exit mechanism works as + follows: the message (a positive integer) is passed around the + ring. Each time it passes rank 0, it is decremented. When + each processes receives a message containing a 0 value, it + passes the message on to the next process and then quits. By + passing the 0 message first, every process gets the 0 message + and can quit normally. */ + + while (1) { + MPI_Recv(&message, 1, MPI_INT, prev, tag, MPI_COMM_WORLD, + MPI_STATUS_IGNORE); + + if (0 == rank) { + --message; + printf("Process 0 decremented value: %d\n", message); + } + + MPI_Send(&message, 1, MPI_INT, next, tag, MPI_COMM_WORLD); + if (0 == message) { + printf("Process %d exiting\n", rank); + break; + } + } + + /* The last process does one extra send to process 0, which needs + to be received before the program can exit */ + + if (0 == rank) { + MPI_Recv(&message, 1, MPI_INT, prev, tag, MPI_COMM_WORLD, + MPI_STATUS_IGNORE); + } + + /* All done */ + + MPI_Finalize(); + return 0; +} diff --git a/docs.it4i/src/ompi/ring_cxx.cc b/docs.it4i/src/ompi/ring_cxx.cc new file mode 100644 index 0000000000000000000000000000000000000000..e783192431d881a28b1f9b92f012f36e2ab8c23a --- /dev/null +++ b/docs.it4i/src/ompi/ring_cxx.cc @@ -0,0 +1,85 @@ +// +// Copyright (c) 2004-2006 The Trustees of Indiana University and Indiana +// University Research and Technology +// Corporation. All rights reserved. +// Copyright (c) 2006 Cisco Systems, Inc. All rights reserved. +// +// Simple ring test program in C++. +// +// NOTE: The MPI C++ bindings were deprecated in MPI-2.2 and removed +// from the standard in MPI-3. Open MPI still provides C++ MPI +// bindings, but they are no longer built by default (and may be +// removed in a future version of Open MPI). You must +// --enable-mpi-cxx when configuring Open MPI to enable the MPI C++ +// bindings. +// + +#include "mpi.h" +#include <iostream> + +int main(int argc, char *argv[]) +{ + int rank, size, next, prev, message, tag = 201; + + // Start up MPI + + MPI::Init(); + rank = MPI::COMM_WORLD.Get_rank(); + size = MPI::COMM_WORLD.Get_size(); + + // Calculate the rank of the next process in the ring. Use the + // modulus operator so that the last process "wraps around" to + // rank zero. + + next = (rank + 1) % size; + prev = (rank + size - 1) % size; + + // If we are the "master" process (i.e., MPI_COMM_WORLD rank 0), + // put the number of times to go around the ring in the message. + + if (0 == rank) { + message = 10; + + std::cout << "Process 0 sending " << message << " to " << next + << ", tag " << tag << " (" << size << " processes in ring)" + << std::endl; + MPI::COMM_WORLD.Send(&message, 1, MPI::INT, next, tag); + std::cout << "Process 0 sent to " << next << std::endl; + } + + // Pass the message around the ring. The exit mechanism works as + // follows: the message (a positive integer) is passed around the + // ring. Each time it passes rank 0, it is decremented. When + // each processes receives a message containing a 0 value, it + // passes the message on to the next process and then quits. By + // passing the 0 message first, every process gets the 0 message + // and can quit normally. + + while (1) { + MPI::COMM_WORLD.Recv(&message, 1, MPI::INT, prev, tag); + + if (0 == rank) { + --message; + std::cout << "Process 0 decremented value: " << message + << std::endl; + } + + MPI::COMM_WORLD.Send(&message, 1, MPI::INT, next, tag); + if (0 == message) { + std::cout << "Process " << rank << " exiting" << std::endl; + break; + } + } + + // The last process does one extra send to process 0, which needs + // to be received before the program can exit */ + + if (0 == rank) { + MPI::COMM_WORLD.Recv(&message, 1, MPI::INT, prev, tag); + } + + // All done + + MPI::Finalize(); + return 0; +} diff --git a/docs.it4i/src/ompi/ring_mpifh.f b/docs.it4i/src/ompi/ring_mpifh.f new file mode 100644 index 0000000000000000000000000000000000000000..64e6498fe7f0bf25dbb4705bc9bb6fca2f12faee --- /dev/null +++ b/docs.it4i/src/ompi/ring_mpifh.f @@ -0,0 +1,81 @@ +C +C Copyright (c) 2004-2006 The Trustees of Indiana University and Indiana +C University Research and Technology +C Corporation. All rights reserved. +C Copyright (c) 2006-2015 Cisco Systems, Inc. All rights reserved. +C $COPYRIGHT$ +C +C Simple ring test program using the mpif.h Fortran bindings. +C + program ring_f77 + implicit none + include 'mpif.h' + integer rank, size, tag, next, from, message, ierr + +C Start up MPI */ + + call MPI_INIT(ierr) + call MPI_COMM_RANK(MPI_COMM_WORLD, rank, ierr) + call MPI_COMM_SIZE(MPI_COMM_WORLD, size, ierr) + +C Calculate the rank of the next process in the ring. Use the +C modulus operator so that the last process "wraps around" to rank +C zero. + + tag = 201 + next = mod((rank + 1), size) + from = mod((rank + size - 1), size) + +C If we are the "master" process (i.e., MPI_COMM_WORLD rank 0), put +C the number of times to go around the ring in the message. + + if (rank .eq. 0) then + message = 10 + + write(*, '("Process 0 sending ", i2, " to ", i2, " tag ", + & i3, " (", i2, " processes in ring)")') + & message, next, tag, size + call MPI_SEND(message, 1, MPI_INTEGER, next, tag, + & MPI_COMM_WORLD, ierr) + write(*, '("Process 0 sent to ", i2)') + & next + endif + +C Pass the message around the ring. The exit mechanism works as +C follows: the message (a positive integer) is passed around the +C ring. Each time it passes rank 0, it is decremented. When each +C processes receives a message containing a 0 value, it passes the +C message on to the next process and then quits. By passing the 0 +C message first, every process gets the 0 message and can quit +C normally. + + 10 call MPI_RECV(message, 1, MPI_INTEGER, from, tag, + & MPI_COMM_WORLD, MPI_STATUS_IGNORE, ierr) + + if (rank .eq. 0) then + message = message - 1 + write(*, '("Process 0 decremented value: ", i2)') message + endif + + call MPI_SEND(message, 1, MPI_INTEGER, next, tag, + & MPI_COMM_WORLD, ierr) + + if (message .eq. 0) then + write(*, '("Process ", i2, " exiting")') rank + goto 20 + endif + goto 10 + +C The last process does one extra send to process 0, which needs to +C be received before the program can exit + + 20 if (rank .eq. 0) then + call MPI_RECV(message, 1, MPI_INTEGER, from, tag, + & MPI_COMM_WORLD, MPI_STATUS_IGNORE, ierr) + endif + +C All done + + call MPI_FINALIZE(ierr) + end + diff --git a/docs.it4i/src/ompi/ring_oshmem_c.c b/docs.it4i/src/ompi/ring_oshmem_c.c new file mode 100644 index 0000000000000000000000000000000000000000..5fe1c7f65dca76f060cbd4120f6ee19b8399efd6 --- /dev/null +++ b/docs.it4i/src/ompi/ring_oshmem_c.c @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2014 Mellanox Technologies, Inc. + * All rights reserved. + * $COPYRIGHT$ + * + * Additional copyrights may follow + * + * $HEADER$ + */ + +#include <shmem.h> +#include <stdio.h> + +#if !defined(OSHMEM_SPEC_VERSION) || OSHMEM_SPEC_VERSION < 10200 +#error This application uses API 1.2 and up +#endif + +int main (int argc, char * argv[]) +{ + static int rbuf = -1; + int proc, nproc, next; + int message = 10; + + shmem_init(); + nproc = shmem_n_pes(); + proc = shmem_my_pe(); + + /* Calculate the PE number of the next process in the ring. Use the + modulus operator so that the last process "wraps around" to PE 0. */ + + next = (proc + 1) % nproc; + + if(proc == 0) + { + printf("Process 0 puts message %d to %d (%d processes in ring)\n", message, next, nproc); + shmem_int_put(&rbuf, &message, 1, next); + } + + /* Pass the message around the ring. The exit mechanism works as + follows: the message (a positive integer) is passed around the + ring. Each time it passes PE 0, it is decremented. When each + processes receives a message containing a 0 value, it passes the + message on to the next process and then quits. By passing the 0 + message first, every process gets the 0 message and can quit + normally. */ + + while(message > 0) { + shmem_int_wait_until(&rbuf, SHMEM_CMP_EQ, message); + if(proc == 0) { + --message; + printf("Process 0 decremented value: %d\n", message); + } + shmem_int_put(&rbuf, &message, 1, next); + if(proc != 0) { + --message; + } + } + shmem_finalize(); + + /* All done */ + + printf("Process %d exiting\n", proc); + + return 0; +} diff --git a/docs.it4i/src/ompi/ring_oshmemfh.f90 b/docs.it4i/src/ompi/ring_oshmemfh.f90 new file mode 100644 index 0000000000000000000000000000000000000000..e365bf23e17a9d2e17faa30f087b14628f2d000b --- /dev/null +++ b/docs.it4i/src/ompi/ring_oshmemfh.f90 @@ -0,0 +1,66 @@ +! +! Copyright (c) 2014 Mellanox Technologies, Inc. +! All rights reserved. +! Copyright (c) 2014 Cisco Systems, Inc. All rights reserved. +! $COPYRIGHT$ +! +! Additional copyrights may follow +! +! $HEADER$ +! + +program ring_oshmem + implicit none + include 'shmem.fh' + + integer*8, save :: rbuf + integer*8 :: message + integer :: proc, nproc, next + integer :: my_pe, num_pes + + rbuf = -1 + message = 10 + + call start_pes(0) + proc = my_pe() + nproc = num_pes() + +! Calculate the PE number of the next process in the ring. Use the +! modulus operator so that the last process "wraps around" to PE 0. + + next = mod((proc + 1), nproc) + + if (proc .eq. 0) then + write(*, '("Process 0 sending ", i2, " to", i2, " (", i2, " processes in ring)")') message, next, nproc + call shmem_put8(rbuf, message, 1, next) + write(*, '("Process 0 sent to ", i2)') next + end if + +! Pass the message around the ring. The exit mechanism works as +! follows: the message (a positive integer) is passed around the +! ring. Each time it passes PE 0, it is decremented. When each +! processes receives a message containing a 0 value, it passes the +! message on to the next process and then quits. By passing the 0 +! message first, every process gets the 0 message and can quit +! normally. + + do while (message .gt. 0) + call shmem_int8_wait_until(rbuf, SHMEM_CMP_EQ, message) + + if (proc .eq. 0) then + message = message - 1 + write(*, '("Process 0 decremented value:", i2)') message + end if + + call shmem_put8(rbuf, message, 1, next) + + if (proc .gt. 0) then + message = message - 1 + end if + end do + +! All done + + write(*, '("Process", i2," exiting.")') proc + +end program ring_oshmem diff --git a/docs.it4i/src/ompi/ring_usempi.f90 b/docs.it4i/src/ompi/ring_usempi.f90 new file mode 100644 index 0000000000000000000000000000000000000000..6c5b0b17bd0fcd9e05ab9e6da3688891377fed21 --- /dev/null +++ b/docs.it4i/src/ompi/ring_usempi.f90 @@ -0,0 +1,75 @@ +! +! Copyright (c) 2004-2006 The Trustees of Indiana University and Indiana +! University Research and Technology +! Corporation. All rights reserved. +! Copyright (c) 2006-2015 Cisco Systems, Inc. All rights reserved. +! $COPYRIGHT$ +! +! Simple ring test program using the Fortran mpi module bindings. +! +program ring + use mpi + implicit none + integer :: rank, size, tag, next, from, ierr, i, message + +! Start up MPI + + call MPI_INIT(ierr) + call MPI_COMM_RANK(MPI_COMM_WORLD, rank, ierr) + call MPI_COMM_SIZE(MPI_COMM_WORLD, size, ierr) + +! Calculate the rank of the next process in the ring. Use the modulus +! operator so that the last process "wraps around" to rank zero. + + tag = 201 + next = mod((rank + 1), size) + from = mod((rank + size - 1), size) + +! If we are the "master" process (i.e., MPI_COMM_WORLD rank 0), put +! the number of times to go around the ring in the message. + + if (rank .eq. 0) then + message = 10 + + write(*, '("Process 0 sending ", i2, " to ", i2, " tag ", i3, " (", i2, " processes in ring)")') message, next, tag, size + call MPI_SEND(message, 1, MPI_INTEGER, next, tag, MPI_COMM_WORLD, ierr) + write(*, '("Process 0 sent to ", i2)') next + endif + +! Pass the message around the ring. The exit mechanism works as +! follows: the message (a positive integer) is passed around the ring. +! Each time it passes rank 0, it is decremented. When each processes +! receives a message containing a 0 value, it passes the message on to +! the next process and then quits. By passing the 0 message first, +! every process gets the 0 message and can quit normally. + + i = 1 +10 call MPI_Recv(message, i, MPI_INTEGER, from, tag, MPI_COMM_WORLD, & + MPI_STATUS_IGNORE, ierr) + + if (rank .eq. 0) then + message = message - 1 + write(*, '("Process 0 decremented value: ", i2)') message + endif + + call MPI_SEND(message, 1, MPI_INTEGER, next, tag, MPI_COMM_WORLD, ierr) + + if (message .eq. 0) then + write(*, '("Process ", i2, " exiting")') rank + goto 20 + endif + goto 10 + +! The last process does one extra send to process 0, which needs to be +! received before the program can exit + + 20 if (rank .eq. 0) then + call MPI_RECV(message, 1, MPI_INTEGER, from, tag, MPI_COMM_WORLD, & + MPI_STATUS_IGNORE, ierr) + endif + +! All done + + call MPI_FINALIZE(ierr) +end program + diff --git a/docs.it4i/src/ompi/ring_usempif08.f90 b/docs.it4i/src/ompi/ring_usempif08.f90 new file mode 100644 index 0000000000000000000000000000000000000000..753b89531e6c4ec09e0c16952e3ce3f5aaae9be2 --- /dev/null +++ b/docs.it4i/src/ompi/ring_usempif08.f90 @@ -0,0 +1,79 @@ +! -*- f90 -*- +! +! Copyright (c) 2004-2006 The Trustees of Indiana University and Indiana +! University Research and Technology +! Corporation. All rights reserved. +! Copyright (c) 2006-2015 Cisco Systems, Inc. All rights reserved. +! Copyright (c) 2009-2012 Los Alamos National Security, LLC. +! All rights reserved. +! $COPYRIGHT$ +! +! Simple ring test program using the Fortran mpi_f08 module bindings. +! +program ring + use mpi_f08 + implicit none + integer :: rank, size, tag, next, from, i, message + + +! Start up MPI + + call MPI_INIT() + call MPI_COMM_RANK(MPI_COMM_WORLD, rank) + call MPI_COMM_SIZE(MPI_COMM_WORLD, size) + +! Calculate the rank of the next process in the ring. Use the modulus +! operator so that the last process "wraps around" to rank zero. + + tag = 201 + next = mod((rank + 1), size) + from = mod((rank + size - 1), size) + +! If we are the "master" process (i.e., MPI_COMM_WORLD rank 0), put +! the number of times to go around the ring in the message. + + if (rank .eq. 0) then + message = 10 + + write(*, '("Process 0 sending ", i2, " to ", i2, " tag ", i3, " (", i2, " processes in ring)")') message, next, tag, size + call MPI_SEND(message, 1, MPI_INTEGER, next, tag, MPI_COMM_WORLD) + write(*, '("Process 0 sent to ", i2)') next + endif + +! Pass the message around the ring. The exit mechanism works as +! follows: the message (a positive integer) is passed around the ring. +! Each time it passes rank 0, it is decremented. When each processes +! receives a message containing a 0 value, it passes the message on to +! the next process and then quits. By passing the 0 message first, +! every process gets the 0 message and can quit normally. + + i = 1 +10 call MPI_Recv(message, i, MPI_INTEGER, from, tag, MPI_COMM_WORLD, & + MPI_STATUS_IGNORE) + + if (rank .eq. 0) then + message = message - 1 + write(*, '("Process 0 decremented value: ", i2)') message + endif + + call MPI_SEND(message, 1, MPI_INTEGER, next, tag, MPI_COMM_WORLD) + + if (message .eq. 0) then + write(*, '("Process ", i2, " exiting")') rank + goto 20 + endif + goto 10 + +! The last process does one extra send to process 0, which needs to be +! received before the program can exit + + 20 if (rank .eq. 0) then + call MPI_RECV(message, 1, MPI_INTEGER, from, tag, MPI_COMM_WORLD, & + MPI_STATUS_IGNORE) + endif + +! All done + + call MPI_FINALIZE() +end program + diff --git a/docs.it4i/src/ompi/spc_example.c b/docs.it4i/src/ompi/spc_example.c new file mode 100644 index 0000000000000000000000000000000000000000..5b57589cffd4a5da6bddcb8baff3d9497c82745b --- /dev/null +++ b/docs.it4i/src/ompi/spc_example.c @@ -0,0 +1,120 @@ +/* + * Copyright (c) 2018 The University of Tennessee and The University + * of Tennessee Research Foundation. All rights + * reserved. + * + * Simple example usage of SPCs through MPI_T. + */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include "mpi.h" + +/* Sends 'num_messages' messages of 'message_size' bytes from rank 0 to rank 1. + * All messages are send synchronously and with the same tag in MPI_COMM_WORLD. + */ +void message_exchange(int num_messages, int message_size) +{ + int i, rank; + /* Use calloc to initialize data to 0's */ + char *data = (char*)calloc(message_size, sizeof(char)); + MPI_Status status; + + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + + if(rank == 0) { + for(i = 0; i < num_messages; i++) + MPI_Send(data, message_size, MPI_BYTE, 1, 123, MPI_COMM_WORLD); + } else if(rank == 1) { + for(i = 0; i < num_messages; i++) + MPI_Recv(data, message_size, MPI_BYTE, 0, 123, MPI_COMM_WORLD, &status); + } + + free(data); +} + +int main(int argc, char **argv) +{ + int num_messages, message_size; + + if(argc < 3) { + printf("Usage: mpirun -np 2 --mca mpi_spc_attach all --mca mpi_spc_dump_enabled true ./spc_example [num_messages] [message_size]\n"); + return -1; + } else { + num_messages = atoi(argv[1]); + message_size = atoi(argv[2]); + } + + int i, rank, size, provided, num, name_len, desc_len, verbosity, bind, var_class, readonly, continuous, atomic, count, index; + MPI_Datatype datatype; + MPI_T_enum enumtype; + MPI_Comm comm; + char name[256], description[256]; + + /* Counter names to be read by ranks 0 and 1 */ + char *counter_names[] = {"runtime_spc_OMPI_BYTES_SENT_USER", + "runtime_spc_OMPI_BYTES_RECEIVED_USER" }; + + MPI_Init(NULL, NULL); + MPI_T_init_thread(MPI_THREAD_SINGLE, &provided); + + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &size); + if(size != 2) { + fprintf(stderr, "ERROR: This test should be run with two MPI processes.\n"); + MPI_Abort(MPI_COMM_WORLD, -1); + } + + /* Determine the MPI_T pvar indices for the OMPI_BYTES_SENT/RECIEVED_USER SPCs */ + index = -1; + MPI_T_pvar_get_num(&num); + for(i = 0; i < num; i++) { + name_len = desc_len = 256; + PMPI_T_pvar_get_info(i, name, &name_len, &verbosity, + &var_class, &datatype, &enumtype, description, &desc_len, &bind, + &readonly, &continuous, &atomic); + if(strcmp(name, counter_names[rank]) == 0) { + index = i; + printf("[%d] %s -> %s\n", rank, name, description); + } + } + + /* Make sure we found the counters */ + if(index == -1) { + fprintf(stderr, "ERROR: Couldn't find the appropriate SPC counter in the MPI_T pvars.\n"); + MPI_Abort(MPI_COMM_WORLD, -1); + } + + int ret; + long long value; + + MPI_T_pvar_session session; + MPI_T_pvar_handle handle; + /* Create the MPI_T sessions/handles for the counters and start the counters */ + ret = MPI_T_pvar_session_create(&session); + ret = MPI_T_pvar_handle_alloc(session, index, NULL, &handle, &count); + ret = MPI_T_pvar_start(session, handle); + + message_exchange(num_messages, message_size); + + ret = MPI_T_pvar_read(session, handle, &value); + /* Print the counter values in order by rank */ + for(i = 0; i < 2; i++) { + if(i == rank) { + printf("[%d] Value Read: %lld\n", rank, value); + fflush(stdout); + } + MPI_Barrier(MPI_COMM_WORLD); + } + /* Stop the MPI_T session, free the handle, and then free the session */ + ret = MPI_T_pvar_stop(session, handle); + ret = MPI_T_pvar_handle_free(session, &handle); + ret = MPI_T_pvar_session_free(&session); + + MPI_T_finalize(); + MPI_Finalize(); + + return 0; +} diff --git a/mkdocs.yml b/mkdocs.yml index efbd57ff1e42340484c09663e01ff9fcfe5625e1..0f9e0c7a1c6d8090d38f4dfe0366fb417f4a8009 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -117,6 +117,7 @@ pages: - TensorFlow: software/machine-learning/tensorflow.md - MPI: - Introduction: software/mpi/mpi.md + - OpenMPI Examples: software/mpi/ompi-examples.md - MPI4Py (MPI for Python): software/mpi/mpi4py-mpi-for-python.md - Running Open MPI: software/mpi/Running_OpenMPI.md - Running MPICH2: software/mpi/running-mpich2.md