Last active
June 30, 2019 16:31
-
-
Save recepkarademir/a888ea7d0b3762b899752a6f827b4392 to your computer and use it in GitHub Desktop.
How to Compile and Run An OpenMP Program
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Visit : http://tdm-gcc.tdragon.net/download | |
| Download : 32Bit = tdm-gcc-5.1.0-3.exe 64Bit = tdm64-gcc-5.1.0-2.exe | |
| Download : 32Bit = gcc-5.1.0-tdm-1-openmp.zip 64Bit = gcc-5.1.0-tdm64-1-openmp.zip | |
| Unzip gcc-5.1.0-tdm-1-openmp.zip or gcc-5.1.0-tdm64-1-openmp.zip | |
| Copy all the files in the gcc-5.1.0-tdm-1-openmp or gcc-5.1.0-tdm64-1-openmp folder to the C:\TDM-GCC-64 location. | |
| It will ask you "if you really would you replace the files?" click yes to all. | |
| Open CMD(Administrator) and write these codes : | |
| cd C:/ | |
| gcc -g -Wall -fopenmp -o PRJ1 PRJ1.c | |
| You have successfully created a PRJ1.exe in C:/ directory. | |
| If you want to pass arguments into the sample.exe, you can write PRJ1 4 on CMD. | |
| PRJ1.c(Code) : | |
| #include <omp.h> | |
| #include <stdio.h> | |
| #include <stdlib.h> | |
| #define N 100 | |
| int main(int argc, char *argv[]) | |
| { | |
| int nthreads, tid, i; | |
| float a[N], b[N], c[N]; | |
| for(i=0 ; i<N; ++i) | |
| { | |
| a[i]=b[i]=i*i; | |
| } | |
| #pragma omp parallel shared(a,b,c,nthreads) private(i,tid) | |
| { | |
| tid=omp_get_thread_num(); | |
| if(tid==0) | |
| { | |
| nthreads=omp_get_num_threads(); | |
| printf("Number of thread = %d\n", nthreads); | |
| } | |
| printf("Thread %d starting... \n", tid); | |
| #pragma omp for schedule(static) | |
| for(i=0 ; i<N; ++i) | |
| { | |
| c[i] = a[i] +b[i]; | |
| printf("Thread %d: c[%d]= %f\n",tid,i,c[i]); | |
| } | |
| } | |
| system("pause"); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment