Révision 125
| Pi/C/Hybrid/Pi_Hybrid.c (revision 125) | ||
|---|---|---|
| 43 | 43 |
#endif |
| 44 | 44 |
|
| 45 | 45 |
typedef struct compute_node {
|
| 46 |
LENGTH iterations;
|
|
| 47 |
int process;
|
|
| 46 |
LENGTH iterations; |
|
| 47 |
int process; |
|
| 48 | 48 |
} node; |
| 49 | 49 |
|
| 50 |
typedef struct compute_result {
|
|
| 51 |
LENGTH inside; |
|
| 52 |
long int useconds; |
|
| 53 |
} result; |
|
| 54 |
|
|
| 50 | 55 |
unsigned int rotl(unsigned int value, int shift) {
|
| 51 |
return (value << shift) | (value >> (sizeof(value) * CHAR_BIT - shift));
|
|
| 56 |
return (value << shift) | (value >> (sizeof(value) * CHAR_BIT - shift)); |
|
| 52 | 57 |
} |
| 53 |
|
|
| 58 |
|
|
| 54 | 59 |
unsigned int rotr(unsigned int value, int shift) {
|
| 55 |
return (value >> shift) | (value << (sizeof(value) * CHAR_BIT - shift));
|
|
| 60 |
return (value >> shift) | (value << (sizeof(value) * CHAR_BIT - shift)); |
|
| 56 | 61 |
} |
| 57 | 62 |
|
| 58 | 63 |
LENGTH MainLoopGlobal(LENGTH iterations,unsigned int seed_w,unsigned int seed_z) |
| 59 | 64 |
{
|
| 60 |
|
|
| 65 |
|
|
| 61 | 66 |
#if defined TCONG |
| 62 |
unsigned int jcong=seed_z;
|
|
| 67 |
unsigned int jcong=seed_z; |
|
| 63 | 68 |
#elif defined TSHR3 |
| 64 |
unsigned int jsr=seed_w;
|
|
| 69 |
unsigned int jsr=seed_w; |
|
| 65 | 70 |
#elif defined TMWC |
| 66 |
unsigned int z=seed_z;
|
|
| 67 |
unsigned int w=seed_w;
|
|
| 71 |
unsigned int z=seed_z; |
|
| 72 |
unsigned int w=seed_w; |
|
| 68 | 73 |
#elif defined TKISS |
| 69 |
unsigned int jcong=seed_z;
|
|
| 70 |
unsigned int jsr=seed_w;
|
|
| 71 |
unsigned int z=seed_z;
|
|
| 72 |
unsigned int w=seed_w;
|
|
| 74 |
unsigned int jcong=seed_z; |
|
| 75 |
unsigned int jsr=seed_w; |
|
| 76 |
unsigned int z=seed_z; |
|
| 77 |
unsigned int w=seed_w; |
|
| 73 | 78 |
#endif |
| 74 | 79 |
|
| 75 |
LENGTH total=0;
|
|
| 76 |
|
|
| 77 |
for (LENGTH i=0;i<iterations;i++) {
|
|
| 78 |
|
|
| 80 |
LENGTH total=0; |
|
| 81 |
|
|
| 82 |
for (LENGTH i=0;i<iterations;i++) {
|
|
| 83 |
|
|
| 79 | 84 |
#if defined TINT32 |
| 80 |
#define THEONE 1073741824
|
|
| 81 |
#if defined TCONG
|
|
| 82 |
unsigned int x=CONG>>17 ;
|
|
| 83 |
unsigned int y=CONG>>17 ;
|
|
| 84 |
#elif defined TSHR3
|
|
| 85 |
unsigned int x=SHR3>>17 ;
|
|
| 86 |
unsigned int y=SHR3>>17 ;
|
|
| 87 |
#elif defined TMWC
|
|
| 88 |
unsigned int x=MWC>>17 ;
|
|
| 89 |
unsigned int y=MWC>>17 ;
|
|
| 90 |
#elif defined TKISS
|
|
| 91 |
unsigned int x=KISS>>17 ;
|
|
| 92 |
unsigned int y=KISS>>17 ;
|
|
| 93 |
#endif
|
|
| 85 |
#define THEONE 1073741824 |
|
| 86 |
#if defined TCONG |
|
| 87 |
unsigned int x=CONG>>17 ; |
|
| 88 |
unsigned int y=CONG>>17 ; |
|
| 89 |
#elif defined TSHR3 |
|
| 90 |
unsigned int x=SHR3>>17 ; |
|
| 91 |
unsigned int y=SHR3>>17 ; |
|
| 92 |
#elif defined TMWC |
|
| 93 |
unsigned int x=MWC>>17 ; |
|
| 94 |
unsigned int y=MWC>>17 ; |
|
| 95 |
#elif defined TKISS |
|
| 96 |
unsigned int x=KISS>>17 ; |
|
| 97 |
unsigned int y=KISS>>17 ; |
|
| 98 |
#endif |
|
| 94 | 99 |
#elif defined TINT64 |
| 95 |
#define THEONE 4611686018427387904
|
|
| 96 |
#if defined TCONG
|
|
| 97 |
unsigned long x=(unsigned long)(CONG>>1) ;
|
|
| 98 |
unsigned long y=(unsigned long)(CONG>>1) ;
|
|
| 99 |
#elif defined TSHR3
|
|
| 100 |
unsigned long x=(unsigned long)(SHR3>>1) ;
|
|
| 101 |
unsigned long y=(unsigned long)(SHR3>>1) ;
|
|
| 102 |
#elif defined TMWC
|
|
| 103 |
unsigned long x=(unsigned long)(MWC>>1) ;
|
|
| 104 |
unsigned long y=(unsigned long)(MWC>>1) ;
|
|
| 105 |
#elif defined TKISS
|
|
| 106 |
unsigned long x=(unsigned long)(KISS>>1) ;
|
|
| 107 |
unsigned long y=(unsigned long)(KISS>>1) ;
|
|
| 108 |
#endif
|
|
| 100 |
#define THEONE 4611686018427387904 |
|
| 101 |
#if defined TCONG |
|
| 102 |
unsigned long x=(unsigned long)(CONG>>1) ; |
|
| 103 |
unsigned long y=(unsigned long)(CONG>>1) ; |
|
| 104 |
#elif defined TSHR3 |
|
| 105 |
unsigned long x=(unsigned long)(SHR3>>1) ; |
|
| 106 |
unsigned long y=(unsigned long)(SHR3>>1) ; |
|
| 107 |
#elif defined TMWC |
|
| 108 |
unsigned long x=(unsigned long)(MWC>>1) ; |
|
| 109 |
unsigned long y=(unsigned long)(MWC>>1) ; |
|
| 110 |
#elif defined TKISS |
|
| 111 |
unsigned long x=(unsigned long)(KISS>>1) ; |
|
| 112 |
unsigned long y=(unsigned long)(KISS>>1) ; |
|
| 113 |
#endif |
|
| 109 | 114 |
#elif defined TFP32 |
| 110 |
#define THEONE 1.0f
|
|
| 111 |
#if defined TCONG
|
|
| 112 |
float x=CONGfp ;
|
|
| 113 |
float y=CONGfp ;
|
|
| 114 |
#elif defined TSHR3
|
|
| 115 |
float x=SHR3fp ;
|
|
| 116 |
float y=SHR3fp ;
|
|
| 117 |
#elif defined TMWC
|
|
| 118 |
float x=MWCfp ;
|
|
| 119 |
float y=MWCfp ;
|
|
| 120 |
#elif defined TKISS
|
|
| 121 |
float x=KISSfp ;
|
|
| 122 |
float y=KISSfp ;
|
|
| 123 |
#endif
|
|
| 115 |
#define THEONE 1.0f |
|
| 116 |
#if defined TCONG |
|
| 117 |
float x=CONGfp ; |
|
| 118 |
float y=CONGfp ; |
|
| 119 |
#elif defined TSHR3 |
|
| 120 |
float x=SHR3fp ; |
|
| 121 |
float y=SHR3fp ; |
|
| 122 |
#elif defined TMWC |
|
| 123 |
float x=MWCfp ; |
|
| 124 |
float y=MWCfp ; |
|
| 125 |
#elif defined TKISS |
|
| 126 |
float x=KISSfp ; |
|
| 127 |
float y=KISSfp ; |
|
| 128 |
#endif |
|
| 124 | 129 |
#elif defined TFP64 |
| 125 |
#define THEONE 1.0f |
|
| 126 |
#if defined TCONG |
|
| 127 |
double x=(double)CONGfp ; |
|
| 128 |
double y=(double)CONGfp ; |
|
| 129 |
#elif defined TSHR3 |
|
| 130 |
double x=(double)SHR3fp ; |
|
| 131 |
double y=(double)SHR3fp ; |
|
| 132 |
#elif defined TMWC |
|
| 133 |
double x=(double)MWCfp ; |
|
| 134 |
double y=(double)MWCfp ; |
|
| 135 |
#elif defined TKISS |
|
| 136 |
double x=(double)KISSfp ; |
|
| 137 |
double y=(double)KISSfp ; |
|
| 138 |
#endif |
|
| 130 |
#define THEONE 1.0f |
|
| 131 |
#if defined TCONG |
|
| 132 |
double x=(double)CONGfp ; |
|
| 133 |
double y=(double)CONGfp ; |
|
| 134 |
#elif defined TSHR3 |
|
| 135 |
double x=(double)SHR3fp ; |
|
| 136 |
double y=(double)SHR3fp ; |
|
| 137 |
#elif defined TMWC |
|
| 138 |
double x=(double)MWCfp ; |
|
| 139 |
double y=(double)MWCfp ; |
|
| 140 |
#elif defined TKISS |
|
| 141 |
double x=(double)KISSfp ; |
|
| 142 |
double y=(double)KISSfp ; |
|
| 139 | 143 |
#endif |
| 144 |
#endif |
|
| 140 | 145 |
|
| 141 |
// Matching test
|
|
| 142 |
unsigned long inside=((x*x+y*y) < THEONE) ? 1:0;
|
|
| 143 |
total+=inside;
|
|
| 144 |
}
|
|
| 145 |
|
|
| 146 |
return(total);
|
|
| 147 |
|
|
| 146 |
// Matching test |
|
| 147 |
unsigned long inside=((x*x+y*y) < THEONE) ? 1:0; |
|
| 148 |
total+=inside; |
|
| 149 |
} |
|
| 150 |
|
|
| 151 |
return(total); |
|
| 152 |
|
|
| 148 | 153 |
} |
| 149 | 154 |
|
| 150 | 155 |
int main(int argc, char *argv[]) {
|
| 151 |
|
|
| 156 |
|
|
| 152 | 157 |
unsigned int seed_z=362436069,seed_w=52128862,process=PROCESS; |
| 153 | 158 |
// Number of NP or OpenMP processes <1024 |
| 154 |
LENGTH iterations=ITERATIONS,insideMPI[1024],insideOpenMP[1024],
|
|
| 155 |
part_inside,part_iterations,insides;
|
|
| 159 |
LENGTH iterations=ITERATIONS,insideMPI[8192],insideOpenMP[1024],
|
|
| 160 |
part_inside=0,part_iterations,insides=0;
|
|
| 156 | 161 |
int numtasks,rank,rc,tag=1,i; |
| 157 | 162 |
float pi; |
| 158 | 163 |
|
| 159 | 164 |
// Hostname supposed to be <128 characters |
| 160 | 165 |
char hostname[128]; |
| 161 |
|
|
| 166 |
|
|
| 162 | 167 |
gethostname(hostname, sizeof hostname); |
| 163 |
|
|
| 164 |
#ifdef TIME |
|
| 168 |
|
|
| 165 | 169 |
struct timeval start,end; |
| 166 | 170 |
long int useconds; |
| 167 |
#endif |
|
| 168 |
|
|
| 171 |
|
|
| 169 | 172 |
MPI_Status Stat; |
| 170 | 173 |
|
| 171 | 174 |
rc = MPI_Init(&argc,&argv); |
| ... | ... | |
| 175 | 178 |
} |
| 176 | 179 |
|
| 177 | 180 |
MPI_Comm_size(MPI_COMM_WORLD,&numtasks); |
| 178 |
|
|
| 179 |
const int nitems=2; |
|
| 180 |
int blocklengths[2] = {1,1};
|
|
| 181 |
|
|
| 181 |
MPI_Comm_rank(MPI_COMM_WORLD,&rank); |
|
| 182 |
|
|
| 183 |
const int nitems=2; |
|
| 184 |
int blocklengths[2] = {1,1};
|
|
| 185 |
|
|
| 182 | 186 |
#ifdef LONG |
| 183 |
MPI_Datatype types[2] = {MPI_LONG, MPI_INT};
|
|
| 187 |
MPI_Datatype types_node[2] = {MPI_LONG, MPI_INT};
|
|
| 188 |
MPI_Datatype types_result[2] = {MPI_LONG, MPI_LONG};
|
|
| 184 | 189 |
#else |
| 185 |
MPI_Datatype types[2] = {MPI_INT, MPI_INT};
|
|
| 190 |
MPI_Datatype types_node[2] = {MPI_INT, MPI_INT};
|
|
| 191 |
MPI_Datatype types_result[2] = {MPI_INT, MPI_LONG};
|
|
| 186 | 192 |
#endif |
| 187 |
|
|
| 188 |
MPI_Datatype mpi_node_type; |
|
| 189 |
MPI_Aint offsets[2]; |
|
| 190 |
|
|
| 191 |
offsets[0] = offsetof(node, iterations); |
|
| 192 |
offsets[1] = offsetof(node, process); |
|
| 193 |
|
|
| 194 |
MPI_Type_create_struct(nitems, blocklengths, offsets, types, &mpi_node_type); |
|
| 195 |
MPI_Type_commit(&mpi_node_type); |
|
| 196 |
|
|
| 197 |
MPI_Comm_size(MPI_COMM_WORLD,&numtasks); |
|
| 198 |
MPI_Comm_rank(MPI_COMM_WORLD,&rank); |
|
| 199 |
|
|
| 193 |
|
|
| 194 |
MPI_Datatype mpi_node_type,mpi_result_type; |
|
| 195 |
MPI_Aint offsets[2],offsetsr[2]; |
|
| 196 |
|
|
| 197 |
offsets[0] = offsetof(node, iterations); |
|
| 198 |
offsets[1] = offsetof(node, process); |
|
| 199 |
|
|
| 200 |
MPI_Type_create_struct(nitems, blocklengths, offsets, types_node, &mpi_node_type); |
|
| 201 |
MPI_Type_commit(&mpi_node_type); |
|
| 202 |
|
|
| 203 |
offsetsr[0] = offsetof(result, inside); |
|
| 204 |
offsetsr[1] = offsetof(result, useconds); |
|
| 205 |
|
|
| 206 |
MPI_Type_create_struct(nitems, blocklengths, offsetsr, types_result, &mpi_result_type); |
|
| 207 |
MPI_Type_commit(&mpi_result_type); |
|
| 208 |
|
|
| 200 | 209 |
if (rank==0) {
|
| 201 | 210 |
|
| 202 | 211 |
if (argc > 1) {
|
| ... | ... | |
| 210 | 219 |
} |
| 211 | 220 |
|
| 212 | 221 |
printf ("\n\tInformation about architecture:\n\n");
|
| 213 |
|
|
| 214 |
printf ("Sizeof int = %lld bytes.\n", (long long)sizeof(int));
|
|
| 215 |
printf ("Sizeof long = %lld bytes.\n", (long long)sizeof(long));
|
|
| 216 |
printf ("Sizeof long long = %lld bytes.\n", (long long)sizeof(long long));
|
|
| 217 | 222 |
|
| 218 |
printf ("Max int = %u\n", INT_MAX);
|
|
| 219 |
printf ("Max long = %ld\n", LONG_MAX);
|
|
| 220 |
printf ("Max long long = %lld\n\n", LLONG_MAX);
|
|
| 223 |
printf ("\tSizeof int = %lld bytes.\n", (long long)sizeof(int));
|
|
| 224 |
printf ("\tSizeof long = %lld bytes.\n", (long long)sizeof(long));
|
|
| 225 |
printf ("\tSizeof long long = %lld bytes.\n", (long long)sizeof(long long));
|
|
| 221 | 226 |
|
| 222 |
part_iterations=iterations/(numtasks*process)+1; |
|
| 227 |
printf ("\tMax int = %u\n", INT_MAX);
|
|
| 228 |
printf ("\tMax long = %ld\n", LONG_MAX);
|
|
| 229 |
printf ("\tMax long long = %lld\n\n", LLONG_MAX);
|
|
| 223 | 230 |
|
| 231 |
part_iterations=(((iterations%numtasks)%process) == 0) ? iterations/numtasks/process:iterations/numtasks/process+1 ; |
|
| 232 |
|
|
| 224 | 233 |
node send; |
| 225 | 234 |
send.iterations=part_iterations; |
| 226 | 235 |
send.process=process; |
| ... | ... | |
| 230 | 239 |
rc = MPI_Send(&send, 1, mpi_node_type, i, tag, MPI_COMM_WORLD); |
| 231 | 240 |
} |
| 232 | 241 |
|
| 233 |
#ifdef TIME |
|
| 234 | 242 |
gettimeofday(&start,(struct timezone *)0); |
| 235 |
#endif |
|
| 236 | 243 |
|
| 237 | 244 |
#pragma omp parallel for |
| 238 |
for (int i=0 ; i<process; i++) {
|
|
| 239 |
insideOpenMP[i]=MainLoopGlobal(part_iterations, |
|
| 240 |
rotr(seed_w,process), |
|
| 241 |
rotl(seed_z,process)); |
|
| 242 |
printf("\t(%s,%i) found %lld for process %i\n",hostname,0,
|
|
| 243 |
(long long)insideOpenMP[i],i); |
|
| 244 |
} |
|
| 245 |
printf("\n");
|
|
| 246 |
|
|
| 247 |
insides=0; |
|
| 248 |
for (int i=0 ; i<process; i++) {
|
|
| 249 |
insides+=insideOpenMP[i]; |
|
| 250 |
} |
|
| 251 |
|
|
| 252 |
#ifdef TIME |
|
| 245 |
for (int i=0 ; i<process; i++) {
|
|
| 246 |
insideOpenMP[i]=MainLoopGlobal(part_iterations, |
|
| 247 |
rotr(seed_w,i), |
|
| 248 |
rotl(seed_z,i)); |
|
| 249 |
/* |
|
| 250 |
printf("\t(%s,%i) found %lld for process %i\n",hostname,0,
|
|
| 251 |
(long long)insideOpenMP[i],i); */ |
|
| 252 |
} |
|
| 253 |
/* |
|
| 254 |
printf("\n");
|
|
| 255 |
*/ |
|
| 256 |
|
|
| 257 |
insides=0; |
|
| 258 |
for (int i=0 ; i<process; i++) {
|
|
| 259 |
insides+=insideOpenMP[i]; |
|
| 260 |
} |
|
| 261 |
|
|
| 253 | 262 |
gettimeofday(&end,(struct timezone *)0); |
| 254 | 263 |
useconds=(end.tv_sec-start.tv_sec)*1000000+end.tv_usec-start.tv_usec; |
| 255 | 264 |
|
| 256 |
printf("\tOn %s with %i find %lld inside in %lu useconds.\n",
|
|
| 257 |
hostname,rank,(long long)insides,useconds);
|
|
| 258 |
#else |
|
| 259 |
printf("\tOn %s with %i find %lld inside\n",hostname,rank,
|
|
| 260 |
(long long)insides);
|
|
| 265 |
printf("\tOn %s with rank #%i find %lld inside in %lu useconds.\n",
|
|
| 266 |
hostname,rank,(long long)insides,useconds); |
|
| 267 |
|
|
| 268 |
// Join part of code
|
|
| 269 |
for (i=1;i<numtasks;i++) {
|
|
| 261 | 270 |
|
| 262 |
#endif
|
|
| 271 |
result recv;
|
|
| 263 | 272 |
|
| 264 |
// Join part of code |
|
| 265 |
for (i=1;i<numtasks;i++) {
|
|
| 266 |
#ifdef LONG |
|
| 267 |
rc = MPI_Recv(&insideMPI[i], 1, MPI_LONG_LONG, i, tag, MPI_COMM_WORLD,&Stat); |
|
| 268 |
#else |
|
| 269 |
rc = MPI_Recv(&insideMPI[i], 1, MPI_INT, i, tag, MPI_COMM_WORLD,&Stat); |
|
| 270 |
#endif |
|
| 271 |
printf("\tReceive %lu inside from rank %i\n",(unsigned long)insideMPI[i],i);
|
|
| 272 |
insides+=insideMPI[i]; |
|
| 273 |
} |
|
| 273 |
rc = MPI_Recv(&recv, 1, mpi_result_type, i, tag, MPI_COMM_WORLD,&Stat); |
|
| 274 | 274 |
|
| 275 |
pi=4.*(float)insides/(float)((iterations/numtasks)*numtasks); |
|
| 275 |
insideMPI[i]=recv.inside; |
|
| 276 |
useconds=recv.useconds; |
|
| 276 | 277 |
|
| 277 |
printf("\n\tPi=%.40f\n\twith error %.40f\n\twith %lld iterations\n\n",pi,
|
|
| 278 |
fabs(pi-4*atan(1.))/pi,(long long)iterations); |
|
| 279 |
|
|
| 278 |
printf("\tReceive from rank #%i, find %lld inside in %lu useconds\n",i,(long long)insideMPI[i],useconds);
|
|
| 279 |
|
|
| 280 |
insides+=insideMPI[i]; |
|
| 281 |
} |
|
| 282 |
|
|
| 283 |
pi=4.*(float)insides/(float)(part_iterations*numtasks*process); |
|
| 284 |
|
|
| 285 |
printf("\n\tPi=%.40f\n\twith error %.40f\n\twith %lld iterations\n\n",pi,
|
|
| 286 |
fabs(pi-4*atan(1.))/pi,(long long)(part_iterations*numtasks*process)); |
|
| 287 |
|
|
| 280 | 288 |
} |
| 281 | 289 |
else |
| 282 | 290 |
{
|
| 283 | 291 |
// Receive information from master |
| 284 |
|
|
| 292 |
|
|
| 285 | 293 |
node recv; |
| 286 |
|
|
| 294 |
|
|
| 287 | 295 |
rc = MPI_Recv(&recv, 1, mpi_node_type, 0, tag, MPI_COMM_WORLD,&Stat); |
| 288 |
|
|
| 296 |
/* |
|
| 289 | 297 |
printf("\t(%s,%i) receive from master %lld with %i process\n",
|
| 290 |
hostname,rank,(long long)recv.iterations,recv.process); |
|
| 298 |
hostname,rank,(long long)recv.iterations,recv.process); |
|
| 299 |
*/ |
|
| 291 | 300 |
|
| 292 |
#ifdef TIME |
|
| 293 | 301 |
gettimeofday(&start,(struct timezone *)0); |
| 294 |
#endif |
|
| 295 |
|
|
| 302 |
|
|
| 296 | 303 |
#pragma omp parallel for |
| 297 |
for (int i=0 ; i<recv.process; i++) {
|
|
| 298 |
insideOpenMP[i]=MainLoopGlobal(recv.iterations,rotr(seed_w,rank+process),rotl(seed_z,rank+process)); |
|
| 299 |
printf("\t(%s,%i) found %lld for process %i\n",hostname,rank,
|
|
| 300 |
(long long)insideOpenMP[i],i); |
|
| 301 |
} |
|
| 302 |
printf("\n");
|
|
| 303 |
|
|
| 304 |
part_inside=0; |
|
| 305 |
for (int i=0 ; i<recv.process; i++) {
|
|
| 306 |
part_inside+=insideOpenMP[i]; |
|
| 307 |
} |
|
| 304 |
for (int i=0 ; i<recv.process; i++) {
|
|
| 305 |
insideOpenMP[i]=MainLoopGlobal(recv.iterations,rotr(seed_w,rank+i),rotl(seed_z,rank-i)); |
|
| 306 |
/* |
|
| 307 |
printf("\t(%s,%i) found %lld for process %i\n",hostname,rank,
|
|
| 308 |
(long long)insideOpenMP[i],i); |
|
| 309 |
*/ |
|
| 310 |
} |
|
| 308 | 311 |
|
| 309 |
#ifdef TIME |
|
| 312 |
/* printf("\n"); */
|
|
| 313 |
|
|
| 314 |
for (int i=0 ; i<recv.process; i++) {
|
|
| 315 |
part_inside+=insideOpenMP[i]; |
|
| 316 |
} |
|
| 317 |
|
|
| 310 | 318 |
gettimeofday(&end,(struct timezone *)0); |
| 311 | 319 |
useconds=(end.tv_sec-start.tv_sec)*1000000+end.tv_usec-start.tv_usec; |
| 320 |
/* |
|
| 321 |
printf("\tOn %s rank %i find %lld inside in %lu useconds.\n",
|
|
| 322 |
hostname,rank,(long long)part_inside,useconds); |
|
| 323 |
*/ |
|
| 324 |
result send; |
|
| 325 |
send.inside=part_inside; |
|
| 326 |
send.useconds=useconds; |
|
| 312 | 327 |
|
| 313 |
printf("\tOn %s rank %i find %lld inside in %lu useconds.\n",
|
|
| 314 |
hostname,rank,(long long)part_inside,useconds); |
|
| 315 |
#else |
|
| 316 |
printf("\tOn %s rank %i find %lld inside\n",hostname,rank,
|
|
| 317 |
(long long)part_inside); |
|
| 328 |
rc = MPI_Send(&send, 1, mpi_result_type, 0, tag, MPI_COMM_WORLD); |
|
| 318 | 329 |
|
| 319 |
#endif |
|
| 320 |
|
|
| 321 |
#ifdef LONG |
|
| 322 |
rc = MPI_Send(&part_inside, 1, MPI_LONG_LONG, 0, tag, MPI_COMM_WORLD); |
|
| 323 |
#else |
|
| 324 |
rc = MPI_Send(&part_inside, 1, MPI_INT, 0, tag, MPI_COMM_WORLD); |
|
| 325 |
#endif |
|
| 326 |
|
|
| 327 | 330 |
} |
| 328 | 331 |
|
| 329 | 332 |
MPI_Type_free(&mpi_node_type); |
| 330 |
|
|
| 333 |
MPI_Type_free(&mpi_result_type); |
|
| 334 |
|
|
| 331 | 335 |
MPI_Finalize(); |
| 332 | 336 |
|
| 333 | 337 |
} |
| Pi/C/Hybrid/Pi_aHybrid.c (revision 125) | ||
|---|---|---|
| 43 | 43 |
#endif |
| 44 | 44 |
|
| 45 | 45 |
typedef struct compute_node {
|
| 46 |
LENGTH iterations;
|
|
| 47 |
int process;
|
|
| 46 |
LENGTH iterations; |
|
| 47 |
int process; |
|
| 48 | 48 |
} node; |
| 49 | 49 |
|
| 50 |
typedef struct compute_result {
|
|
| 51 |
LENGTH inside; |
|
| 52 |
long int useconds; |
|
| 53 |
} result; |
|
| 54 |
|
|
| 50 | 55 |
unsigned int rotl(unsigned int value, int shift) {
|
| 51 |
return (value << shift) | (value >> (sizeof(value) * CHAR_BIT - shift));
|
|
| 56 |
return (value << shift) | (value >> (sizeof(value) * CHAR_BIT - shift)); |
|
| 52 | 57 |
} |
| 53 | 58 |
|
| 54 | 59 |
unsigned int rotr(unsigned int value, int shift) {
|
| 55 |
return (value >> shift) | (value << (sizeof(value) * CHAR_BIT - shift));
|
|
| 60 |
return (value >> shift) | (value << (sizeof(value) * CHAR_BIT - shift)); |
|
| 56 | 61 |
} |
| 57 | 62 |
|
| 58 | 63 |
LENGTH MainLoopGlobal(LENGTH iterations,unsigned int seed_w,unsigned int seed_z) |
| 59 | 64 |
{
|
| 60 |
|
|
| 65 |
|
|
| 61 | 66 |
#if defined TCONG |
| 62 |
unsigned int jcong=seed_z;
|
|
| 67 |
unsigned int jcong=seed_z; |
|
| 63 | 68 |
#elif defined TSHR3 |
| 64 |
unsigned int jsr=seed_w;
|
|
| 69 |
unsigned int jsr=seed_w; |
|
| 65 | 70 |
#elif defined TMWC |
| 66 |
unsigned int z=seed_z;
|
|
| 67 |
unsigned int w=seed_w;
|
|
| 71 |
unsigned int z=seed_z; |
|
| 72 |
unsigned int w=seed_w; |
|
| 68 | 73 |
#elif defined TKISS |
| 69 |
unsigned int jcong=seed_z;
|
|
| 70 |
unsigned int jsr=seed_w;
|
|
| 71 |
unsigned int z=seed_z;
|
|
| 72 |
unsigned int w=seed_w;
|
|
| 74 |
unsigned int jcong=seed_z; |
|
| 75 |
unsigned int jsr=seed_w; |
|
| 76 |
unsigned int z=seed_z; |
|
| 77 |
unsigned int w=seed_w; |
|
| 73 | 78 |
#endif |
| 74 | 79 |
|
| 75 |
LENGTH total=0; |
|
| 80 |
LENGTH total=0; |
|
| 81 |
|
|
| 82 |
for (LENGTH i=0;i<iterations;i++) {
|
|
| 76 | 83 |
|
| 77 |
for (LENGTH i=0;i<iterations;i++) {
|
|
| 78 |
|
|
| 79 | 84 |
#if defined TINT32 |
| 80 |
#define THEONE 1073741824
|
|
| 81 |
#if defined TCONG
|
|
| 82 |
unsigned int x=CONG>>17 ;
|
|
| 83 |
unsigned int y=CONG>>17 ;
|
|
| 84 |
#elif defined TSHR3
|
|
| 85 |
unsigned int x=SHR3>>17 ;
|
|
| 86 |
unsigned int y=SHR3>>17 ;
|
|
| 87 |
#elif defined TMWC
|
|
| 88 |
unsigned int x=MWC>>17 ;
|
|
| 89 |
unsigned int y=MWC>>17 ;
|
|
| 90 |
#elif defined TKISS
|
|
| 91 |
unsigned int x=KISS>>17 ;
|
|
| 92 |
unsigned int y=KISS>>17 ;
|
|
| 93 |
#endif
|
|
| 85 |
#define THEONE 1073741824 |
|
| 86 |
#if defined TCONG |
|
| 87 |
unsigned int x=CONG>>17 ; |
|
| 88 |
unsigned int y=CONG>>17 ; |
|
| 89 |
#elif defined TSHR3 |
|
| 90 |
unsigned int x=SHR3>>17 ; |
|
| 91 |
unsigned int y=SHR3>>17 ; |
|
| 92 |
#elif defined TMWC |
|
| 93 |
unsigned int x=MWC>>17 ; |
|
| 94 |
unsigned int y=MWC>>17 ; |
|
| 95 |
#elif defined TKISS |
|
| 96 |
unsigned int x=KISS>>17 ; |
|
| 97 |
unsigned int y=KISS>>17 ; |
|
| 98 |
#endif |
|
| 94 | 99 |
#elif defined TINT64 |
| 95 |
#define THEONE 4611686018427387904
|
|
| 96 |
#if defined TCONG
|
|
| 97 |
unsigned long x=(unsigned long)(CONG>>1) ;
|
|
| 98 |
unsigned long y=(unsigned long)(CONG>>1) ;
|
|
| 99 |
#elif defined TSHR3
|
|
| 100 |
unsigned long x=(unsigned long)(SHR3>>1) ;
|
|
| 101 |
unsigned long y=(unsigned long)(SHR3>>1) ;
|
|
| 102 |
#elif defined TMWC
|
|
| 103 |
unsigned long x=(unsigned long)(MWC>>1) ;
|
|
| 104 |
unsigned long y=(unsigned long)(MWC>>1) ;
|
|
| 105 |
#elif defined TKISS
|
|
| 106 |
unsigned long x=(unsigned long)(KISS>>1) ;
|
|
| 107 |
unsigned long y=(unsigned long)(KISS>>1) ;
|
|
| 108 |
#endif
|
|
| 100 |
#define THEONE 4611686018427387904 |
|
| 101 |
#if defined TCONG |
|
| 102 |
unsigned long x=(unsigned long)(CONG>>1) ; |
|
| 103 |
unsigned long y=(unsigned long)(CONG>>1) ; |
|
| 104 |
#elif defined TSHR3 |
|
| 105 |
unsigned long x=(unsigned long)(SHR3>>1) ; |
|
| 106 |
unsigned long y=(unsigned long)(SHR3>>1) ; |
|
| 107 |
#elif defined TMWC |
|
| 108 |
unsigned long x=(unsigned long)(MWC>>1) ; |
|
| 109 |
unsigned long y=(unsigned long)(MWC>>1) ; |
|
| 110 |
#elif defined TKISS |
|
| 111 |
unsigned long x=(unsigned long)(KISS>>1) ; |
|
| 112 |
unsigned long y=(unsigned long)(KISS>>1) ; |
|
| 113 |
#endif |
|
| 109 | 114 |
#elif defined TFP32 |
| 110 |
#define THEONE 1.0f
|
|
| 111 |
#if defined TCONG
|
|
| 112 |
float x=CONGfp ;
|
|
| 113 |
float y=CONGfp ;
|
|
| 114 |
#elif defined TSHR3
|
|
| 115 |
float x=SHR3fp ;
|
|
| 116 |
float y=SHR3fp ;
|
|
| 117 |
#elif defined TMWC
|
|
| 118 |
float x=MWCfp ;
|
|
| 119 |
float y=MWCfp ;
|
|
| 120 |
#elif defined TKISS
|
|
| 121 |
float x=KISSfp ;
|
|
| 122 |
float y=KISSfp ;
|
|
| 123 |
#endif
|
|
| 115 |
#define THEONE 1.0f |
|
| 116 |
#if defined TCONG |
|
| 117 |
float x=CONGfp ; |
|
| 118 |
float y=CONGfp ; |
|
| 119 |
#elif defined TSHR3 |
|
| 120 |
float x=SHR3fp ; |
|
| 121 |
float y=SHR3fp ; |
|
| 122 |
#elif defined TMWC |
|
| 123 |
float x=MWCfp ; |
|
| 124 |
float y=MWCfp ; |
|
| 125 |
#elif defined TKISS |
|
| 126 |
float x=KISSfp ; |
|
| 127 |
float y=KISSfp ; |
|
| 128 |
#endif |
|
| 124 | 129 |
#elif defined TFP64 |
| 125 |
#define THEONE 1.0f |
|
| 126 |
#if defined TCONG |
|
| 127 |
double x=(double)CONGfp ; |
|
| 128 |
double y=(double)CONGfp ; |
|
| 129 |
#elif defined TSHR3 |
|
| 130 |
double x=(double)SHR3fp ; |
|
| 131 |
double y=(double)SHR3fp ; |
|
| 132 |
#elif defined TMWC |
|
| 133 |
double x=(double)MWCfp ; |
|
| 134 |
double y=(double)MWCfp ; |
|
| 135 |
#elif defined TKISS |
|
| 136 |
double x=(double)KISSfp ; |
|
| 137 |
double y=(double)KISSfp ; |
|
| 138 |
#endif |
|
| 130 |
#define THEONE 1.0f |
|
| 131 |
#if defined TCONG |
|
| 132 |
double x=(double)CONGfp ; |
|
| 133 |
double y=(double)CONGfp ; |
|
| 134 |
#elif defined TSHR3 |
|
| 135 |
double x=(double)SHR3fp ; |
|
| 136 |
double y=(double)SHR3fp ; |
|
| 137 |
#elif defined TMWC |
|
| 138 |
double x=(double)MWCfp ; |
|
| 139 |
double y=(double)MWCfp ; |
|
| 140 |
#elif defined TKISS |
|
| 141 |
double x=(double)KISSfp ; |
|
| 142 |
double y=(double)KISSfp ; |
|
| 139 | 143 |
#endif |
| 140 |
|
|
| 141 |
// Matching test |
|
| 142 |
unsigned long inside=((x*x+y*y) < THEONE) ? 1:0;
|
|
| 143 |
total+=inside;
|
|
| 144 |
}
|
|
| 145 |
|
|
| 146 |
return(total); |
|
| 147 |
|
|
| 144 |
#endif |
|
| 145 |
|
|
| 146 |
// Matching test
|
|
| 147 |
unsigned long inside=((x*x+y*y) < THEONE) ? 1:0;
|
|
| 148 |
total+=inside;
|
|
| 149 |
} |
|
| 150 |
|
|
| 151 |
return(total); |
|
| 148 | 152 |
} |
| 149 | 153 |
|
| 150 | 154 |
int main(int argc, char *argv[]) {
|
| 151 | 155 |
|
| 152 | 156 |
unsigned int seed_z=362436069,seed_w=52128862,process=PROCESS; |
| 153 | 157 |
// Number of NP or OpenMP processes <1024 |
| 154 |
LENGTH iterations=ITERATIONS,insideMPI[1024],insideOpenMP[1024],
|
|
| 155 |
part_inside,part_iterations,insides;
|
|
| 158 |
LENGTH iterations=ITERATIONS,insideMPI[8192],insideOpenMP[1024],
|
|
| 159 |
part_inside=0,part_iterations,insides=0;
|
|
| 156 | 160 |
int numtasks,rank,rc,tag=1,i; |
| 157 | 161 |
float pi; |
| 158 | 162 |
|
| 159 | 163 |
// Hostname supposed to be <128 characters |
| 160 | 164 |
char hostname[128]; |
| 161 |
|
|
| 165 |
|
|
| 162 | 166 |
gethostname(hostname, sizeof hostname); |
| 163 |
|
|
| 164 |
#ifdef TIME |
|
| 167 |
|
|
| 165 | 168 |
struct timeval start,end; |
| 166 | 169 |
long int useconds; |
| 167 |
#endif |
|
| 168 |
|
|
| 170 |
|
|
| 169 | 171 |
MPI_Status Stat; |
| 170 | 172 |
MPI_Request RequestSend,RequestRecv,RequestSend2,RequestRecv2; |
| 171 | 173 |
|
| ... | ... | |
| 174 | 176 |
printf ("Error starting MPI program. Terminating.\n");
|
| 175 | 177 |
MPI_Abort(MPI_COMM_WORLD, rc); |
| 176 | 178 |
} |
| 177 |
|
|
| 179 |
|
|
| 178 | 180 |
MPI_Comm_size(MPI_COMM_WORLD,&numtasks); |
| 179 |
|
|
| 180 |
const int nitems=2; |
|
| 181 |
int blocklengths[2] = {1,1};
|
|
| 182 |
|
|
| 181 |
MPI_Comm_rank(MPI_COMM_WORLD,&rank); |
|
| 182 |
|
|
| 183 |
const int nitems=2; |
|
| 184 |
int blocklengths[2] = {1,1};
|
|
| 185 |
|
|
| 183 | 186 |
#ifdef LONG |
| 184 |
MPI_Datatype types[2] = {MPI_LONG, MPI_INT};
|
|
| 187 |
MPI_Datatype types_node[2] = {MPI_LONG, MPI_INT};
|
|
| 188 |
MPI_Datatype types_result[2] = {MPI_LONG, MPI_LONG};
|
|
| 185 | 189 |
#else |
| 186 |
MPI_Datatype types[2] = {MPI_INT, MPI_INT};
|
|
| 190 |
MPI_Datatype types_node[2] = {MPI_INT, MPI_INT};
|
|
| 191 |
MPI_Datatype types_result[2] = {MPI_INT, MPI_LONG};
|
|
| 187 | 192 |
#endif |
| 193 |
|
|
| 194 |
MPI_Datatype mpi_node_type,mpi_result_type; |
|
| 195 |
MPI_Aint offsets[2],offsetsr[2]; |
|
| 188 | 196 |
|
| 189 |
MPI_Datatype mpi_node_type; |
|
| 190 |
MPI_Aint offsets[2]; |
|
| 191 |
|
|
| 192 |
offsets[0] = offsetof(node, iterations); |
|
| 193 |
offsets[1] = offsetof(node, process); |
|
| 194 |
|
|
| 195 |
MPI_Type_create_struct(nitems, blocklengths, offsets, types, &mpi_node_type); |
|
| 196 |
MPI_Type_commit(&mpi_node_type); |
|
| 197 |
|
|
| 198 |
MPI_Comm_rank(MPI_COMM_WORLD,&rank); |
|
| 199 |
|
|
| 197 |
offsets[0] = offsetof(node, iterations); |
|
| 198 |
offsets[1] = offsetof(node, process); |
|
| 199 |
|
|
| 200 |
MPI_Type_create_struct(nitems, blocklengths, offsets, types_node, &mpi_node_type); |
|
| 201 |
MPI_Type_commit(&mpi_node_type); |
|
| 202 |
|
|
| 203 |
offsetsr[0] = offsetof(result, inside); |
|
| 204 |
offsetsr[1] = offsetof(result, useconds); |
|
| 205 |
|
|
| 206 |
MPI_Type_create_struct(nitems, blocklengths, offsetsr, types_result, &mpi_result_type); |
|
| 207 |
MPI_Type_commit(&mpi_result_type); |
|
| 208 |
|
|
| 200 | 209 |
if (rank==0) {
|
| 201 | 210 |
|
| 202 | 211 |
if (argc > 1) {
|
| ... | ... | |
| 210 | 219 |
} |
| 211 | 220 |
|
| 212 | 221 |
printf ("\n\tInformation about architecture:\n\n");
|
| 213 |
|
|
| 214 |
printf ("Sizeof int = %lld bytes.\n", (long long)sizeof(int));
|
|
| 215 |
printf ("Sizeof long = %lld bytes.\n", (long long)sizeof(long));
|
|
| 216 |
printf ("Sizeof long long = %lld bytes.\n", (long long)sizeof(long long));
|
|
| 217 | 222 |
|
| 218 |
printf ("Max int = %u\n", INT_MAX);
|
|
| 219 |
printf ("Max long = %ld\n", LONG_MAX);
|
|
| 220 |
printf ("Max long long = %lld\n\n", LLONG_MAX);
|
|
| 223 |
printf ("\tSizeof int = %lld bytes.\n", (long long)sizeof(int));
|
|
| 224 |
printf ("\tSizeof long = %lld bytes.\n", (long long)sizeof(long));
|
|
| 225 |
printf ("\tSizeof long long = %lld bytes.\n", (long long)sizeof(long long));
|
|
| 221 | 226 |
|
| 222 |
part_iterations=iterations/(numtasks*process)+1; |
|
| 227 |
printf ("\tMax int = %u\n", INT_MAX);
|
|
| 228 |
printf ("\tMax long = %ld\n", LONG_MAX);
|
|
| 229 |
printf ("\tMax long long = %lld\n\n", LLONG_MAX);
|
|
| 223 | 230 |
|
| 231 |
part_iterations=(((iterations%numtasks)%process) == 0) ? iterations/numtasks/process:iterations/numtasks/process+1 ; |
|
| 232 |
|
|
| 224 | 233 |
node send; |
| 225 | 234 |
send.iterations=part_iterations; |
| 226 | 235 |
send.process=process; |
| 227 |
|
|
| 236 |
|
|
| 228 | 237 |
// Split part of code |
| 229 | 238 |
for (i=1;i<numtasks;i++) {
|
| 230 | 239 |
rc = MPI_Isend(&send, 1, mpi_node_type, i, tag, MPI_COMM_WORLD, &RequestSend); |
| 231 | 240 |
} |
| 232 | 241 |
MPI_Wait(&RequestSend,&Stat); |
| 233 | 242 |
|
| 234 |
#ifdef TIME |
|
| 235 | 243 |
gettimeofday(&start,(struct timezone *)0); |
| 236 |
#endif |
|
| 237 | 244 |
|
| 238 | 245 |
#pragma omp parallel for |
| 239 |
for (int i=0 ; i<process; i++) {
|
|
| 240 |
insideOpenMP[i]=MainLoopGlobal(part_iterations, |
|
| 241 |
rotr(seed_w,process), |
|
| 242 |
rotl(seed_z,process)); |
|
| 243 |
printf("\t(%s,%i) found %lld for process %i\n",hostname,0,
|
|
| 244 |
(long long)insideOpenMP[i],i); |
|
| 245 |
} |
|
| 246 |
printf("\n");
|
|
| 247 |
|
|
| 248 |
insides=0; |
|
| 249 |
for (int i=0 ; i<process; i++) {
|
|
| 250 |
insides+=insideOpenMP[i]; |
|
| 251 |
} |
|
| 252 |
|
|
| 253 |
#ifdef TIME |
|
| 246 |
for (int i=0 ; i<process; i++) {
|
|
| 247 |
insideOpenMP[i]=MainLoopGlobal(part_iterations, |
|
| 248 |
rotr(seed_w,i), |
|
| 249 |
rotl(seed_z,i)); |
|
| 250 |
/* |
|
| 251 |
printf("\t(%s,%i) found %lld for process %i\n",hostname,0,
|
|
| 252 |
(long long)insideOpenMP[i],i); */ |
|
| 253 |
} |
|
| 254 |
/* printf("\n"); */
|
|
| 255 |
|
|
| 256 |
for (int i=0 ; i<process; i++) {
|
|
| 257 |
insides+=insideOpenMP[i]; |
|
| 258 |
} |
|
| 259 |
|
|
| 254 | 260 |
gettimeofday(&end,(struct timezone *)0); |
| 255 | 261 |
useconds=(end.tv_sec-start.tv_sec)*1000000+end.tv_usec-start.tv_usec; |
| 256 | 262 |
|
| 257 |
printf("\tOn %s with %i find %lld inside in %lu useconds.\n",
|
|
| 258 |
hostname,rank,(long long)insides,useconds);
|
|
| 259 |
#else |
|
| 260 |
printf("\tOn %s with %i find %lld inside\n",hostname,rank,
|
|
| 261 |
(long long)insides);
|
|
| 263 |
printf("\tOn %s with rank #%i find %lld inside in %lu useconds.\n",
|
|
| 264 |
hostname,rank,(long long)insides,useconds); |
|
| 265 |
|
|
| 266 |
// Join part of code
|
|
| 267 |
for (i=1;i<numtasks;i++) {
|
|
| 262 | 268 |
|
| 263 |
#endif
|
|
| 269 |
result recv;
|
|
| 264 | 270 |
|
| 265 |
// Join part of code |
|
| 266 |
for (i=1;i<numtasks;i++) {
|
|
| 267 |
#ifdef LONG |
|
| 268 |
rc = MPI_Irecv(&insideMPI[i], 1, MPI_LONG_LONG, i, tag, |
|
| 269 |
MPI_COMM_WORLD, &RequestRecv2); |
|
| 270 |
#else |
|
| 271 |
rc = MPI_Irecv(&insideMPI[i], 1, MPI_INT, i, tag, |
|
| 272 |
MPI_COMM_WORLD, &RequestRecv2); |
|
| 273 |
#endif |
|
| 274 |
MPI_Wait(&RequestRecv2,&Stat); |
|
| 275 |
printf("\tReceive %lu inside from rank %i\n",(unsigned long)insideMPI[i],i);
|
|
| 276 |
insides+=insideMPI[i]; |
|
| 277 |
} |
|
| 271 |
rc = MPI_Irecv(&recv,1,mpi_result_type,i,tag,MPI_COMM_WORLD,&RequestRecv2); |
|
| 272 |
MPI_Wait(&RequestRecv2,&Stat); |
|
| 278 | 273 |
|
| 279 |
pi=4.*(float)insides/(float)((iterations/numtasks)*numtasks); |
|
| 274 |
insideMPI[i]=recv.inside; |
|
| 275 |
useconds=recv.useconds; |
|
| 280 | 276 |
|
| 281 |
printf("\n\tPi=%.40f\n\twith error %.40f\n\twith %lld iterations\n\n",pi,
|
|
| 282 |
fabs(pi-4*atan(1.))/pi,(long long)iterations); |
|
| 283 |
|
|
| 277 |
printf("\tReceive from rank #%i, find %lld inside in %lu useconds\n",i,(long long)insideMPI[i],useconds);
|
|
| 278 |
|
|
| 279 |
insides+=insideMPI[i]; |
|
| 280 |
} |
|
| 281 |
|
|
| 282 |
pi=4.*(float)insides/(float)(part_iterations*numtasks*process); |
|
| 283 |
|
|
| 284 |
printf("\n\tPi=%.40f\n\twith error %.40f\n\twith %lld iterations\n\n",pi,
|
|
| 285 |
fabs(pi-4*atan(1.))/pi,(long long)(part_iterations*numtasks*process)); |
|
| 286 |
|
|
| 284 | 287 |
} |
| 285 | 288 |
else |
| 286 | 289 |
{
|
| 287 | 290 |
// Receive information from master |
| 288 |
|
|
| 291 |
|
|
| 289 | 292 |
node recv; |
| 290 |
|
|
| 291 |
rc = MPI_Irecv(&recv, 1, mpi_node_type, 0, tag, MPI_COMM_WORLD, &RequestRecv);
|
|
| 293 |
|
|
| 294 |
rc = MPI_Irecv(&recv,1,mpi_node_type,0,tag,MPI_COMM_WORLD,&RequestRecv);
|
|
| 292 | 295 |
MPI_Wait(&RequestRecv,&Stat); |
| 296 |
/* |
|
| 297 |
printf("\t(%s,%i) receive from master %lld with %i process\n",
|
|
| 298 |
hostname,rank,(long long)recv.iterations,recv.process); |
|
| 299 |
*/ |
|
| 293 | 300 |
|
| 294 |
printf("\t(%s,%i) receive from master %lld with %i process\n",
|
|
| 295 |
hostname,rank,(long long)recv.iterations,recv.process); |
|
| 296 |
|
|
| 297 |
#ifdef TIME |
|
| 298 | 301 |
gettimeofday(&start,(struct timezone *)0); |
| 299 |
#endif |
|
| 300 |
|
|
| 302 |
|
|
| 301 | 303 |
#pragma omp parallel for |
| 302 |
for (int i=0 ; i<recv.process; i++) {
|
|
| 303 |
insideOpenMP[i]=MainLoopGlobal(recv.iterations,rotr(seed_w,rank+process),rotl(seed_z,rank+process)); |
|
| 304 |
printf("\t(%s,%i) found %lld for process %i\n",hostname,rank,
|
|
| 305 |
(long long)insideOpenMP[i],i); |
|
| 306 |
} |
|
| 307 |
printf("\n");
|
|
| 308 |
|
|
| 309 |
part_inside=0; |
|
| 310 |
for (int i=0 ; i<recv.process; i++) {
|
|
| 311 |
part_inside+=insideOpenMP[i]; |
|
| 312 |
} |
|
| 304 |
for (int i=0 ; i<recv.process; i++) {
|
|
| 305 |
insideOpenMP[i]=MainLoopGlobal(recv.iterations,rotr(seed_w,rank+i),rotl(seed_z,rank-i)); |
|
| 306 |
/* |
|
| 307 |
printf("\t(%s,%i) found %lld for process %i\n",hostname,rank,
|
|
| 308 |
(long long)insideOpenMP[i],i); |
|
| 309 |
*/ |
|
| 310 |
} |
|
| 311 |
/* printf("\n"); */
|
|
| 313 | 312 |
|
| 314 |
#ifdef TIME |
|
| 313 |
for (int i=0 ; i<recv.process; i++) {
|
|
| 314 |
part_inside+=insideOpenMP[i]; |
|
| 315 |
} |
|
| 316 |
|
|
| 315 | 317 |
gettimeofday(&end,(struct timezone *)0); |
| 316 | 318 |
useconds=(end.tv_sec-start.tv_sec)*1000000+end.tv_usec-start.tv_usec; |
| 317 | 319 |
|
| 320 |
/* |
|
| 318 | 321 |
printf("\tOn %s rank %i find %lld inside in %lu useconds.\n",
|
| 319 | 322 |
hostname,rank,(long long)part_inside,useconds); |
| 320 |
#else |
|
| 321 |
printf("\tOn %s rank %i find %lld inside\n",hostname,rank,
|
|
| 322 |
(long long)part_inside); |
|
| 323 |
*/ |
|
| 323 | 324 |
|
| 324 |
#endif |
|
| 325 |
|
|
| 326 |
#ifdef LONG |
|
| 327 |
rc = MPI_Isend(&part_inside, 1, MPI_LONG_LONG, 0, tag, MPI_COMM_WORLD, &RequestSend2); |
|
| 328 |
#else |
|
| 329 |
rc = MPI_Isend(&part_inside, 1, MPI_INT, 0, tag, MPI_COMM_WORLD, &RequestSend2); |
|
| 330 |
#endif |
|
| 331 |
|
|
| 325 |
result send; |
|
| 326 |
send.inside=part_inside; |
|
| 327 |
send.useconds=useconds; |
|
| 328 |
|
|
| 329 |
rc = MPI_Isend(&send, 1, mpi_result_type, 0, tag, MPI_COMM_WORLD, &RequestSend2); |
|
| 330 |
|
|
| 332 | 331 |
MPI_Wait(&RequestSend2, &Stat); |
| 333 | 332 |
} |
| 334 | 333 |
|
| 335 | 334 |
MPI_Type_free(&mpi_node_type); |
| 336 |
|
|
| 337 |
MPI_Finalize(); |
|
| 335 |
MPI_Type_free(&mpi_result_type); |
|
| 338 | 336 |
|
| 337 |
MPI_Finalize(); |
|
| 339 | 338 |
} |
| Pi/C/Hybrid/Makefile (revision 125) | ||
|---|---|---|
| 5 | 5 |
SOURCE=Pi_Hybrid.c Pi_aHybrid.c |
| 6 | 6 |
|
| 7 | 7 |
CC=mpicc.openmpi |
| 8 |
CFLAGS=-Wall -O3 -std=c99 -fopenmp |
|
| 8 |
CFLAGS=-Wall -Wno-sequence-point -O3 -std=c99 -fopenmp
|
|
| 9 | 9 |
LIBRARY=-lm |
| 10 | 10 |
|
| 11 | 11 |
all: $(SOURCE) |
| ... | ... | |
| 14 | 14 |
.PHONY: clean check mrproper |
| 15 | 15 |
|
| 16 | 16 |
mrproper: $(SOURCE) |
| 17 |
rm -rf $(foreach TVAR,$(TVARS),$(foreach TRND,$(MARSAGLIA),$(<:.c=)_$(TVAR)_$(TRND) ) )
|
|
| 17 |
$(foreach SRC,$(SOURCE),$(foreach TVAR,$(COMPUTING),$(foreach TRND,$(MARSAGLIA),rm $(SRC:.c=)_$(TVAR)_$(TRND); ) ) )
|
|
| 18 | 18 |
find . -name "*~" -exec rm {} \;
|
| 19 | 19 |
|
| 20 | 20 |
clean: |
Formats disponibles : Unified diff