-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.cpp
More file actions
95 lines (83 loc) · 1.92 KB
/
Copy pathtest.cpp
File metadata and controls
95 lines (83 loc) · 1.92 KB
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
/**
* @file test.cpp
*
* SPDX-FileCopyrightText: 2008-2026 HPCS Group <rootsim@googlegroups.com>
* SPDX-License-Identifier: GPL-3.0-only
*
* @brief A test file for CPP
*/
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <mpi.h>
using namespace std;
/**
* @brief Print the current time
*/
void timestamp()
{
#define TIME_SIZE 40
static char time_buffer[TIME_SIZE];
const struct std::tm *tm_ptr;
std::time_t now;
now = std::time(NULL);
tm_ptr = std::localtime(&now);
std::strftime(time_buffer, TIME_SIZE, "%d %B %Y %I:%M:%S %p", tm_ptr);
std::cout << time_buffer << "\n";
return;
#undef TIME_SIZE
}
/**
* @brief the @c main function.
*
* This is the entry point of the program, and the only function in this dummy test.
*
* @param argc the number of arguments
* @param argv the vector of arguments
*
* @return the exit code
*/
int main(int argc, char *argv[])
{
int id;
int ierr;
int p;
double wtime;
ierr = MPI_Init(&argc, &argv);
if(ierr != 0) {
cout << "\n";
cout << "HELLO_MPI - Fatal error!\n";
cout << " MPI_Init returned nonzero ierr.\n";
exit(1);
}
ierr = MPI_Comm_size(MPI_COMM_WORLD, &p);
ierr = MPI_Comm_rank(MPI_COMM_WORLD, &id);
if(id == 0) {
timestamp();
cout << "\n";
cout << "P" << id << ": HELLO_MPI - Master process:\n";
cout << "P" << id << ": C++/MPI version\n";
cout << "P" << id << ": An MPI example program.\n";
cout << "\n";
cout << "P" << id << ": The number of processes is " << p << "\n";
cout << "\n";
}
if(id == 0) {
wtime = MPI_Wtime();
}
cout << "P" << id << ": 'Hello, world!'\n";
if(id == 0) {
wtime = MPI_Wtime() - wtime;
cout << "P" << id << ": Elapsed wall clock time = " << wtime << " seconds.\n";
}
MPI_Finalize();
if(id == 0) {
cout << "\n";
cout << "P" << id << ": HELLO_MPI:\n";
cout << "P" << id << ": Normal end of execution.\n";
cout << "\n";
timestamp();
}
return 0;
}