forked from Seagate/cortx-motr-apps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mpiapp.c
157 lines (135 loc) · 3.58 KB
/
mpiapp.c
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/* -*- C -*- */
/*
* Copyright (c) 2017-2020 Seagate Technology LLC and/or its Affiliates
*
* 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.
*
* For any questions about this software or licensing,
* please email [email protected] or [email protected].
*
* Original author: Ganesan Umanesan <[email protected]>
* Original creation date: 24-May-2018
*/
#include <mpi.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <libgen.h>
#include "c0appz.h"
#define DMPISEQ 0
#define DCLOVIS 1
char *prog;
/* main */
int main(int argc, char **argv)
{
int wsize;
int wrank;
char pname[MPI_MAX_PROCESSOR_NAME];
int pnlen;
/* MPI start */
MPI_Init(NULL, NULL);
MPI_Comm_size(MPI_COMM_WORLD, &wsize);
MPI_Comm_rank(MPI_COMM_WORLD, &wrank);
MPI_Get_processor_name(pname, &pnlen);
fprintf(stderr,"MPI rank [ %d ] start.\n",wrank);
/*
* rank index
* gather all node ids and ranks
* and determine rank index.
*/
int node;
node = atoi((char *)(pname+7));
node = (node * 1000) + wrank;
int *nptr = (int *)malloc(sizeof(int) * wsize);
MPI_Allgather(&node, 1, MPI_INT, nptr, 1, MPI_INT, MPI_COMM_WORLD);
MPI_Barrier(MPI_COMM_WORLD);
int idx;
int *ptr;
idx = 0;
ptr = nptr;
while(ptr != nptr + wsize) {
if((*ptr/1000 == node/1000) && (node > *ptr)) idx++;
ptr++;
}
fprintf(stderr,"MPI rank [ %d ] [%s] size = %d rank = %d index = %d\n",
wrank, pname, wsize, wrank, idx);
/* time in */
c0appz_timein();
prog = basename(strdup(argv[0]));
c0appz_setrc(prog);
c0appz_putrc();
#if DMPISEQ
/* mpi recv */
int token = 0;
if(wrank != 0) {
MPI_Recv(&token,1,MPI_INT,wrank-1,0,MPI_COMM_WORLD,MPI_STATUS_IGNORE);
fprintf(stderr,"recv:[%d] <<- [%d] token:[[%d]]\n",wrank,wrank-1,token);
}
#endif
#if DCLOVIS
int rc;
fprintf(stderr,"MPI rank [ %d ] c0appz_init(%d) [**]\n",wrank,idx);
/* initialize resources */
rc = c0appz_init(idx);
if (rc != 0) {
fprintf(stderr,"error! c0appz_init(%i) failed: %d\n", idx, rc);
return -2;
}
fprintf(stderr,"MPI rank [ %d ] c0appz_init(%d) [OK]\n",wrank,idx);
#endif
#if DMPISEQ
/* mpi send */
token = 1000+wrank;
if(wrank != wsize-1) {
MPI_Send(&token,1,MPI_INT, wrank+1,0,MPI_COMM_WORLD);
fprintf(stderr,"send:[%d] ->> [%d] token:[[%d]]\n",wrank,wrank+1,token);
}
MPI_Barrier(MPI_COMM_WORLD);
#endif
/*
* do something
*/
fprintf(stderr,"MPI rank [ %d ] do something here...\n",wrank);
#if DCLOVIS
/* delete */
int64_t idh = 0;
int64_t idl = 0;
idl = 1048577 + wrank;
fprintf(stderr,"deleting object < %lu %lu >\n",idh,idl);
if (c0appz_rm(0,1048577) != 0) {
fprintf(stderr,"error! delete object failed.\n");
};
#endif
#if DCLOVIS
fprintf(stderr,"MPI rank [ %d ] c0appz_free() [**]\n",wrank);
/* free resources*/
c0appz_free();
fprintf(stderr,"MPI rank [ %d ] c0appz_free() [OK]\n",wrank);
#endif
/* time out */
c0appz_timeout(0);
/* success */
fprintf(stderr,"MPI rank [ %d ] end.\n",wrank);
/* MPI end */
MPI_Finalize();
return 0;
}
/*
* Local variables:
* c-indentation-style: "K&R"
* c-basic-offset: 8
* tab-width: 8
* fill-column: 80
* scroll-step: 1
* End:
*/