close

Вход

Забыли?

вход по аккаунту

код для вставкиСкачать
#include<limits.h>
#include<math.h>
#include<omp.h>
#include<mpi.h>
#include<stdio.h>
#include<unistd.h>
#define NUM_TRAPEZOIDS 100000
#if 1
__attribute__((target(mic))) inline double f(double x) {
return 1.00*x*x*exp(-(x-0.0)*(x-0.0)/(2.0*0.25*0.25))
+0.50*x*x*exp(-(x-0.2)*(x-0.2)/(2.0*0.50*0.50))
+0.50*x*x*exp(-(x-0.4)*(x-0.4)/(2.0*1.00*1.00))
+0.25*x*x*exp(-(x+0.4)*(x+0.4)/(2.0*1.00*1.00));
}
#endif
int main(intargc,char *argv[])
{
intnamelen,rank,size;
char name[MPI_MAX_PROCESSOR_NAME];
doubleupper_bound=5.0,lower_bound=-5.0;
double x0,x1,width;
double integral=0;
doublecompute_time,total_time;
intchunk_size,i;
MPI_Init(&argc,&argv);
MPI_Comm_size(MPI_COMM_WORLD,&size);
MPI_Comm_rank(MPI_COMM_WORLD,&rank);
MPI_Get_processor_name(name,&namelen);
printf("myrank=%d,size=%d,name=%s \n",rank,size,name);
chunk_size = NUM_TRAPEZOIDS/size;
x0=lower_bound+(upper_bound-lower_bound)*rank/size;
x1=x0+(upper_bound-lower_bound)/size;
width=(x1-x0)/chunk_size;
MPI_Barrier(MPI_COMM_WORLD);
compute_time=total_time=MPI_Wtime();
#if 1
#pragma offload target(mic:0)
{
#ifdef __INTEL_OFFLOAD
charmicname[HOST_NAME_MAX];
gethostname(micname,HOST_NAME_MAX);
//printf("_________micname1=%s,HOST_NAME_MAX=%d\n",micname,HOST_NAME_MAX);
#pragma omp parallel
//#pragma omp critical
#pragma omp for reduction(+:integral)
for( i=0;i<chunk_size;i++) {
if(i%50000==0)
{printf("i=%d\n",i);printf("___thread=%d,____micname=%s\n",omp_get_thread_num(),micname
);}
integral+=0.5*width
*(f(x0+width*i)+f(x0+width*(i+1)));
}
#endif
}
compute_time=MPI_Wtime()- compute_time;
MPI_Allreduce(MPI_IN_PLACE,&integral,1,MPI_DOUBLE,MPI_SUM,MPI_COMM_WORLD);
total_time=MPI_Wtime() - total_time;
printf("myrank %d of %d on %s :%f seconds\n",
rank,size,name,compute_time);
if(rank==0)
{
printf("integral=%f,time=%f\n",integral,total_time);
}
#endif
MPI_Finalize();
return(0);
}
Run.sh
#! /bin/csh -f
setenv MIC_OMP_NUM_THREADS 1201
setenv MIC_ENV_PREFIX MIC
setenv MIC_STACKSIZE 5M
mpicc -openmp -o trap-offload ./trapezoid.c
mpirun -n 1 -env MIC_KMP_AFFINITY proclist=[1-120],explicit,granularity=thread ./trap-offload:
-n 1 -env MIC_KMP_AFFINITY proclist=[121-240],explict,granularity=thread ./trap-offload
error:
mpirun: No match
1/--страниц
Пожаловаться на содержимое документа