Search
Task to practice on seminar: EN: 05_seminar_assignment-en.pdf CZ: 05_cviceni_zadani.pdf Prepared basic program for image sharpening (template code for seminar project 4):
OpenMP specification and documentation
Complete lectures of Tim Mattson’s (Intel)
Measure the execution time of part of a program under Windows using QueryPerformanceCounter() from windows.h library:
LARGE_INTEGER start, stop, frequency; long overhead; QueryPerformanceFrequency(&frequency); QueryPerformanceCounter(&start); QueryPerformanceCounter(&stop); overhead = stop.QuadPart-start.QuadPart; //------------------------------ QueryPerformanceCounter(&start); // ... QueryPerformanceCounter(&stop); //------------------------------ cout << " Execution time of observed program portion is " << 1000*(stop.QuadPart - start.QuadPart - overhead)/(double)frequency.QuadPart << " ms" << endl;
struct timespec start, stop; double elapsed; //------------------------------ clock_gettime(CLOCK_REALTIME, &start); // ... clock_gettime(CLOCK_REALTIME, &stop); //------------------------------ elapsed = ( stop.tv_sec - start.tv_sec )*1000 + (double)( stop.tv_nsec - start.tv_nsec )/(double)1000000; printf( " Execution time of observed program portion is %lf ms\n", elapsed);
Files for installation (to work on tasks at home):
Remark NetBeans installation is not mandatory. Programs can be edited even in Notepad (http://notepad-plus-plus.org). It is necessary to mark for in Cygwin installation next packages/components from development section:
Install also all automatically selected components. If you decide to use NetBeans:
MPI executables directory neds to be added to search path as well: setx path ”%path%;C:\Program Files (x86)\MPICH2\bin
Option setup in NetBeans IDE: Tools → Options → C/C++ → karta “Build Tools” → Tool Collection → Add.. → Cygwin Tools → Options → C/C++ → karta “Code Assistance” → Tool Collection → Cygwin and insert MPICH2 in Include directories list: C:\Program Files (x86)\MPICH2\include
On the “Build Tools” tab in the same dialog (Tools → Options → C/C++) next setup should be seen:
NetBeans setup for correct compilation of developed programs:
C Compiler: - Additional Options: -fopenmp
MPI: File → Project Properties:
C Compiler: - Include directories: .../Program Files/MPICH2/include Linker: - Additional Library directories: .../Program Files/MPICH2/lib - Libraries: mpi.lib
OpenMP & MPI: File → Project Properties:
C Compiler: - Include directories: .../Program Files/MPICH2/include - Additional Options: -fopenmp Linker: - Additional Library directories: .../Program Files/MPICH2/lib - Libraries: mpi.lib
The program.c compilation from Cygwin command line “Cygwin Bash Shell” (without NetBeans use) with g++ (gcc, mpiCC):
g++ program.c -fopenmp
MPI:
g++ program.c -I"C:\Program Files\MPICH2\include" -L"C:\Program Files\MPICH2\lib" -lmpi
OpenMP & MPI:
g++ program.c -fopenmp -I"C:\Program Files\MPICH2\include" -L"C:\Program Files\MPICH2\lib" -lmpi
Example program for development environment testing - program.c:
#include <stdio.h> #include <omp.h> int main(int argc, char *argv[]) { int iam = 0, np = 1; #pragma omp parallel default(shared) private(iam, np) { np = omp_get_num_threads(); iam = omp_get_thread_num(); printf("Hello from thread %d out of %d \n", iam, np); } return 0; }
#include <stdio.h> #include "mpi.h" int main(int argc, char *argv[]) { int numprocs, rank, namelen; char processor_name[MPI_MAX_PROCESSOR_NAME]; MPI_Init(&argc, &argv); MPI_Comm_size(MPI_COMM_WORLD, &numprocs); MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Get_processor_name(processor_name, &namelen); printf("Hello from process %d out of %d on %s\n", rank, numprocs, processor_name); MPI_Finalize(); return 0; }
#include <stdio.h> #include "mpi.h" #include <omp.h> int main(int argc, char *argv[]) { int numprocs, rank, namelen; char processor_name[MPI_MAX_PROCESSOR_NAME]; int iam = 0, np = 1; MPI_Init(&argc, &argv); MPI_Comm_size(MPI_COMM_WORLD, &numprocs); MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Get_processor_name(processor_name, &namelen); #pragma omp parallel default(shared) private(iam, np) { np = omp_get_num_threads(); iam = omp_get_thread_num(); printf("Hello from thread %d out of %d from process %d out of %d on %s\n", iam, np, rank, numprocs, processor_name); } MPI_Finalize(); return 0; }
Remark: Do not forget to copy or locate required libraries in directory with compiled and started program (usual file names: cyggcc_s-1.dll, cyggomp-1.dll, cygstdc++-6.dll, cygwin1.dll).