diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..9a0a2f5 --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,19 @@ +{ + "configurations": [ + { + "name": "Mac", + "includePath": [ + "${workspaceFolder}/**" + ], + "defines": [], + "macFrameworkPath": [ + "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks" + ], + "compilerPath": "/usr/bin/clang", + "cStandard": "c17", + "cppStandard": "c++17", + "intelliSenseMode": "macos-clang-arm64" + } + ], + "version": 4 +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..70e34ec --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "C_Cpp.errorSquiggles": "disabled" +} \ No newline at end of file diff --git a/image b/image new file mode 100755 index 0000000..9b171a8 Binary files /dev/null and b/image differ diff --git a/image.c b/openmp_image.c similarity index 87% rename from image.c rename to openmp_image.c index 2573a5b..69bea64 100644 --- a/image.c +++ b/openmp_image.c @@ -1,8 +1,9 @@ #include #include -#include +#include #include #include "image.h" +#include "/opt/homebrew/Cellar/libomp/16.0.1/include/omp.h" #define STB_IMAGE_IMPLEMENTATION #include "stb_image.h" @@ -59,10 +60,13 @@ uint8_t getPixelValue(Image* srcImage,int x,int y,int bit,Matrix algorithm){ void convolute(Image* srcImage,Image* destImage,Matrix algorithm){ int row,pix,bit,span; span=srcImage->bpp*srcImage->bpp; - for (row=0;rowheight;row++){ - for (pix=0;pixwidth;pix++){ - for (bit=0;bitbpp;bit++){ - destImage->data[Index(pix,row,srcImage->width,bit,srcImage->bpp)]=getPixelValue(srcImage,pix,row,bit,algorithm); + #pragma omp parallel + { + for (row=0;rowheight;row++){ + for (pix=0;pixwidth;pix++){ + for (bit=0;bitbpp;bit++){ + destImage->data[Index(pix,row,srcImage->width,bit,srcImage->bpp)]=getPixelValue(srcImage,pix,row,bit,algorithm); + } } } } @@ -90,8 +94,9 @@ enum KernelTypes GetKernelType(char* type){ //main: //argv is expected to take 2 arguments. First is the source file name (can be jpg, png, bmp, tga). Second is the lower case name of the algorithm. int main(int argc,char** argv){ - long t1,t2; - t1=time(NULL); + + struct timeval start, end; + gettimeofday(&start,NULL); stbi_set_flip_vertically_on_load(0); if (argc!=3) return Usage(); @@ -112,11 +117,17 @@ int main(int argc,char** argv){ destImage.width=srcImage.width; destImage.data=malloc(sizeof(uint8_t)*destImage.width*destImage.bpp*destImage.height); convolute(&srcImage,&destImage,algorithms[type]); + + + gettimeofday(&end,NULL); + if (end.tv_usec >= start.tv_usec){ + printf("time:%ld.%d",end.tv_sec-start.tv_sec,end.tv_usec-start.tv_usec); + }else{ + printf("time:%ld.%d",end.tv_sec-start.tv_sec-1,1000000-end.tv_usec+start.tv_usec); + } stbi_write_png("output.png",destImage.width,destImage.height,destImage.bpp,destImage.data,destImage.bpp*destImage.width); stbi_image_free(srcImage.data); free(destImage.data); - t2=time(NULL); - printf("Took %ld seconds\n",t2-t1); return 0; } \ No newline at end of file diff --git a/openmptest.c b/openmptest.c new file mode 100644 index 0000000..4607db1 --- /dev/null +++ b/openmptest.c @@ -0,0 +1,16 @@ +#include "/opt/homebrew/Cellar/libomp/16.0.1/include/omp.h" +#include +#include + +int main(int argc, char* argv[]) +{ + + // Beginning of parallel region + #pragma omp parallel + { + + printf("Hello World... from thread = %d\n", + omp_get_thread_num()); + } + // Ending of parallel region +} \ No newline at end of file diff --git a/output.png b/output.png new file mode 100644 index 0000000..7c8985c Binary files /dev/null and b/output.png differ diff --git a/test b/test new file mode 100755 index 0000000..96a3810 Binary files /dev/null and b/test differ