-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
2,565 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
cmake_minimum_required(VERSION 3.9) | ||
|
||
project(HWMain VERSION "0.0.1") | ||
|
||
set(DATA_INPUT_FILE "test_data.txt" CACHE STRING "Set input data File") | ||
# set(DATA_INPUT_FILE "test_data1.txt") | ||
# set(DATA_INPUT_FILE "test_data2.txt") | ||
# configure_file(${DATA_INPUT_FILE} "test_data1.txt" @ONLY) | ||
|
||
add_executable(Main | ||
main.cpp definitions.h | ||
) | ||
set(COMP_DEF | ||
#MY_DEBUG | ||
MY_INFO | ||
) | ||
target_compile_definitions(Main PRIVATE | ||
${COMP_DEF} BUILD_WITH_CMAKE | ||
) | ||
if(WIN32) | ||
if(CMAKE_CL_64) | ||
target_include_directories(Main PRIVATE | ||
"D:/software/pthread/include" | ||
) | ||
target_link_libraries(Main PRIVATE | ||
#"D:/software/pthread/dll/x64/pthreadVC2.dll" | ||
"D:/software/pthread/lib/x64/pthreadVC2.lib" | ||
) | ||
else() | ||
target_include_directories(Main PRIVATE | ||
"D:/software/pthread/include" | ||
) | ||
target_link_libraries(Main PRIVATE | ||
#"D:/software/pthread/dll/x86/pthreadVC2.dll" | ||
"D:/software/pthread/lib/x86/pthreadVC2.lib" | ||
) | ||
endif() | ||
elseif(UNIX) | ||
target_link_libraries(Main PRIVATE pthread) | ||
endif() |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
class Tester(object): | ||
def __init__(self): | ||
pass | ||
|
||
def test(self, func, args, exe_times = 100): | ||
import time | ||
print("[D] ", func, args) | ||
start = time.perf_counter() | ||
for _ in range(exe_times): | ||
func(**args) | ||
end = time.perf_counter() | ||
print("Exe func ", func) | ||
print("Total Time: ", end - start, "s", " Per time: ", (end - start) / exe_times) | ||
|
||
class Main(object): | ||
def readfile(self, name): | ||
lines = [] | ||
with open(name, "r", encoding="utf-8") as f: | ||
for line in f.readlines(): | ||
cline = [int(l) for l in line.split(",") ] | ||
lines.append(cline) | ||
# for line in f: | ||
# cline = [int(l) for l in line.split(",") ] | ||
# lines.append(cline) | ||
# print(len(lines), lines[0:3]) | ||
|
||
if __name__ == "__main__": | ||
m = Main() | ||
# m.readfile("./test_data.txt") | ||
t = Tester() | ||
args = { "name": "./test_data.txt"} | ||
t.test(m.readfile, args = args, exe_times=3) | ||
|
||
|
||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
## HW 2020 software challenge | ||
|
||
Solution written by @Brifuture. | ||
|
||
Best score: `2.8s online` / `4.1s offline`(my laptop: intel 8250U, 8G memory). | ||
|
||
Change definitions in `definitions.h` to deploy different configuration. | ||
|
||
### Dataset | ||
|
||
Dataset could be downloaded from [github repo](https://github.com/liusen1006/2020HuaweiCodecraft-TestData). | ||
|
||
Download this repo and move `test_data_*.txt` into the build directory of CMakeProject (If you build without CMake, the program will try to find data file in `/data/test_data.txt`). | ||
|
||
Change `DataInputFile` in `definitions.h` with the actual filename which contains the data you downloaded. | ||
|
||
### Build on Windows | ||
|
||
Download `PThread.7z` from [Tag-hw2020swc](https://github.com/BriFuture/blog-code-example/releases/download/hw2020swc/pthread.7z), then extracted it into directory like `D:/software`. | ||
|
||
CMake is used to generate project based on MSVC/gcc. If PThread is installed into location other than `D:/software/pthread`, you have to change `target_include_directories` and `target_link_libraries` in the file `CMakeLists.txt`. | ||
|
||
> Note: pthread.dll wont be found when running the project. You can add it into path by either of the following: | ||
> - Add pthread dll location into **PATH**. | ||
> - Open VistualStudio click project `Main` properties, Choose `Debug` tag, set `PATH=%PATH%D:\software\pthread\dll\x64;` in the environment variables. | ||
### Build on linux | ||
|
||
In the shell terminal, type `./run.sh` without CMake, type `./runcmake.sh` to build project with CMake. | ||
|
||
### Strategy | ||
|
||
See `main.cpp` to get more details. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#ifndef DEFINITIONS_H | ||
#define DEFINITIONS_H | ||
|
||
#define USE_TESTER | ||
|
||
#ifdef _MSC_VER | ||
#define ON_WIN | ||
#endif | ||
|
||
#define LARGE_DATA | ||
#define TEST_RUNLARGE | ||
//#define TEST_LAYER2 | ||
|
||
#if defined(LARGE_DATA) && !defined(TEST_RUNLARGE) | ||
#define MaxThreadNum 4 | ||
#else | ||
#define MaxThreadNum 1 | ||
#endif | ||
#ifdef TEST_RUNLARGE | ||
#define DefaultWorkerNum 1 | ||
#else | ||
// WorkerNum 不能加快速度,但是可以均分任务 | ||
#define DefaultWorkerNum (MaxThreadNum * 1) | ||
#endif | ||
|
||
#if defined(ON_WIN) && defined(LARGE_DATA) | ||
#define NotOutputToFile | ||
#endif | ||
|
||
#define FULL_DATA_INFO | ||
// #define FULL_DATA_DEBUG | ||
|
||
#ifdef USE_TESTER | ||
#if defined(LARGE_DATA) | ||
#undef MY_INFO | ||
//#define DataInputFile "test_data_2861665.txt" // 11s(26s delete)/1c 5s(20s delete)/4c | ||
//#define DataInputFile "test_data_2896262.txt" // best 14s828ms | ||
#define DataInputFile "test_data_3512444.txt" // best 16s55/1c 6s2/4c, kp 2c 18s total | ||
#define DataInputFile "test_data_1004812.txt" // best 7s4/1c 2s7/4c kp 8s/2c 13s/1c total | ||
#else | ||
//#define DataInputFile "test_data_77409.txt" // best 50ms(460ms wf) | ||
#define DataInputFile "test_data_3738.txt" // best 162ms (171ms wf) // 287ms on preserved path/1core | ||
#define DataInputFile "test_data_56.txt" // best 31 ms | ||
#define DataInputFile "test_data_38252.txt" // best 99ms (306ms wf) | ||
#define DataInputFile "test_data_1.txt" | ||
#define DataInputFile "test_data_58284.txt" // best 485 ms(808ms wf) | ||
#endif // end LARGE_DATA | ||
|
||
#define DataOutputFile "result.txt" | ||
#endif // end USE_TESTER | ||
|
||
|
||
//#define USE_NODE_LAYER_2 | ||
|
||
#endif // DEFINITIONS_H |
Oops, something went wrong.