Commit 109601cb authored by Eric Jullo's avatar Eric Jullo
Browse files

Remove MPI stuff

parent ab54c64e
......@@ -37,7 +37,7 @@
double getLhood0(); // defined in o_chi.c
static int minusone; // count chi2 errors in image plane
static int nchi2; // count number of computed chi2
static double nchi2; // count number of computed chi2
static time_t start,end; // computation time
static int UserBuild(double*, CommonStr*, ObjectStr*, int, int);
......@@ -237,7 +237,6 @@ ObjectStr* Object) // I O sample object
return 1;
}
#ifndef PARALLEL
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Function: UserBuild
//
......@@ -288,76 +287,6 @@ int output) // I +ve if Mock to be written out, -ve if not
return valid;
}
#else
#include "mpi.h"
extern pthread_mutex_t mutexsum; // for nchi2 and minusone variables in bayesapp.c
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Function: UserBuild (PARALLEL implementation)
//-----------------------------------------------------------------------------
//
static int UserBuild( // O +ve = OK, 0 = DO NOT USE, -ve = error
double* Lhood, // O loglikelihood
CommonStr* Common, // I General information
ObjectStr* Object, // I(O) Cubes in, perhaps Mock out
int Natoms, // I # atoms
int output) // I +ve if Mock to be written out, -ve if not
{
double** Cubes = Object->Cubes; // I Cubes in [0,1) [Natoms][Ndim]
double* Cube=Cubes[0];
int valid;
int slave;
double temp[3]; // {valid,chi2,Lhood0} if valid = 1
// {valid, **, **} if valid = 0
MPI_Status status;
UserCommonStr* UserCommon = (UserCommonStr*)Common->UserCommon;
slave = UserCommon->slave;
valid = 0.;
*Lhood = 0.;
if( Natoms == 1 )
{
/* Set the clumps parameters from the cube and eventually reject the whole object*/
// Send the Cube to any processor waiting
#ifdef MPIDEBUG
printf("UserBuild: Send data to slave %d...\n",
slave);
#endif
MPI_Send(&Common->Ndim, 1, MPI_INT, slave, 100, MPI_COMM_WORLD);
MPI_Send(Cube, Common->Ndim, MPI_DOUBLE, slave, 150, MPI_COMM_WORLD);
MPI_Recv(temp, 3, MPI_DOUBLE, slave, 200, MPI_COMM_WORLD, &status);
#ifdef MPIDEBUG
printf("UserBuild: Data received from slave %d...\n",slave);
#endif
valid = temp[0];
/* Compute the likelyhood for this object */
if( valid )
{
pthread_mutex_lock (&mutexsum);
nchi2++;
*Lhood = temp[1];
if( *Lhood == -1 )
{
minusone++;
valid = 0;
}
else
{
*Lhood = -0.5 * (*Lhood);
*Lhood += -0.5 * temp[3];
}
pthread_mutex_unlock(&mutexsum);
}
}
return valid;
}
#endif // PARALLEL
//=============================================================================
// Dummy procedure to link to BayeSys3 when not running MassInf
......@@ -559,6 +488,7 @@ int UserMonitor( // O 0 = continue, +ve = finish, -ve = abort
double chi2;
FILE *bayes;
int nimages;
double chi2rate;
char limages[ZMBOUND][IDSIZE];
// FILE *debug;
......@@ -589,11 +519,14 @@ int UserMonitor( // O 0 = continue, +ve = finish, -ve = abort
if( Common->cool < 1.0 )
{
Nrem = Common->Nsystem;
chi2rate = difftime(end,start);
chi2rate = chi2rate > 0 ? chi2rate : -1;
chi2rate = nchi2/chi2rate;
printf(" \r");
fprintf(stdout, // (stderr flushes output immediately)
"Burn-in : %10.6lf %5d %12.3lf %10.3lf %d/%d %dchi2/s\r",
Common->cool, Nrem, chi2, Common->Evidence,minusone,nchi2,
(int)(((double)nchi2)/difftime(end,start)) );
"Burn-in : %10.6lf %5d %12.3lf %10.3lf %d/%.0lf %.0lfchi2/s\r",
Common->cool, Nrem, chi2, Common->Evidence,minusone,nchi2,chi2rate);
}
else
{
......@@ -605,7 +538,7 @@ int UserMonitor( // O 0 = continue, +ve = finish, -ve = abort
Common->cool, UserCommon->Nsample+1, M.itmax+1, chi2, Common->Evidence);
}
fflush(stdout);
minusone=0;nchi2=0;start=end;
minusone=0;nchi2=0.;start=end;
time(&end);
// SAVE: save the chi2 value
// if( Common->cool >= 1. )
......@@ -641,14 +574,19 @@ int UserMonitor( // O 0 = continue, +ve = finish, -ve = abort
fprintf(bayes, "%lf ", getParVal(0, ipx));
// SAVE: save zmlimit parameters
for( k = 0; k < I.nzlim; k++ )
if( zlim[k].opt != 0 )
for( ipx = 0; ipx < I.nzlim; ipx++ )
if( zlim[ipx].opt != 0 )
{
// look for the images families corresponding to the zmlimit to optimize
nimages = splitzmlimit(zlim[k].n, limages);
/*nimages = splitzmlimit(zlim[k].n, limages);
i = 0;
while( indexCmp( multi[i][0].n, limages[0] ) ) i++;
fprintf( bayes, "%lf ", multi[i][0].z );
fprintf( bayes, "%lf ", multi[i][0].z );*/
i = 0;
while( indexCmp( multi[i][0].n, zlim[ipx].n ) ) i++;
for( k = 0; k < I.mult[i]; k++ )
fprintf( bayes, "%lf ", multi[i][k].z );
}
// SAVE : save pot parameters
......@@ -672,7 +610,6 @@ int UserMonitor( // O 0 = continue, +ve = finish, -ve = abort
{
for( i = 0; i < I.n_mult; i++ )
fprintf( bayes, "%lf ", sqrt(I.sig2pos[i]) );
}
if( I.dsigell != -1. )
fprintf( bayes, "%lf ", sqrt(I.sig2ell) );
......
This diff is collapsed.
......@@ -7,10 +7,6 @@
#include<dimension.h>
#include<structure.h>
#ifdef PARALLEL
#include "mpi.h"
#endif
/****************************************************************/
/* nom: LENSTOOL */
/* auteur: Jean-Paul Kneib */
......@@ -33,7 +29,7 @@ struct g_cline CL;
struct g_observ O;
struct pot lens[NLMAX];
struct pot lmin[NLMAX],lmax[NLMAX],prec[NLMAX];
struct pot clmin,clmax; /*cosmological limits*/
struct g_cosmo clmin,clmax; /*cosmological limits*/
struct ipot ip;
struct MCarlo mc;
struct cline cl[NIMAX];
......@@ -65,11 +61,6 @@ double **tmp_p;
double **map_axx;
double **map_ayy;
#ifdef PARALLEL
int myid;
int numprocs;
#endif
int main(int argc, char *argv[])
{
......@@ -81,7 +72,7 @@ int main(int argc, char *argv[])
extern struct galaxie image[NAMAX][NIMAX];
int noedit,init;
char infile[80];
/************* Verification du format de la commande ****************/
if( argc != 2 && argc!=3 )
{
......@@ -95,30 +86,11 @@ int main(int argc, char *argv[])
if( strstr( infile, ".par" ) == NULL )
strcat( infile, ".par" );
noedit=0;
if( argc == 3 && !strcmp(argv[2],"-n") )
noedit=1;
#ifdef PARALLEL
// Parallel implementation
int namelen;
char processor_name[MPI_MAX_PROCESSOR_NAME];
int provided;
MPI_Init_thread(&argc,&argv, MPI_THREAD_MULTIPLE,&provided);
MPI_Comm_size(MPI_COMM_WORLD,&numprocs);
MPI_Comm_rank(MPI_COMM_WORLD,&myid);
MPI_Get_processor_name(processor_name,&namelen);
fprintf(stdout,"Process %d of %d is on %s\n",
myid, numprocs, processor_name);
fflush(stdout);
noedit=1;
#endif
/************** Read the .par file and initialise potentials ***********/
init=init_grille(infile,noedit);
......@@ -270,9 +242,5 @@ int main(int argc, char *argv[])
if( M.icorshear != 0 )
cor_shear();
#ifdef PARALLEL
MPI_Finalize();
#endif
return 0;
}
......@@ -9,7 +9,6 @@
#include<structure.h>
#include "bayesys3.h"
#include "userstr.h"
#include <time.h>
/****************************************************************/
/* nom: o_run_bayes */
......@@ -20,12 +19,6 @@
* Optimise the potential parameters using the bayesys3 algorithm.
*
*/
#ifdef PARALLEL
static void bayesWait();
static void stopSlaves();
#endif
typedef void (*sighandler_t)(int);
static void signalReset();
int optInterrupt; // Global variable read in bayesapp.c/UserMonitor()
......@@ -49,18 +42,13 @@ double o_run_bayes()
int nDim = 0; //# of parameters
int ipx; //index of the current parameter in the Param
int i; //index of the clump in the lens[] global variable
int k; //index of the z_m_limit images to optimise
int k; //index of the z_m_limit images to optimise
int j;
FILE *bayes;
char name[60];
#ifdef PARALLEL
extern int myid;
if( myid != 0 )
bayesWait();
#endif
// Clean the results files
#ifdef DEBUG
bayes= fopen( "bayes.dbg.dat" , "w" );
......@@ -104,8 +92,15 @@ double o_run_bayes()
for( k = 0; k < I.nzlim; k++ )
if( zlim[k].opt != 0 )
{
nDim++;
fprintf( bayes, "#Redshift of %s\n", zlim[k].n );
//nDim+
i = 0;
while( indexCmp( multi[i][0].n, zlim[k].n ) ) i++;
for( j = 0; j < I.mult[i]; j++ )
{
fprintf( bayes, "#Redshift of %s\n", multi[i][j].n );
nDim++;
}
//fprintf( bayes, "#Redshift of %s\n", zlim[k].n );
}
// Potfile parameters to optimise
......@@ -145,7 +140,7 @@ double o_run_bayes()
// The noise
if( I.dsigposAs != -1. )
{
nDim += I.n_mult;
nDim+=I.n_mult;
for( i = 0; i < I.n_mult; i++ )
fprintf( bayes, "#SigposArsec %s (arcsec)\n",multi[i][0].n);
}
......@@ -188,10 +183,6 @@ double o_run_bayes()
//Run bayesys
BayeSys3(Common, Objects);
#ifdef PARALLEL
stopSlaves();
#endif
// Reset the SIGINT signal to its default behavior
signal(SIGINT, SIG_DFL);
......@@ -217,78 +208,3 @@ static void signalReset()
optInterrupt = 1;
fprintf( stderr, "INFO: Optimisation interrupted by CTRL-C\r");
}
#ifdef PARALLEL
#include "mpi.h"
/* Wait for a message on channel 100 containing the Cube to process
* Return a message on channel 200 to processor 0 containing
* {valid, chi2, Lhood0} if valid = 1
* {valid, 0, 0} if valid = 0
*/
static void bayesWait()
{
double getLhood0(); // defined in o_chi.c
MPI_Status status;
double *Cube;
int nDim;
double temp[3];
extern int myid;
#ifdef MPIDEBUG
unsigned long int count=0;
#endif
temp[0] = 0.;
temp[1] = 0.;
temp[2] = 0.;
MPI_Recv(&nDim, 1, MPI_INT, 0, 100, MPI_COMM_WORLD, &status);
#ifdef MPIDEBUG
printf("bayesWait: Data received (%d)...\n",count);
count++;
#endif
Cube = (double *) malloc( nDim * sizeof(double) );
while( nDim != -1 )
{
MPI_Recv(Cube, nDim, MPI_DOUBLE, 0, 150, MPI_COMM_WORLD, &status);
/* Set the clumps parameters from the cube and eventually reject the whole object*/
temp[0] = (double)rescaleCube_1Atom(Cube,nDim);
if( temp[0] )
{
temp[1] = o_chi();
temp[2] = getLhood0();
}
#ifdef MPIDEBUG
printf("bayesWait: Send data (%d) [%lf,%lf,%lf]...\n",count,
temp[0],temp[1],temp[2]);
#endif
MPI_Send(temp, 3, MPI_DOUBLE, 0, 200, MPI_COMM_WORLD);
MPI_Recv(&nDim, 1, MPI_INT, 0, 100, MPI_COMM_WORLD, &status);
#ifdef MPIDEBUG
printf("bayesWait: Data received (%d)...\n",count);
count++;
#endif
}
free( Cube );
MPI_Finalize();
exit(0);
}
/* Send the -1 Signal to all the slaves processes
*/
static void stopSlaves()
{
extern int numprocs;
int val,j;
val = -1;
for( j = 1; j <= numprocs; j++ )
MPI_Send(&val, 1, MPI_INT, j, 100, MPI_COMM_WORLD);
}
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment