/usr/include/linbox/algorithms/cra-mpi.h is in liblinbox-dev 1.3.2-1.1build2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 | /* Copyright (C) 2007 LinBox
* Written by bds and zw
*
* author: B. David Saunders and Zhendong Wan
* parallelized for BOINC computing by Bryan Youse
*
*
* ========LICENCE========
* This file is part of the library LinBox.
*
* LinBox is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* ========LICENCE========
*/
#ifndef __LINBOX_cra_mpi_H
#define __LINBOX_cra_mpi_H
#define MPICH_IGNORE_CXX_SEEK //BB: ???
#include "linbox/util/timer.h"
#include <stdlib.h>
#include "linbox/integer.h"
#include "linbox/solutions/methods.h"
#include <vector>
#include <utility>
#include "linbox/algorithms/cra-domain.h"
#include "linbox/util/mpicpp.h"
namespace LinBox
{
template<class CRABase>
struct MPIChineseRemainder {
typedef typename CRABase::Domain Domain;
typedef typename CRABase::DomainElement DomainElement;
protected:
CRABase Builder_;
Communicator* _commPtr;
unsigned int _numprocs;
public:
template<class Param>
MPIChineseRemainder(const Param& b, Communicator *c) :
Builder_(b), _commPtr(c), _numprocs(c->size())
{}
/** \brief The CRA loop.
*
* termination condition.
*
* \param Iteration Function object of two arguments, \c
* Iteration(r, p), given prime \c p it outputs residue(s) \c
* r. This loop may be parallelized. \p Iteration must be
* reentrant, thread safe. For example, \p Iteration may be
* returning the coefficients of the minimal polynomial of a
* matrix \c mod \p p.
@warning we won't detect bad primes.
*
* \param primeg RandIter object for generating primes.
* \param[out] res an integer
*/
template<class Function, class PrimeIterator>
Integer & operator() (Integer& res, Function& Iteration, PrimeIterator& primeg)
{
// defer to standard CRA loop if no parallel usage is desired
if(_commPtr == 0 || _commPtr->size() == 1) {
ChineseRemainder< CRABase > sequential(Builder_);
return sequential(res, Iteration, primeg);
}
int procs = _commPtr->size();
int process = _commPtr->rank();
// parent process
if(process == 0 ){
// create an array to store primes
int primes[procs - 1];
DomainElement r;
// send each child process a new prime to work on
for(int i=1; i<procs; i++){
++primeg; while(Builder_.noncoprime(*primeg) ) ++primeg;
primes[i - 1] = *primeg;
_commPtr->send(primes[i - 1], i);
}
int idle_process = 0;
bool first_time = true;
int poison_pills_left = procs - 1;
// loop until all execution is complete
while( poison_pills_left > 0 ){
// receive sub-answers from child procs
_commPtr->recv(r, MPI_ANY_SOURCE);
idle_process = (_commPtr->get_stat()).MPI_SOURCE;
Domain D(primes[idle_process - 1]);
// assimilate results
if(first_time){
Builder_.initialize(D, r);
first_time = false;
}
else
Builder_.progress( D, r );
// queue a new prime if applicable
if(! Builder_.terminated()){
++primeg;
primes[idle_process - 1] = *primeg;
}
// otherwise, queue a poison pill
else{
primes[idle_process - 1] = 0;
poison_pills_left--;
}
// send the prime or poison pill
_commPtr->send(primes[idle_process - 1], idle_process);
} // end while
return Builder_.result(res);
} // end if(parent process)
// child processes
else{
int pp;
while(true){
// receive the prime to work on, stop
// if signaled a zero
_commPtr->recv(pp, 0);
if(pp == 0)
break;
Domain D(pp);
DomainElement r; D.init(r);
Iteration(r, D);
//Comm->buffer_attach(rr);
// send the results
_commPtr->send(r, 0);
}
return res;
}
}
#if 0
template<class V, class F, class P>
V & operator() (V& res, F& it, P&primeg){ return res; }
#endif
template<class Vect, class Function, class PrimeIterator>
Vect & operator() (Vect& res, Function& Iteration, PrimeIterator& primeg)
{
// if there is no communicator or if there is only one process,
// then proceed normally (without parallel)
if(_commPtr == 0 || _commPtr->size() == 1) {
ChineseRemainder< CRABase > sequential(Builder_);
return sequential(res, Iteration, primeg);
}
int procs = _commPtr->size();
int process = _commPtr->rank();
std::vector<DomainElement> r;
// parent propcess
if(process == 0){
int primes[procs - 1];
Domain D(*primeg);
// for each slave process...
for(int i=1; i<procs; i++){
// generate a new prime
++primeg; while(Builder_.noncoprime(*primeg) ) ++primeg;
// fix the array of currently sent primes
primes[i - 1] = *primeg;
// send the prime to a slave process
_commPtr->send(primes[i - 1], i);
}
Builder_.initialize( D, Iteration(r, D) );
int idle_process = 0;
int poison_pills_left = procs - 1;
while(poison_pills_left > 0 ){
// receive the beginnin and end of a vector in heapspace
_commPtr->recv(r.begin(), r.end(), MPI_ANY_SOURCE, 0);
// determine which process sent answer
// and give them a new prime
idle_process = (_commPtr->get_stat()).MPI_SOURCE;
Domain D(primes[idle_process - 1]);
Builder_.progress(D, r);
// if still working, queue a prime
if(! Builder_.terminated()){
++primeg;
primes[idle_process - 1] = *primeg;
}
// otherwise, queue a poison pill
else{
primes[idle_process - 1] = 0;
poison_pills_left--;
}
// send the prime or poison
_commPtr->send(primes[idle_process - 1], idle_process);
} // while
return Builder_.result(res);
}
// child process
else{
int pp;
// get a prime, compute, send back start and end
// of heap addresses
while(true){
_commPtr->recv(pp, 0);
if(pp == 0)
break;
Domain D(pp);
Iteration(r, D);
_commPtr->send(r.begin(), r.end(), 0, 0);
}
return res;
}
}
};
}
#undef MPICH_IGNORE_CXX_SEEK
#endif // __LINBOX_cra_mpi_H
// vim:sts=8:sw=8:ts=8:noet:sr:cino=>s,f0,{0,g0,(0,:0,t0,+0,=s
// Local Variables:
// mode: C++
// tab-width: 8
// indent-tabs-mode: nil
// c-basic-offset: 8
// End:
|