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
64 changes: 64 additions & 0 deletions parallelReadTiff/cSrc/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
---
Language: Cpp
BasedOnStyle: LLVM
AlignConsecutiveAssignments: true
#llvm11: AlignConsecutiveBitFields: false
AlignConsecutiveDeclarations: true
AlignConsecutiveMacros: true
#llvm10-11: AlignOperands: true - Align
#llvm11: AllowShortEnumsOnASingleLine: true
AllowShortFunctionsOnASingleLine: None
AlwaysBreakAfterReturnType: AllDefinitions
BraceWrapping:
AfterFunction: true
#llvm10-11: AfterControlStatement: false - Never
BeforeCatch: true
BeforeElse: true
#llvm11: BeforeLambdaBody: false
#llvm11: BeforeWhile: false
BreakBeforeBraces: Stroustrup
BreakAfterJavaFieldAnnotations: true
BreakStringLiterals: true
ColumnLimit: 110 # Update $max_trace_macro_line_len in bin/trace also
IncludeCategories:
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 3
SortPriority: 0
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
Priority: 4
SortPriority: 0
- Regex: '.*'
Priority: 0
SortPriority: 0
- Regex: '^PDC*.*'
Priority: 1
SortPriority: 0
- Regex: 'private.*'
Priority: 2
SortPriority: 0
IncludeIsMainRegex: '(public)?$'
IndentCaseLabels: true
#llvm11: IndentCaseBlocks: false
IndentGotoLabels: false
#llvm11: IndentExternBlock: AfterExternBlock
IndentWidth: 4
#llvm11: InsertTrailingCommas: None
# MacroBlockBegin: "^BEGIN_FUNC"
# MacroBlockEnd: "^END_FUNC"
ObjCBlockIndentWidth: 4
#llvm11: ObjCBreakBeforeNestedBlockParam: true
ReflowComments: true
SortIncludes: false
StatementMacros:
- FUNC_ENTER
- FUNC_LEAVE
- PGOTO_DONE
- PGOTO_ERROR
#llvm10: TypenameMacros:
#llvm10: - STACK_OF
#llvm10: - LIST
#llvm11: WhitespaceSensitiveMacros:
#llvm11: - STRINGIZE
#llvm11: - PP_STRINGIZE
...

56 changes: 56 additions & 0 deletions parallelReadTiff/cSrc/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
cmake_minimum_required (VERSION 2.8.12)

# Setup cmake policies.
foreach(p
CMP0012
CMP0013
CMP0014
CMP0022 # CMake 2.8.12
CMP0025 # CMake 3.0
CMP0053 # CMake 3.1
CMP0054 # CMake 3.1
CMP0074 # CMake 3.12
CMP0075 # CMake 3.12
CMP0083 # CMake 3.14
CMP0093 # CMake 3.15
)
if(POLICY ${p})
cmake_policy(SET ${p} NEW)
endif()
endforeach()

project(OMP_TIFF C)

# Find OpenMP
option(USE_SYSTEM_OPENMP "Use system-installed OpenMP." ON)
if(USE_SYSTEM_OPENMP)
find_package(OpenMP REQUIRED)
if(OPENMP_FOUND)
add_definitions(-DENABLE_OPENMP=1)
set(ENABLE_OPENMP 1)
set(OPENMP_LIBRARIES "${OpenMP_C_LIBRARIES}")
else()
message(FATAL_ERROR "OpenMP not found")
endif()
endif()

# Find LibTIFF
option(USE_LIB_TIFF "Enable LibTiff." ON)
if(USE_LIB_TIFF)
find_package(TIFF REQUIRED)
if(TIFF_FOUND)
# Add the LibTIFF include directory to the include path
include_directories(${TIFF_INCLUDE_DIRS})
add_library(omp_tiff parallelReadTiff.c)
target_compile_options(omp_tiff PRIVATE ${OpenMP_C_FLAGS})
target_link_libraries(omp_tiff PUBLIC ${OpenMP_C_LIBRARIES})
target_link_libraries(omp_tiff PUBLIC ${TIFF_LIBRARIES})
target_include_directories(omp_tiff PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

add_executable(main main.c)
target_link_libraries(main ${TIFF_LIBRARIES})
target_link_libraries(main omp_tiff)
else()
message(WARNING "LibTiff not found, ignore building the executables which requires LibTiff support.")
endif()
endif()
71 changes: 63 additions & 8 deletions parallelReadTiff/cSrc/main.c
Original file line number Diff line number Diff line change
@@ -1,13 +1,68 @@
#include "parallelReadTiff.h"
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <getopt.h>

int main(){
clock_t begin = clock();
void* test = readTiffParallelWrapper("C:\\Users\\Matt\\Desktop\\testTiff\\test.tif");
if(!test) return 1;
clock_t end = clock();
double time_spent = (double)(end - begin) / CLOCKS_PER_SEC;
printf("%f\n",time_spent);
free(test);
int
parse_console_args(int argc, char *argv[], char **file_name)
{
int c, parse_code = -1;

while ((c = getopt(argc, argv, "f:")) != -1) {
switch (c) {
case 'f':
*file_name = optarg;
parse_code = 0;
break;
default:
fprintf(stderr, "Usage: %s [-f filename]\n", argv[0]);
parse_code = -1;
exit(EXIT_FAILURE);
}
}
return parse_code;
}

int
main(int argc, char *argv[])
{

char *file_name = NULL;
void *tiff = NULL;
int i = 0;
struct timespec start, end;
double duration;

// parse console argument
int parse_code = parse_console_args(argc, argv, &file_name);
if (parse_code) {
return parse_code;
}

// print file name for validating purpose
printf("Filename: %s\n", file_name ? file_name : "(none)");

clock_gettime(CLOCK_MONOTONIC, &start); // start timing the operation

// calling tiff loading process.
parallel_TIFF_load(file_name, &tiff, 1, NULL);

clock_gettime(CLOCK_MONOTONIC, &end); // end timing the operation

duration = (end.tv_sec - start.tv_sec) * 1e9 + (end.tv_nsec - start.tv_nsec); // calculate duration in nanoseconds

printf("Read Tiff File Done! Time taken: %.4f seconds\n", duration/1e9);

if (!tiff)
return 1;

printf("first few bytes ");
for (i = 0; i < 10; i++) {
printf("%d ", ((uint8_t *)tiff)[i]);
}
printf("\n");
free(tiff);
return 0;
}
Loading