-
Notifications
You must be signed in to change notification settings - Fork 1
/
broadcast.c
143 lines (142 loc) · 5.78 KB
/
broadcast.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
#include <stdio.h>
#include <stdlib.h>
#include "mceik_broadcast.h"
/*!
* @brief Broadcasts the station list from root to all processes on the
* communicator
*
* @author Ben Baker
*
* @copyright Apache 2
*
*/
void broadcast_stations(MPI_Comm comm, const int root,
struct mceik_stations_struct *stations)
{
int k, myid;
//------------------------------------------------------------------------//
//
// Get communicator info
MPI_Comm_rank(comm, &myid);
// Integers
MPI_Bcast(&stations->nstat, 1, MPI_INT, root, comm);
MPI_Bcast(&stations->lcartesian, 1, MPI_INT, root, comm);
if (stations->nstat < 1){return;}
// Arrays
if (myid != root)
{
stations->lhasP = (int *)calloc((size_t) stations->nstat, sizeof(int));
stations->lhasS = (int *)calloc((size_t) stations->nstat, sizeof(int));
}
MPI_Bcast(stations->lhasP, stations->nstat, MPI_INT, root, comm);
MPI_Bcast(stations->lhasS, stations->nstat, MPI_INT, root, comm);
// Doubles
if (myid != root)
{
stations->xrec = (double *)
calloc((size_t) stations->nstat, sizeof(double));
stations->yrec = (double *)
calloc((size_t) stations->nstat, sizeof(double));
stations->zrec = (double *)
calloc((size_t) stations->nstat, sizeof(double));
stations->pcorr = (double *)
calloc((size_t) stations->nstat, sizeof(double));
stations->scorr = (double *)
calloc((size_t) stations->nstat, sizeof(double));
}
MPI_Bcast(stations->xrec, stations->nstat, MPI_DOUBLE, root, comm);
MPI_Bcast(stations->yrec, stations->nstat, MPI_DOUBLE, root, comm);
MPI_Bcast(stations->zrec, stations->nstat, MPI_DOUBLE, root, comm);
MPI_Bcast(stations->pcorr, stations->nstat, MPI_DOUBLE, root, comm);
MPI_Bcast(stations->scorr, stations->nstat, MPI_DOUBLE, root, comm);
// Characters
if (myid != root)
{
stations->netw = (char **)
calloc((size_t) stations->nstat, sizeof(char *));
stations->stnm = (char **)
calloc((size_t) stations->nstat, sizeof(char *));
stations->chan = (char **)
calloc((size_t) stations->nstat, sizeof(char *));
stations->loc = (char **)
calloc((size_t) stations->nstat, sizeof(char *));
for (k=0; k<stations->nstat; k++)
{
stations->netw[k] = (char *)calloc(64, sizeof(char));
stations->stnm[k] = (char *)calloc(64, sizeof(char));
stations->chan[k] = (char *)calloc(64, sizeof(char));
stations->loc[k] = (char *)calloc(64, sizeof(char));
}
}
for (k=0; k<stations->nstat; k++)
{
MPI_Bcast(stations->netw[k], 64, MPI_CHAR, root, comm);
MPI_Bcast(stations->stnm[k], 64, MPI_CHAR, root, comm);
MPI_Bcast(stations->chan[k], 64, MPI_CHAR, root, comm);
MPI_Bcast(stations->loc[k], 64, MPI_CHAR, root, comm);
}
return;
}
//============================================================================//
/*!
* @brief Distributes the catalog to all processes on communicator from
* root process
*
* @param[in] comm MPI communicator
* @param[in] root root process ID on communicator with catalog
*
* @param[in,out] catalog on input this is the catalog on the root process.
* on output this is the catalog on all the processes
* on the communicator.
*
* @author Ben Baker
*
* @copyright Apache 2
*
*/
void broadcast_catalog(MPI_Comm comm, const int root,
struct mceik_catalog_struct *catalog)
{
int myid, nevents, nwork;
//------------------------------------------------------------------------//
//
// Get communicator info
MPI_Comm_rank(comm, &myid);
// Sizes
MPI_Bcast(&catalog->nevents, 1, MPI_INT, root, comm);
nevents = catalog->nevents;
if (nevents < 1){return;}
if (myid == root){nwork = catalog->obsPtr[nevents];}
MPI_Bcast(&nwork, 1, MPI_INT, root, comm);
// Integers
if (myid != root)
{
catalog->luseObs = (int *) calloc((size_t) nwork, sizeof(int));
catalog->pickType = (int *) calloc((size_t) nwork, sizeof(int));
catalog->statPtr = (int *) calloc((size_t) nwork, sizeof(int));
catalog->obsPtr = (int *) calloc((size_t) nevents+1, sizeof(int));
}
MPI_Bcast(catalog->luseObs, nwork, MPI_INT, root, comm);
MPI_Bcast(catalog->pickType, nwork, MPI_INT, root, comm);
MPI_Bcast(catalog->statPtr, nwork, MPI_INT, root, comm);
MPI_Bcast(catalog->obsPtr, nevents+1, MPI_INT, root, comm);
// Doubles
if (myid != root)
{
catalog->xsrc = (double *) calloc((size_t) nevents, sizeof(double));
catalog->ysrc = (double *) calloc((size_t) nevents, sizeof(double));
catalog->zsrc = (double *) calloc((size_t) nevents, sizeof(double));
catalog->tori = (double *) calloc((size_t) nevents, sizeof(double));
catalog->tobs = (double *) calloc((size_t) nwork, sizeof(double));
catalog->test = (double *) calloc((size_t) nwork, sizeof(double));
catalog->varObs = (double *) calloc((size_t) nwork, sizeof(double));
}
MPI_Bcast(catalog->xsrc, nevents, MPI_DOUBLE, root, comm);
MPI_Bcast(catalog->ysrc, nevents, MPI_DOUBLE, root, comm);
MPI_Bcast(catalog->zsrc, nevents, MPI_DOUBLE, root, comm);
MPI_Bcast(catalog->tori, nevents, MPI_DOUBLE, root, comm);
MPI_Bcast(catalog->tobs, nwork, MPI_DOUBLE, root, comm);
MPI_Bcast(catalog->test, nwork, MPI_DOUBLE, root, comm);
MPI_Bcast(catalog->varObs, nwork, MPI_DOUBLE, root, comm);
return;
}