Skip to content
Extraits de code Groupes Projets
Valider 08504bd8 rédigé par Nicolas MARIE's avatar Nicolas MARIE
Parcourir les fichiers

pgpu debut TP3

parent e22de7af
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -6,7 +6,7 @@ int main(int argc, char** argv)
{
double alpha = 2;
double *X = NULL, *Y = NULL;
int N = 1000;
int N = 100000000;
if (argc > 1) N = atoi(argv[1]);
X = (double*) malloc(sizeof(double) * N);
......@@ -18,6 +18,8 @@ int main(int argc, char** argv)
Y[i] = X[i] + i;
}
int runningOnGPU = 0;
#pragma omp target teams distribute parallel for map(to: X[:N]) map(tofrom: Y[:N]) map(from: runningOnGPU)
for(int i = 0; i < N; ++i)
{
Y[i] += alpha * X[i];
......
......@@ -19,21 +19,25 @@ double get_elapsedtime(void)
void mult(int N, float *A, float* B, float* C)
{
int i = 0, j = 0, k = 0;
int total_size = N*N;
//int total_size = N*N;
#pragma omp target teams distribute parallel for map(to: A) map(to: B) map(from: C)
for(i = 0; i < N; ++i)
{
for(j = 0; j < N; ++j)
{
float val = 0.;
for(k = 0; k < N; ++k)
{
val += A[i * N + k] * B[k * N + j];
C[i * N + j] += A[i * N + k] * B[k * N + j];
}
C[i * N + j] = val;
}
}
}
[[clang::optnone]]
void donotopti(float *C){
return;
}
int main(int argc, char** argv)
{
double t0 = 0., t1 = 0., duration = 0.;
......@@ -77,5 +81,7 @@ int main(int argc, char** argv)
fprintf(stdout, " Elapsed Time : %f\n", duration);
donotopti(C);
return 0;
}
CC=clang -fopenmp -fopenmp-targets=nvptx64-nvidia-cuda -Xopenmp-target -march=sm_61
CC=clang -fopenmp -fopenmp-targets=nvptx64-nvidia-cuda
CFLAGS=-O3 -Wall
LDFLAGS=-lm -lrt
......
......@@ -17,5 +17,17 @@ int main()
else
printf("### Unable to use the GPU, using CPU! ###\n");
printf("Nb. devices: %d\n", omp_get_num_devices());
int team = 0;
#pragma omp target map(from: team)
{
#pragma omp teams
{
team = omp_get_num_teams();
}
}
printf("Nb. teams: %d\n", team);
return 0;
}
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter