1 #ifndef __MIGRATE_MPI_
2 #define __MIGRATE_MPI_
3 /*
4  (c) Peter Beerli 2013 Tallahassee FL
5 
6  Permission is hereby granted, free of charge, to any person obtaining
7  a copy of this software and associated documentation files (the
8  "Software"), to deal in the Software without restriction, including
9  without limitation the rights to use, copy, modify, merge, publish,
10  distribute, sublicense, and/or sell copies of the Software, and to
11  permit persons to whom the Software is furnished to do so, subject
12  to the following conditions:
13 
14  The above copyright notice and this permission notice shall be
15  included in all copies or substantial portions of the Software.
16 
17  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
21  ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
22  CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 */
25 
26 
27 #ifdef MPI
28 #ifdef POOCH
29 #include "poochmpi.h"
30 #else
31 #include <mpi.h>
32 #endif
33 #include <stdio.h>
34 #include <stdarg.h>
35 #include "migration.h"
36 
37 #include "bayes.h"
38 
39 #define MYINT  int
40 #define REPTAG 90
41 #define PRINTTAG 800
42 #define TEMPTAG 7000
43 #define BURNTAG 6000
44 
45 typedef struct _filedb_fmt {
46 	FILE *file;
47 	long handle;
48 } filedb_fmt;
49 
50 
51 extern filedb_fmt filedb[30];
52 extern long filenum;
53 
54 extern MPI_Comm comm_world;
55 extern MPI_Comm comm_workers;
56 
57 #endif
58 extern int myID;
59 extern int myRepID;
60 extern int allID;
61 extern int color;
62 extern int numcpu;
63 extern int locidone;
64 extern int profiledone;
65 
66 #define SLAVE 1
67 
68 #define MIGMPI_END 0
69 #define MIGMPI_LIKE 1
70 #define MIGMPI_GRADIENT 2
71 #define MIGMPI_RESULT 3
72 #define MIGMPI_SUMFILE 4
73 #define MIGMPI_MIGHIST 5
74 #define MIGMPI_BAYESHIST 6
75 #define MIGMPI_SKYLINE 7
76 #define MIGMPI_TREESPACE 8
77 #define MIGMPI_PLOTPLANE 9
78 #define MIGMPI_PARALIO 10
79 #ifdef MPI
80 
81 #ifndef PTHREADS
82 #define tpool_t char
83 #else
84 #include "heating.h"
85 #endif
86 
87 extern void broadcast_options (option_fmt * options);
88 
89 extern void mpi_runloci_master (long loci, int *who, world_fmt *world, boolean options_readsum, boolean menu);
90 
91 extern void mpi_runloci_worker (world_fmt ** universe, int usize,
92                                     option_fmt * options, data_fmt * data,
93                                     tpool_t * heating_pool, long maxreplicate,
94                                     long *treefilepos, long *Gmax);
95 
96 extern MYREAL mpi_likelihood_master (MYREAL *param, MYREAL *lparam,
97                                          world_fmt * world, nr_fmt * nr,
98                                          helper_fmt * helper, int *who);
99 extern void broadcast_options_master (option_fmt * options, data_fmt *data);
100 extern void broadcast_options_worker (option_fmt * options);
101 
102 extern void broadcast_data_master (data_fmt * data, option_fmt * options);
103 extern void broadcast_data_worker (data_fmt * data, option_fmt * options);
104 extern void mpi_results_master (long sendtype, world_fmt * world,
105                                     long maxrep,
106                                     void (*unpack) (MYREAL *buffer,
107                                                     world_fmt * world, long locus,
108                                                     long maxrep, long numpop));
109 extern void mpi_results_worker (long bufsize, world_fmt * world, long maxrep,
110                                     long (*pack) (MYREAL **buffer,
111                                                   world_fmt * world, long locus,
112                                                   long maxrep, long numpop));
113 
114 extern long pack_result_buffer (MYREAL **buffer, world_fmt * world,
115                                     long locus, long maxrep, long numpop);
116 extern void unpack_result_buffer (MYREAL *buffer, world_fmt * world,
117                                       long locus, long maxrep, long numpop);
118 extern long pack_sumfile_buffer (MYREAL **buffer, world_fmt * world,
119                                      long locus, long maxrep, long numpop);
120 extern void unpack_sumfile_buffer (MYREAL *buffer, world_fmt * world,
121                                        long locus, long maxrep, long numpop);
122 extern long pack_treespace_buffer (MYREAL **buffer, world_fmt * world,
123 				   long locus, long maxrep, long numpop);
124 extern void unpack_treespace_buffer (MYREAL *buffer, world_fmt * world,
125 				     long locus, long maxrep, long numpop);
126 
127 extern long pack_mighist_buffer (MYREAL **buffer, world_fmt * world,
128                                      long locus, long maxrep, long numpop);
129 extern void unpack_mighist_buffer (MYREAL *buffer, world_fmt * world,
130                                        long locus, long maxrep, long numpop);
131 extern long pack_skyline_buffer (MYREAL **buffer, world_fmt * world,
132 				 long locus, long maxrep, long numpop);
133 extern void unpack_skyline_buffer (MYREAL *buffer, world_fmt * world,
134 				   long locus, long maxrep, long numpop);
135 
136 extern long unpack_single_bayes_buffer(MYREAL *buffer,bayes_fmt * bayes, world_fmt * world,long locus);
137 
138 extern long pack_bayes_buffer (MYREAL **buffer, world_fmt * world,
139                                long locus, long maxrep, long numpop);
140 
141 extern void unpack_bayes_buffer (MYREAL *buffer, world_fmt * world,
142                                  long locus, long maxrep, long numpop);
143 
144 extern void mpi_gradient_master (nr_fmt * nr, world_fmt * world, int *who);
145 
146 extern void mpi_maximize_worker (world_fmt * world, option_fmt *options,long kind, long rep);
147 
148 extern void mpi_startparam_master(world_fmt * world);
149 extern void mpi_startparam_worker(world_fmt * world);
150 
151 extern void mpi_gmax_master(world_fmt * world, long *Gmax);
152 extern void mpi_gmax_worker(world_fmt * world);
153 
154 extern void mpi_send_stop (world_fmt * world);
155 extern void mpi_results_stop (void);
156 extern void assignloci_worker (world_fmt * world, option_fmt *options, long * Gmax);
157 void setup_parameter0_mpi (world_fmt * world, nr_fmt * nr, long repkind,
158                            long repstart, long repstop, long loci, long kind,
159                            boolean multilocus);
160 
161 extern void setup_filehandle_db(FILE *file, world_fmt *world, option_fmt *options, data_fmt *data);
162 extern long get_filehandle(void *file, world_fmt *world, option_fmt *options, data_fmt *data);
163 extern void mpi_fprintf(FILE *file, const char *fmt, ...);
164 extern void mpi_fprintf2(FILE *file, long filesize, const char *fmt, ...);
165 #ifdef PARALIO
166 extern void mpi_mdim_send(MPI_File *file, char *values, long size);
167 #else
168 extern void mpi_mdim_send(float *values, long size);
169 #endif
170 //extern void mpi_mdim_send(float *values, long size);
171 extern long get_filehandle2(void *file, world_fmt *world);
172 #ifdef SLOWNET
173 extern void
174 mpi_broadcast_results (world_fmt * world, long loci,
175                        long (*pack) (MYREAL **buffer, world_fmt * world,
176                                      long locus, long maxrep, long numpop),
177                        void (*unpack) (MYREAL *buffer, world_fmt * world,
178                                        long locus, long maxrep, long numpop));
179 extern void mpi_profiles_master (world_fmt * world, long nparam, int *profilewho);
180 extern void mpi_profiles_worker (world_fmt * world, long *gmaxptr);
181 extern void setup_parameter0_slowmpi (world_fmt * world, nr_fmt * nr, long repkind,
182                                long repstart, long repstop, long loci,
183                                long kind, boolean multilocus);
184 extern long  mpi_send_stop_mcmc_lociworker(long numcpu, long loci);
185 extern long  mpi_send_stop_mcmc_worker_orig(long numcpu, long loci, MPI_Comm *comm, MPI_Request *irequests, MPI_Status *istatus, long id);
186 #endif /*slownet */
187 extern long  mpi_send_stop_mcmc_replicateworker(long numcpu, long loci);
188 extern int get_replicant_color(int numcpu, long maxreplicate, long loci);
189 
190 //#include <sys/resource.h>
191 //extern void set_memory_limit(rlim_t softsize,rlim_t maxsize);
192 //extern void check_memory_limit();
193 
194 #endif /*mpi */
195 
196 
197 #endif
198