Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
135 changes: 70 additions & 65 deletions tools/01_NAO_generation/SIAB/src_parallel/parallel_common.cpp
Original file line number Diff line number Diff line change
@@ -1,101 +1,106 @@
#include "parallel_common.h"

#include <string.h> //this is needed because strcpy

#ifdef __MPI
void Parallel_Common::bcast_string(string &object)
void Parallel_Common::bcast_string(string& object)
{
char swap[100];
if(MY_RANK == 0) strcpy(swap, object.c_str() );
MPI_Bcast(swap, 100, MPI_CHAR, 0, MPI_COMM_WORLD);
if(MY_RANK != 0) object = static_cast<string>( swap );
// cout<<"\n"<<object;
return;
char swap[100];
if (MY_RANK == 0)
strcpy(swap, object.c_str());
MPI_Bcast(swap, 100, MPI_CHAR, 0, MPI_COMM_WORLD);
if (MY_RANK != 0)
object = static_cast<string>(swap);
// cout<<"\n"<<object;
return;
}

void Parallel_Common::bcast_string(string *object,const int n)
void Parallel_Common::bcast_string(string* object, const int n)
{
for(int i=0;i<n;i++)
{
char swap[100];
if(MY_RANK == 0) strcpy(swap, object[i].c_str() );
MPI_Bcast(swap, 100, MPI_CHAR, 0, MPI_COMM_WORLD);
if(MY_RANK != 0) object[i] = static_cast<string>( swap );
}
return;
for (int i = 0; i < n; i++)
{
char swap[100];
if (MY_RANK == 0)
strcpy(swap, object[i].c_str());
MPI_Bcast(swap, 100, MPI_CHAR, 0, MPI_COMM_WORLD);
if (MY_RANK != 0)
object[i] = static_cast<string>(swap);
}
return;
}

void Parallel_Common::bcast_complex_double(complex<double> &object)
void Parallel_Common::bcast_complex_double(complex<double>& object)
{
double a = object.real();
double b = object.imag();
Parallel_Common::bcast_double(a);
Parallel_Common::bcast_double(b);
object = std::complex<double>( a, b);
return;
double a = object.real();
double b = object.imag();
Parallel_Common::bcast_double(a);
Parallel_Common::bcast_double(b);
object = std::complex<double>(a, b);
return;
}

void Parallel_Common::bcast_complex_double(complex<double> *object, const int n)
void Parallel_Common::bcast_complex_double(complex<double>* object, const int n)
{
double *a = new double[n];
double *b = new double[n];

for(int i=0; i<n; i++)
{
a[i] = object[i].real();
b[i] = object[i].imag();
}

Parallel_Common::bcast_double( a, n);
Parallel_Common::bcast_double( b, n);

for(int i=0; i<n; i++)
{
object[i] = std::complex<double>( a[i], b[i]);
}
delete[] a;
delete[] b;
double* a = new double[n];
double* b = new double[n];

for (int i = 0; i < n; i++)
{
a[i] = object[i].real();
b[i] = object[i].imag();
}

Parallel_Common::bcast_double(a, n);
Parallel_Common::bcast_double(b, n);

for (int i = 0; i < n; i++)
{
object[i] = std::complex<double>(a[i], b[i]);
}
delete[] a;
delete[] b;
}

void Parallel_Common::bcast_double(double &object)
void Parallel_Common::bcast_double(double& object)
{
MPI_Bcast(&object, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD);
// cout<<"\n"<<object;
return;
MPI_Bcast(&object, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD);
// cout<<"\n"<<object;
return;
}

void Parallel_Common::bcast_double(double *object,const int n)
void Parallel_Common::bcast_double(double* object, const int n)
{
MPI_Bcast(object, n, MPI_DOUBLE, 0, MPI_COMM_WORLD);
MPI_Bcast(object, n, MPI_DOUBLE, 0, MPI_COMM_WORLD);
}

void Parallel_Common::bcast_int(int &object)
void Parallel_Common::bcast_int(int& object)
{
MPI_Bcast(&object, 1, MPI_INT, 0, MPI_COMM_WORLD);
// cout<<"\n"<<object;
return;
MPI_Bcast(&object, 1, MPI_INT, 0, MPI_COMM_WORLD);
// cout<<"\n"<<object;
return;
}

void Parallel_Common::bcast_int(int *object,const int n)
void Parallel_Common::bcast_int(int* object, const int n)
{
MPI_Bcast(object,n,MPI_INT,0,MPI_COMM_WORLD);
MPI_Bcast(object, n, MPI_INT, 0, MPI_COMM_WORLD);
}

void Parallel_Common::bcast_bool(bool &object)
void Parallel_Common::bcast_bool(bool& object)
{
int swap = object;
if(MY_RANK == 0)swap = object;
int swap = object;
if (MY_RANK == 0)
swap = object;
MPI_Bcast(&swap, 1, MPI_INT, 0, MPI_COMM_WORLD);
if(MY_RANK != 0)object = static_cast<bool>( swap );
// cout<<"\n"<<object;
return;
if (MY_RANK != 0)
object = static_cast<bool>(swap);
// cout<<"\n"<<object;
return;
}

void Parallel_Common::bcast_char(char *object,const int n)
void Parallel_Common::bcast_char(char* object, const int n)
{
MPI_Bcast(object, n, MPI_CHAR, 0, MPI_COMM_WORLD);
return;
MPI_Bcast(object, n, MPI_CHAR, 0, MPI_COMM_WORLD);
return;
}



#endif
28 changes: 14 additions & 14 deletions tools/01_NAO_generation/SIAB/src_parallel/parallel_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@

namespace Parallel_Common
{
//(1) bcast array
void bcast_complex_double( std::complex<double> *object, const int n);
void bcast_string(string *object,const int n);
void bcast_double(double *object,const int n);
void bcast_int(int *object,const int n);
void bcast_char(char *object,const int n);

//(2) bcast single
void bcast_complex_double( std::complex<double> &object);
void bcast_string(string &object);
void bcast_double(double &object);
void bcast_int(int &object);
void bcast_bool(bool &object);
//(1) bcast array
void bcast_complex_double(std::complex<double>* object, const int n);
void bcast_string(string* object, const int n);
void bcast_double(double* object, const int n);
void bcast_int(int* object, const int n);
void bcast_char(char* object, const int n);

}
//(2) bcast single
void bcast_complex_double(std::complex<double>& object);
void bcast_string(string& object);
void bcast_double(double& object);
void bcast_int(int& object);
void bcast_bool(bool& object);

} // namespace Parallel_Common

#endif
81 changes: 41 additions & 40 deletions tools/01_NAO_generation/SIAB/src_parallel/parallel_global.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,62 +3,63 @@
// DATE : 2009-11-08
//==========================================================
#include "parallel_global.h"

#include "../src_spillage/tools.h"
#include "parallel_common.h"
#include "parallel_reduce.h"
#include "../src_spillage/tools.h"

using namespace std;

#if defined __MPI
MPI_Comm POOL_WORLD;

void Parallel_Global::myProd(complex<double> *in, std::complex<double> *inout,int *len,MPI_Datatype *dptr)
void Parallel_Global::myProd(complex<double>* in, std::complex<double>* inout, int* len, MPI_Datatype* dptr)
{
for(int i=0;i<*len;i++)
{
(*inout).real()=(*inout).real()+(*in).real();
(*inout).imag()=(*inout).imag()+(*in).imag();
in++;
inout++;
}
return;
for (int i = 0; i < *len; i++)
{
(*inout).real() = (*inout).real() + (*in).real();
(*inout).imag() = (*inout).imag() + (*in).imag();
in++;
inout++;
}
return;
}
#endif

void Parallel_Global::read_pal_param(int argc,char **argv)
void Parallel_Global::read_pal_param(int argc, char** argv)
{
#if defined __MPI
//for test
/*
cout << "\n Hello! Test MPI NOW : argc = "<<argc<<endl;
for(int i=0;i<argc;i++)
{
cout<<"\n argv["<<i<<"]="<<argv[i];
}
cout<<endl;
*/
MPI_Init(&argc,&argv);
//----------------------------------------------------------
// int atoi ( const char * str );
// atoi : Convert string to int type
// atof : Convert string to double type
// atol : Convert string to long int type
//----------------------------------------------------------
// KPAR = atoi(argv[1]); // mohan abandon 2010-06-09
// for test
/*
cout << "\n Hello! Test MPI NOW : argc = "<<argc<<endl;
for(int i=0;i<argc;i++)
{
cout<<"\n argv["<<i<<"]="<<argv[i];
}
cout<<endl;
*/
MPI_Init(&argc, &argv);
//----------------------------------------------------------
// int atoi ( const char * str );
// atoi : Convert string to int type
// atof : Convert string to double type
// atol : Convert string to long int type
//----------------------------------------------------------
// KPAR = atoi(argv[1]); // mohan abandon 2010-06-09

// get the size --> NPROC
// get the rank --> MY_RANK
MPI_Comm_size(MPI_COMM_WORLD,&NPROC);
MPI_Comm_rank(MPI_COMM_WORLD,&MY_RANK);
// get the size --> NPROC
// get the rank --> MY_RANK
MPI_Comm_size(MPI_COMM_WORLD, &NPROC);
MPI_Comm_rank(MPI_COMM_WORLD, &MY_RANK);

for(int i=0; i<NPROC; i++)
{
if(i==MY_RANK)
{
cout << " My rank is " << MY_RANK << endl;
}
MPI_Barrier(MPI_COMM_WORLD);
}
for (int i = 0; i < NPROC; i++)
{
if (i == MY_RANK)
{
cout << " My rank is " << MY_RANK << endl;
}
MPI_Barrier(MPI_COMM_WORLD);
}
#endif
return;
}
9 changes: 4 additions & 5 deletions tools/01_NAO_generation/SIAB/src_parallel/parallel_global.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,15 @@
extern MPI_Comm POOL_WORLD;
#endif

//void myProd(complex<double> *in, std::complex<double> *inout,int *len,MPI_Datatype *dptr);
// void myProd(complex<double> *in, std::complex<double> *inout,int *len,MPI_Datatype *dptr);

namespace Parallel_Global
{
void read_pal_param(int argc, char **argv);
void read_pal_param(int argc, char** argv);

#ifdef __MPI
void myProd(complex<double> *in, std::complex<double> *inout,int *len,MPI_Datatype *dptr);
void myProd(complex<double>* in, std::complex<double>* inout, int* len, MPI_Datatype* dptr);
#endif
}

} // namespace Parallel_Global

#endif // GMPI
Loading
Loading