Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debug for ahc029 #9

Merged
merged 43 commits into from
Jan 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
6ab8499
Bump golang.org/x/crypto from 0.14.0 to 0.17.0
dependabot[bot] Dec 22, 2023
70f96ca
fix zero score
fmhr Dec 23, 2023
6862398
fix errorが出た時に、wg.Done()が呼び出されない問題を修正
fmhr Dec 24, 2023
18a0903
fix reactiveRun args
fmhr Dec 25, 2023
492cd41
fix double output
fmhr Dec 25, 2023
cd1af1d
fix table to os.Stderr
fmhr Dec 25, 2023
5658dce
fix
fmhr Dec 25, 2023
5b1008f
add config.Bucket
fmhr Dec 25, 2023
bb10cfb
fix Dockerfile
fmhr Dec 25, 2023
f139a5a
fix Dockerfile 証明書のエラー
fmhr Dec 26, 2023
82bcd0a
add directory mk
fmhr Dec 26, 2023
f821f0a
fix used binaryname rename to tmpname
fmhr Dec 26, 2023
be87b50
fix mkdir
fmhr Dec 26, 2023
762f5c3
fix rename binary
fmhr Dec 26, 2023
3bb7ad2
add displaytablay flag
fmhr Dec 27, 2023
7440f5d
add csvOutput
fmhr Dec 28, 2023
1a39c39
Add orderedmap/v2 package and update function return types
fmhr Jan 6, 2024
254ab37
Update JSON unmarshaling in cloudWorker.go and main.go
fmhr Jan 6, 2024
9740fd0
Refactor requestToWorker and sortBySeed functions
fmhr Jan 6, 2024
4ea5806
Refactor EncodableOrderedMap to use a struct for key-value pairs
fmhr Jan 6, 2024
92d378c
Add logging for response body and update struct field names
fmhr Jan 6, 2024
0e3a09f
Add logging statements to MarshalJSON and UnmarshalJSON functions
fmhr Jan 6, 2024
488b68f
Fix unmarshal function and remove unnecessary log statement
fmhr Jan 6, 2024
2f53b20
Commented out unnecessary code in UnmarshalJSON function
fmhr Jan 6, 2024
37bcebd
Add EncodableOrderedMap type for JSON serialization
fmhr Jan 6, 2024
2cd6e5e
Refactor code to improve CSV output and header extraction
fmhr Jan 6, 2024
68b75b7
Add CsvOutput function and Logscore flag
fmhr Jan 6, 2024
bf30802
Update Makefile and config.go
fmhr Jan 10, 2024
db67341
Refactor maxInt function and update usage in runParallel.go
fmhr Jan 10, 2024
25fd543
Update config file and setConfig function
fmhr Jan 10, 2024
6b23deb
Refactor error handling in code
fmhr Jan 10, 2024
9ae59b5
Refactor error handling in gen.go and tracer.go
fmhr Jan 10, 2024
b10520a
Update Dockerfile and installation scripts
fmhr Jan 12, 2024
85cad4f
Update Dockerfile and gcloudbuild.sh
fmhr Jan 12, 2024
7c71989
Refactor handleSignals function and use sync.Map for currentlyRunning…
fmhr Jan 13, 2024
039b061
Remove unused code and sort data by seed in DisplayTable function
fmhr Jan 14, 2024
6e748d6
Delete debug binary file
fmhr Jan 14, 2024
801efd2
Update file paths and embed directories
fmhr Jan 14, 2024
0860074
Update file paths in mkDirCompilerBase and mkDirWorkerBase functions
fmhr Jan 14, 2024
756cd78
Add file path validation for temporary binary file
fmhr Jan 14, 2024
4fedcad
Update Dockerfile and gcloudbuild.sh, remove unnecessary code in main.go
fmhr Jan 14, 2024
579dc84
Refactor file path handling in worker/main.go
fmhr Jan 14, 2024
601a67e
Refactor file path handling in worker main.go
fmhr Jan 14, 2024
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ WORKER_DIR=./cmd/worker
build: $(BINARIES)
$(BINARIES): $(GO_FILES)
@echo "Building..."
go build -o $(BUILD_DIR)/$(BINARY_NAME) $(CMD_DIR)
go build -race -o $(BUILD_DIR)/$(BINARY_NAME) $(CMD_DIR)

# 実行ファイルのクリーンアップ
.PHONY: clean
Expand Down
30 changes: 15 additions & 15 deletions cloudCompile.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ import (

func checkConfigCloudCompile(config *Config) error {
if config.Source == "" {
return ErrorTrace("error: [SourcePath] must not be empty", nil)
return NewStackTraceError("error: [SourcePath] must not be empty")
}
if config.Binary == "" {
return ErrorTrace("error: [BinaryPath] must not be empty", nil)
return NewStackTraceError("error: [BinaryPath] must not be empty")
}
if config.CompileCmd == "" {
return ErrorTrace("error: [CompileCmd] must not be empty", nil)
return NewStackTraceError("error: [CompileCmd] must not be empty")
}
if config.CompilerURL == "" {
return ErrorTrace("error: [CompilerURL] must not be empty", nil)
return NewStackTraceError("error: [CompilerURL] must not be empty")
}
return nil
}
Expand All @@ -37,24 +37,24 @@ func checkConfigCloudCompile(config *Config) error {
func CloudCompile(config *Config) error {
log.Println("cloud compiling...")
if err := checkConfigCloudCompile(config); err != nil {
return ErrorTrace("invalid config: %w", err)
return err
}
// ソースファイルを開く
file, err := os.Open(config.Source)
if err != nil {
return ErrorTrace("error opening file: %w", err)
return err
}
defer file.Close()
// マルチパートフォームを作成
body := &bytes.Buffer{}
writer := multipart.NewWriter(body)
part, err := writer.CreateFormFile("file", filepath.Base(config.Source))
if err != nil {
return ErrorTrace("error creating form file: %w", err)
return err
}
_, err = io.Copy(part, file)
if err != nil {
return ErrorTrace("error writing to form file: %w", err)
return err
}
writer.WriteField("sourcePath", config.Source)
writer.WriteField("compileCmd", config.CompileCmd)
Expand All @@ -67,32 +67,32 @@ func CloudCompile(config *Config) error {
req, err := http.NewRequest("POST", config.CompilerURL, body)
req.Header.Set("Content-Type", writer.FormDataContentType())
if err != nil {
return ErrorTrace("error making new requets: %w", err)
return err
}

resp, err := http.DefaultClient.Do(req)
if err != nil {
return ErrorTrace("error making request: %w", err)
return err
}
defer resp.Body.Close()

if resp.StatusCode != http.StatusOK {
bodyBytes, err := io.ReadAll(resp.Body)
if err != nil {
return ErrorTrace("error reading response body: %w", err)
return err
}
fmt.Print("server response:", string(bodyBytes), "url:", config.CompilerURL, "\n")
return ErrorTrace(string(bodyBytes), fmt.Errorf("error response status code: %d", resp.StatusCode))
msg := fmt.Sprint("server response:", string(bodyBytes), "url:", config.CompilerURL, "\n")
return NewStackTraceError(msg)
}

// cloud storageに保存したバイナルの名前を取得
content := resp.Header.Get("Content-Disposition")
_, params, err := mime.ParseMediaType(content)
if err != nil {
return ErrorTrace("error parsing media type: %w", err)
return err
}
filename := params["filename"]
config.TmpBinary = filename

log.Println("cloud compile done:", filename)
return nil
}
8 changes: 4 additions & 4 deletions cloudDir.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ import (
"path/filepath"
)

//go:embed cmd/compiler/*
//go:embed cmd/compiler/script/*
var compilerFiles embed.FS

//go:embed cmd/worker/*
//go:embed cmd/worker/script/*
var workerFiles embed.FS

func mkDirCompilerBase() {
targetDir := "./fj/compiler/"
extractEmbeddedFiles(compilerFiles, "cmd/compiler", targetDir)
extractEmbeddedFiles(compilerFiles, "cmd/compiler/script", targetDir)
}

func mkDirWorkerBase() {
targetDir := "./fj/worker/"
extractEmbeddedFiles(workerFiles, "cmd/worker", targetDir)
extractEmbeddedFiles(workerFiles, "cmd/worker/script", targetDir)
}

func extractEmbeddedFiles(embeddedFS embed.FS, sourcdDir, targetDir string) {
Expand Down
31 changes: 19 additions & 12 deletions cloudWorker.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,25 @@ import (
"mime/multipart"
"net/http"
"time"

"github.com/elliotchance/orderedmap/v2"
)

// requestToWorker はバイナリをワーカーに送信する
func requestToWorker(config *Config, seed int) (rtn map[string]float64, err error) {
func requestToWorker(config *Config, seed int) (*orderedmap.OrderedMap[string, any], error) {
start := time.Now()
body := &bytes.Buffer{}
writer := multipart.NewWriter(body)

// configをJSONに変換
configData, err := json.Marshal(config)
if err != nil {
return nil, ErrorTrace("failed to marshal config: %v", err)
return nil, NewStackTraceError(err.Error())
}
// JSON configを追加
configPart, err := writer.CreateFormField("config")
if err != nil {
return nil, ErrorTrace("failed to create form field for config: %v", err)
return nil, NewStackTraceError(err.Error())
}
configPart.Write(configData)

Expand All @@ -50,33 +52,38 @@ func requestToWorker(config *Config, seed int) (rtn map[string]float64, err erro
if resp.StatusCode != http.StatusOK {
bodyBytes, err := io.ReadAll(resp.Body)
if err != nil {
return nil, ErrorTrace("error reading response body: %w", err)
return nil, WrapError(err)
}
return nil, ErrorTrace(fmt.Sprintf("error response status code:%d resp:%s", resp.StatusCode, string(bodyBytes)), err)
return nil, NewStackTraceError(fmt.Sprintf("error response status code:%d resp:%s", resp.StatusCode, string(bodyBytes)))
}

// レスポンスボディから文字列を取り出す
bodyBytes, err := io.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("failed to read response body: %v", err)
}
if err := json.Unmarshal(bodyBytes, &rtn); err != nil {
rtn := orderedmap.NewOrderedMap[string, any]()
if err := json.Unmarshal(bodyBytes, (*EncodableOrderedMap)(rtn)); err != nil {
return nil, fmt.Errorf("failed to parse response body: %v", err)
}
elapsed := time.Since(start)
rtn["responseTime"] = elapsed.Seconds()
if rtn["Score"] == 0 {
log.Println("response body:", string(bodyBytes))
rtn.Set("responseTime", elapsed.Seconds())
score, ok := rtn.Get("Score")
if !ok {
return nil, fmt.Errorf("failed to get score from response body: %v", err)
}
if score == 0.0 {
log.Println("Score=0:response body:", string(bodyBytes))
}
return rtn, nil
}

func SendBinaryToWorker(config *Config, seed int, binaryNameInBucket string) (rtn map[string]float64, err error) {
func SendBinaryToWorker(config *Config, seed int, binaryNameInBucket string) (*orderedmap.OrderedMap[string, any], error) {
if config.WorkerURL == "" {
return nil, ErrorTrace("", fmt.Errorf("worker URL is not specified"))
return nil, NewStackTraceError("worker URL is not specified")
}
if config.Binary == "" {
return nil, ErrorTrace("", fmt.Errorf("binary path is not specified"))
return nil, NewStackTraceError("binary path is not specified")
}
return requestToWorker(config, seed)
}
42 changes: 0 additions & 42 deletions cmd/compiler/Dockerfile

This file was deleted.

36 changes: 36 additions & 0 deletions cmd/compiler/script/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
FROM golang:1.21 as serverbuild

WORKDIR /app

RUN git clone https://github.com/fmhr/fj.git \
&& cd fj \
&& go mod tidy

WORKDIR /app/fj/cmd/compiler

RUN go build -o /app/server



FROM ubuntu:latest

WORKDIR /work

RUN apt-get update && apt-get install -y \
apt-utils \
wget \
unzip \
gzip

COPY . /work
RUN sh install_go.sh
ENV PATH $PATH:/opt/go/bin
# RUN sh install_cpp20.sh

COPY --from=serverbuild /app/server /work

RUN chmod +x /work/server

EXPOSE $PORT

CMD ["/work/server"]
2 changes: 2 additions & 0 deletions cmd/compiler/script/compile.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Go,"go build -o a.out"
C++20,"g++-12 -std=gnu++2b -O2 -DONLINE_JUDGE -DATCODER -Wall -Wextra -mtune=native -march=native -fconstexpr-depth=2147483647 -fconstexpr-loop-limit=2147483647 -fconstexpr-ops-limit=2147483647 -I/opt/ac-library -I/opt/boost/gcc/include -L/opt/boost/gcc/lib -o a.out Main.cpp -lgmpxx -lgmp -I/usr/include/eigen3"
File renamed without changes.
26 changes: 26 additions & 0 deletions cmd/compiler/script/install_cpp20.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

apt-get update
apt-get install -y g++-12
apt-get install -y libgmp3-dev

# /tmpディレクトリに移動してから作業を行う
cd /tmp

# ac-libraryのダウンロードとインストール
mkdir -p /opt/ac-library
wget https://github.com/atcoder/ac-library/releases/download/v1.5.1/ac-library.zip -O ac-library.zip
unzip /tmp/ac-library.zip -d /opt/ac-library

# boostのダウンロードとインストール
apt-get install -y build-essential
# wget https://boostorg.jfrog.io/artifactory/main/release/1.82.0/source/boost_1_82_0.tar.gz -O boost_1_82_0.tar.gz
wget https://github.com/boostorg/boost/releases/download/boost-1.82.0/boost-1.82.0.tar.gz -O boost_1_82_0.tar.gz
tar xf boost_1_82_0.tar.gz
cd boost-1.82.0
./bootstrap.sh --with-toolset=gcc --without-libraries=mpi,graph_parallel
./b2 -j3 toolset=gcc variant=release link=static runtime-link=static cxxflags="-std=c++20" stage
./b2 -j3 toolset=gcc variant=release link=static runtime-link=static cxxflags="-std=c++20" --prefix=/opt/boost/gcc install

# Eigenのインストール
apt-get install -y libeigen3-dev=3.4.0-2ubuntu2
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
cd /tmp
wget https://go.dev/dl/go1.20.6.linux-amd64.tar.gz
wget -q https://go.dev/dl/go1.20.6.linux-amd64.tar.gz
tar -C /opt -xf go1.20.6.linux-amd64.tar.gz
export PATH=$PATH:/opt/go/bin
export PATH=$PATH:/opt/go/bin # 一時的にパスを通す コンテナには反映されない

mkdir -p /go/src/atcoder.jp/golang
cd /go/src/atcoder.jp/golang
go mod init atcoder.jp/golang
Expand Down
File renamed without changes.
7 changes: 6 additions & 1 deletion cmd/fj/main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package main

import "github.com/fmhr/fj"
import (
"log"

"github.com/fmhr/fj"
)

func main() {
log.SetFlags(log.Lshortfile)
fj.Fj()
}
34 changes: 0 additions & 34 deletions cmd/worker/Dockerfile

This file was deleted.

Loading
Loading