Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -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
}
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"C_Cpp.errorSquiggles": "disabled"
}
Binary file added image
Binary file not shown.
29 changes: 20 additions & 9 deletions image.c → openmp_image.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#include <stdio.h>
#include <stdint.h>
#include <time.h>
#include <sys/time.h>
#include <string.h>
#include "image.h"
#include "/opt/homebrew/Cellar/libomp/16.0.1/include/omp.h"

#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"
Expand Down Expand Up @@ -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;row<srcImage->height;row++){
for (pix=0;pix<srcImage->width;pix++){
for (bit=0;bit<srcImage->bpp;bit++){
destImage->data[Index(pix,row,srcImage->width,bit,srcImage->bpp)]=getPixelValue(srcImage,pix,row,bit,algorithm);
#pragma omp parallel
{
for (row=0;row<srcImage->height;row++){
for (pix=0;pix<srcImage->width;pix++){
for (bit=0;bit<srcImage->bpp;bit++){
destImage->data[Index(pix,row,srcImage->width,bit,srcImage->bpp)]=getPixelValue(srcImage,pix,row,bit,algorithm);
}
}
}
}
Expand Down Expand Up @@ -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();
Expand All @@ -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;
}
16 changes: 16 additions & 0 deletions openmptest.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include "/opt/homebrew/Cellar/libomp/16.0.1/include/omp.h"
#include <stdio.h>
#include <stdlib.h>

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
}
Binary file added output.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test
Binary file not shown.