diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..38404b9 --- /dev/null +++ b/.clang-format @@ -0,0 +1,176 @@ +--- +Language: Cpp +# BasedOnStyle: WebKit +AccessModifierOffset: -4 +AlignAfterOpenBracket: DontAlign +AlignArrayOfStructures: None +AlignConsecutiveAssignments: Consecutive +AlignConsecutiveBitFields: None +AlignConsecutiveDeclarations: None +AlignConsecutiveMacros: Consecutive +AlignEscapedNewlines: Right +AlignOperands: Align +AlignTrailingComments: true +AllowAllArgumentsOnNextLine: false +AllowAllParametersOfDeclarationOnNextLine: true +AllowShortEnumsOnASingleLine: true +AllowShortBlocksOnASingleLine: Never +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: All +AllowShortLambdasOnASingleLine: All +AllowShortIfStatementsOnASingleLine: OnlyFirstIf +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakTemplateDeclarations: MultiLine +AttributeMacros: + - __capability +BinPackArguments: false +BinPackParameters: false +BraceWrapping: + AfterCaseLabel: false + AfterClass: false + AfterControlStatement: Never + AfterEnum: false + AfterFunction: true + AfterNamespace: false + AfterObjCDeclaration: false + AfterStruct: false + AfterUnion: false + AfterExternBlock: false + BeforeCatch: false + BeforeElse: false + BeforeLambdaBody: false + BeforeWhile: false + IndentBraces: false + SplitEmptyFunction: true + SplitEmptyRecord: true + SplitEmptyNamespace: true +BreakBeforeBinaryOperators: None +BreakBeforeBraces: WebKit +BreakBeforeInheritanceComma: false +BreakInheritanceList: BeforeColon +BreakBeforeTernaryOperators: true +BreakConstructorInitializersBeforeComma: false +BreakConstructorInitializers: BeforeComma +BreakAfterJavaFieldAnnotations: false +BreakStringLiterals: true +ColumnLimit: 90 +CommentPragmas: '^ IWYU pragma:' +CompactNamespaces: false +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: false +DeriveLineEnding: true +DerivePointerAlignment: false +DisableFormat: false +EmptyLineAfterAccessModifier: Never +EmptyLineBeforeAccessModifier: LogicalBlock +ExperimentalAutoDetectBinPacking: false +BasedOnStyle: '' +ConstructorInitializerAllOnOneLineOrOnePerLine: false +AllowAllConstructorInitializersOnNextLine: true +FixNamespaceComments: false +ForEachMacros: + - foreach + - Q_FOREACH + - BOOST_FOREACH +IfMacros: + - KJ_IF_MAYBE +IncludeBlocks: Preserve +IncludeCategories: + - Regex: '^"(llvm|llvm-c|clang|clang-c)/' + Priority: 2 + SortPriority: 0 + CaseSensitive: false + - Regex: '^(<|"(gtest|gmock|isl|json)/)' + Priority: 3 + SortPriority: 0 + CaseSensitive: false + - Regex: '.*' + Priority: 1 + SortPriority: 0 + CaseSensitive: false +IncludeIsMainRegex: '(Test)?$' +IncludeIsMainSourceRegex: '' +IndentAccessModifiers: false +IndentCaseLabels: false +IndentCaseBlocks: false +IndentGotoLabels: true +IndentPPDirectives: None +IndentExternBlock: AfterExternBlock +IndentWidth: 4 +IndentWrappedFunctionNames: false +InsertTrailingCommas: None +JavaScriptQuotes: Leave +JavaScriptWrapImports: true +KeepEmptyLinesAtTheStartOfBlocks: true +LambdaBodyIndentation: Signature +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: Inner +ObjCBinPackProtocolList: Auto +ObjCBlockIndentWidth: 4 +ObjCBreakBeforeNestedBlockParam: true +ObjCSpaceAfterProperty: true +ObjCSpaceBeforeProtocolList: true +PenaltyBreakAssignment: 200 +PenaltyBreakBeforeFirstCallParameter: 19 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakString: 1000 +PenaltyBreakTemplateDeclaration: 10 +PenaltyExcessCharacter: 1000000 +PenaltyReturnTypeOnItsOwnLine: 60 +PenaltyIndentedWhitespace: 0 +PointerAlignment: Left +PPIndentWidth: -1 +ReferenceAlignment: Pointer +ReflowComments: true +ShortNamespaceLines: 1 +SortIncludes: CaseSensitive +SortJavaStaticImport: Before +SortUsingDeclarations: true +SpaceAfterCStyleCast: false +SpaceAfterLogicalNot: false +SpaceAfterTemplateKeyword: true +SpaceBeforeAssignmentOperators: true +SpaceBeforeCaseColon: false +SpaceBeforeCpp11BracedList: true +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeParens: ControlStatements +SpaceAroundPointerQualifiers: Default +SpaceBeforeRangeBasedForLoopColon: true +SpaceInEmptyBlock: false +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: Never +SpacesInConditionalStatement: false +SpacesInContainerLiterals: true +SpacesInCStyleCastParentheses: false +SpacesInLineCommentPrefix: + Minimum: 1 + Maximum: -1 +SpacesInParentheses: false +SpacesInSquareBrackets: false +SpaceBeforeSquareBrackets: false +BitFieldColonSpacing: Both +Standard: Latest +StatementAttributeLikeMacros: + - Q_EMIT +StatementMacros: + - Q_UNUSED + - QT_REQUIRE_VERSION +TabWidth: 8 +UseCRLF: false +UseTab: Never +WhitespaceSensitiveMacros: + - STRINGIZE + - PP_STRINGIZE + - BOOST_PP_STRINGIZE + - NS_SWIFT_NAME + - CF_SWIFT_NAME +... diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 0000000..acdff1e --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,14 @@ +--- +Checks: 'clang-diagnostic-*,clang-analyzer-*,clang-bugprone-*,readability-identifier-naming' +WarningsAsErrors: true +HeaderFilterRegex: '.*' +AnalyzeTemporaryDtors: false +CheckOptions: + - key: readability-identifier-naming.StructCase + value: 'CamelCase' + - key: readability-identifier-naming.FunctionCase + value: 'camelBack' + - key: readability-identifier-naming.VariableCase + value: 'camelBack' + - key: readability-identifier-naming.GlobalConstantCase + value: 'UPPER_CASE' diff --git a/.clangd b/.clangd new file mode 100644 index 0000000..7b6167a --- /dev/null +++ b/.clangd @@ -0,0 +1,3 @@ +CompileFlags: + Add: [-I/Users/jan/prg/MD-Bench/verletlist/includes, -I/Users/jan/prg/MD-Bench/common/includes, -DALIGNMENT=64] + Compiler: clang diff --git a/Makefile b/Makefile index defffb6..bd4f835 100644 --- a/Makefile +++ b/Makefile @@ -98,10 +98,6 @@ ifeq ($(strip $(ENABLE_OMP_SIMD)),true) DEFINES += -DENABLE_OMP_SIMD endif -ifeq ($(strip $(USE_SIMD_KERNEL)),true) - DEFINES += -DUSE_SIMD_KERNEL -endif - VPATH = $(SRC_DIR) $(ASM_DIR) $(CUDA_DIR) ASM = $(patsubst $(SRC_DIR)/%.c, $(BUILD_DIR)/%.s,$(wildcard $(SRC_DIR)/*.c)) OVERWRITE:= $(patsubst $(ASM_DIR)/%-new.s, $(BUILD_DIR)/%.o,$(wildcard $(ASM_DIR)/*-new.s)) diff --git a/gromacs/atom.c b/clusterpair/atom.c similarity index 99% rename from gromacs/atom.c rename to clusterpair/atom.c index b50a3d1..a5ad2d3 100644 --- a/gromacs/atom.c +++ b/clusterpair/atom.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg. + * Copyright (C) NHR@FAU, University Erlangen-Nuremberg. * All rights reserved. This file is part of MD-Bench. * Use of this source code is governed by a LGPL-3.0 * license that can be found in the LICENSE file. diff --git a/gromacs/cuda/force_lj.cu b/clusterpair/cuda/force_lj.cu similarity index 99% rename from gromacs/cuda/force_lj.cu rename to clusterpair/cuda/force_lj.cu index 1dcbde5..f1cf8c0 100644 --- a/gromacs/cuda/force_lj.cu +++ b/clusterpair/cuda/force_lj.cu @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg. + * Copyright (C) NHR@FAU, University Erlangen-Nuremberg. * All rights reserved. This file is part of MD-Bench. * Use of this source code is governed by a LGPL-3.0 * license that can be found in the LICENSE file. diff --git a/gromacs/force_eam.c b/clusterpair/force_eam.c similarity index 99% rename from gromacs/force_eam.c rename to clusterpair/force_eam.c index 10b55e5..b99ec57 100644 --- a/gromacs/force_eam.c +++ b/clusterpair/force_eam.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg. + * Copyright (C) NHR@FAU, University Erlangen-Nuremberg. * All rights reserved. This file is part of MD-Bench. * Use of this source code is governed by a LGPL-3.0 * license that can be found in the LICENSE file. diff --git a/gromacs/force_lj.c b/clusterpair/force_lj.c similarity index 99% rename from gromacs/force_lj.c rename to clusterpair/force_lj.c index 84e384a..715f0ef 100644 --- a/gromacs/force_lj.c +++ b/clusterpair/force_lj.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg. + * Copyright (C) NHR@FAU, University Erlangen-Nuremberg. * All rights reserved. This file is part of MD-Bench. * Use of this source code is governed by a LGPL-3.0 * license that can be found in the LICENSE file. diff --git a/gromacs/includes/atom.h b/clusterpair/includes/atom.h similarity index 98% rename from gromacs/includes/atom.h rename to clusterpair/includes/atom.h index b674cdc..b1e9e13 100644 --- a/gromacs/includes/atom.h +++ b/clusterpair/includes/atom.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg. + * Copyright (C) NHR@FAU, University Erlangen-Nuremberg. * All rights reserved. This file is part of MD-Bench. * Use of this source code is governed by a LGPL-3.0 * license that can be found in the LICENSE file. diff --git a/gromacs/includes/integrate.h b/clusterpair/includes/integrate.h similarity index 97% rename from gromacs/includes/integrate.h rename to clusterpair/includes/integrate.h index 5236ed8..6206b92 100644 --- a/gromacs/includes/integrate.h +++ b/clusterpair/includes/integrate.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg. + * Copyright (C) NHR@FAU, University Erlangen-Nuremberg. * All rights reserved. This file is part of MD-Bench. * Use of this source code is governed by a LGPL-3.0 * license that can be found in the LICENSE file. diff --git a/gromacs/includes/neighbor.h b/clusterpair/includes/neighbor.h similarity index 96% rename from gromacs/includes/neighbor.h rename to clusterpair/includes/neighbor.h index 668edc8..1e560d3 100644 --- a/gromacs/includes/neighbor.h +++ b/clusterpair/includes/neighbor.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg. + * Copyright (C) NHR@FAU, University Erlangen-Nuremberg. * All rights reserved. This file is part of MD-Bench. * Use of this source code is governed by a LGPL-3.0 * license that can be found in the LICENSE file. diff --git a/gromacs/includes/pbc.h b/clusterpair/includes/pbc.h similarity index 88% rename from gromacs/includes/pbc.h rename to clusterpair/includes/pbc.h index 33ceb53..88f6ebf 100644 --- a/gromacs/includes/pbc.h +++ b/clusterpair/includes/pbc.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg. + * Copyright (C) NHR@FAU, University Erlangen-Nuremberg. * All rights reserved. This file is part of MD-Bench. * Use of this source code is governed by a LGPL-3.0 * license that can be found in the LICENSE file. diff --git a/gromacs/includes/stats.h b/clusterpair/includes/stats.h similarity index 93% rename from gromacs/includes/stats.h rename to clusterpair/includes/stats.h index f97abf2..8258adb 100644 --- a/gromacs/includes/stats.h +++ b/clusterpair/includes/stats.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg. + * Copyright (C) NHR@FAU, University Erlangen-Nuremberg. * All rights reserved. This file is part of MD-Bench. * Use of this source code is governed by a LGPL-3.0 * license that can be found in the LICENSE file. diff --git a/gromacs/includes/tracing.h b/clusterpair/includes/tracing.h similarity index 98% rename from gromacs/includes/tracing.h rename to clusterpair/includes/tracing.h index 7c4c59e..1ae2c0b 100644 --- a/gromacs/includes/tracing.h +++ b/clusterpair/includes/tracing.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg. + * Copyright (C) NHR@FAU, University Erlangen-Nuremberg. * All rights reserved. This file is part of MD-Bench. * Use of this source code is governed by a LGPL-3.0 * license that can be found in the LICENSE file. diff --git a/gromacs/includes/vtk.h b/clusterpair/includes/vtk.h similarity index 91% rename from gromacs/includes/vtk.h rename to clusterpair/includes/vtk.h index 5311342..a31dbf5 100644 --- a/gromacs/includes/vtk.h +++ b/clusterpair/includes/vtk.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg. + * Copyright (C) NHR@FAU, University Erlangen-Nuremberg. * All rights reserved. This file is part of MD-Bench. * Use of this source code is governed by a LGPL-3.0 * license that can be found in the LICENSE file. diff --git a/gromacs/includes/xtc.h b/clusterpair/includes/xtc.h similarity index 87% rename from gromacs/includes/xtc.h rename to clusterpair/includes/xtc.h index 201cb2d..bd2b29d 100644 --- a/gromacs/includes/xtc.h +++ b/clusterpair/includes/xtc.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg. + * Copyright (C) NHR@FAU, University Erlangen-Nuremberg. * All rights reserved. This file is part of MD-Bench. * Use of this source code is governed by a LGPL-3.0 * license that can be found in the LICENSE file. diff --git a/gromacs/main-stub.c b/clusterpair/main-stub.c similarity index 99% rename from gromacs/main-stub.c rename to clusterpair/main-stub.c index bfaadf6..68f23ac 100644 --- a/gromacs/main-stub.c +++ b/clusterpair/main-stub.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg. + * Copyright (C) NHR@FAU, University Erlangen-Nuremberg. * All rights reserved. This file is part of MD-Bench. * Use of this source code is governed by a LGPL-3.0 * license that can be found in the LICENSE file. diff --git a/gromacs/main.c b/clusterpair/main.c similarity index 99% rename from gromacs/main.c rename to clusterpair/main.c index 91030eb..58b35f2 100644 --- a/gromacs/main.c +++ b/clusterpair/main.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg. + * Copyright (C) NHR@FAU, University Erlangen-Nuremberg. * All rights reserved. This file is part of MD-Bench. * Use of this source code is governed by a LGPL-3.0 * license that can be found in the LICENSE file. diff --git a/gromacs/neighbor.c b/clusterpair/neighbor.c similarity index 99% rename from gromacs/neighbor.c rename to clusterpair/neighbor.c index ba9fc82..8e3abad 100644 --- a/gromacs/neighbor.c +++ b/clusterpair/neighbor.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg. + * Copyright (C) NHR@FAU, University Erlangen-Nuremberg. * All rights reserved. This file is part of MD-Bench. * Use of this source code is governed by a LGPL-3.0 * license that can be found in the LICENSE file. diff --git a/gromacs/pbc.c b/clusterpair/pbc.c similarity index 99% rename from gromacs/pbc.c rename to clusterpair/pbc.c index 412e088..630146c 100644 --- a/gromacs/pbc.c +++ b/clusterpair/pbc.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg. + * Copyright (C) NHR@FAU, University Erlangen-Nuremberg. * All rights reserved. This file is part of MD-Bench. * Use of this source code is governed by a LGPL-3.0 * license that can be found in the LICENSE file. diff --git a/gromacs/stats.c b/clusterpair/stats.c similarity index 97% rename from gromacs/stats.c rename to clusterpair/stats.c index 9f2f562..f60074f 100644 --- a/gromacs/stats.c +++ b/clusterpair/stats.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg. + * Copyright (C) NHR@FAU, University Erlangen-Nuremberg. * All rights reserved. This file is part of MD-Bench. * Use of this source code is governed by a LGPL-3.0 * license that can be found in the LICENSE file. diff --git a/gromacs/tracing.c b/clusterpair/tracing.c similarity index 96% rename from gromacs/tracing.c rename to clusterpair/tracing.c index efa284e..a8be7cc 100644 --- a/gromacs/tracing.c +++ b/clusterpair/tracing.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg. + * Copyright (C) NHR@FAU, University Erlangen-Nuremberg. * All rights reserved. This file is part of MD-Bench. * Use of this source code is governed by a LGPL-3.0 * license that can be found in the LICENSE file. diff --git a/gromacs/vtk.c b/clusterpair/vtk.c similarity index 99% rename from gromacs/vtk.c rename to clusterpair/vtk.c index b683dc8..542bf9e 100644 --- a/gromacs/vtk.c +++ b/clusterpair/vtk.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg. + * Copyright (C) NHR@FAU, University Erlangen-Nuremberg. * All rights reserved. This file is part of MD-Bench. * Use of this source code is governed by a LGPL-3.0 * license that can be found in the LICENSE file. diff --git a/gromacs/xtc.c b/clusterpair/xtc.c similarity index 96% rename from gromacs/xtc.c rename to clusterpair/xtc.c index 333f592..b3de58e 100644 --- a/gromacs/xtc.c +++ b/clusterpair/xtc.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg. + * Copyright (C) NHR@FAU, University Erlangen-Nuremberg. * All rights reserved. This file is part of MD-Bench. * Use of this source code is governed by a LGPL-3.0 * license that can be found in the LICENSE file. diff --git a/common/allocate.c b/common/allocate.c index 3085e8d..4c78ef1 100644 --- a/common/allocate.c +++ b/common/allocate.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg. + * Copyright (C) NHR@FAU, University Erlangen-Nuremberg. * All rights reserved. This file is part of MD-Bench. * Use of this source code is governed by a LGPL-3.0 * license that can be found in the LICENSE file. diff --git a/common/device.c b/common/device.c index d1d51ef..55cf48f 100644 --- a/common/device.c +++ b/common/device.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg. + * Copyright (C) NHR@FAU, University Erlangen-Nuremberg. * All rights reserved. This file is part of MD-Bench. * Use of this source code is governed by a LGPL-3.0 * license that can be found in the LICENSE file. diff --git a/common/eam_utils.c b/common/eam_utils.c index c28be17..ec3b444 100644 --- a/common/eam_utils.c +++ b/common/eam_utils.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg. + * Copyright (C) NHR@FAU, University Erlangen-Nuremberg. * All rights reserved. This file is part of MD-Bench. * Use of this source code is governed by a LGPL-3.0 * license that can be found in the LICENSE file. diff --git a/common/includes/allocate.h b/common/includes/allocate.h index 6b6a087..08dda49 100644 --- a/common/includes/allocate.h +++ b/common/includes/allocate.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg. + * Copyright (C) NHR@FAU, University Erlangen-Nuremberg. * All rights reserved. This file is part of MD-Bench. * Use of this source code is governed by a LGPL-3.0 * license that can be found in the LICENSE file. diff --git a/common/includes/device.h b/common/includes/device.h index f28cc62..85e217d 100644 --- a/common/includes/device.h +++ b/common/includes/device.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg. + * Copyright (C) NHR@FAU, University Erlangen-Nuremberg. * All rights reserved. This file is part of MD-Bench. * Use of this source code is governed by a LGPL-3.0 * license that can be found in the LICENSE file. diff --git a/common/includes/eam.h b/common/includes/eam.h index 39902a5..b521821 100644 --- a/common/includes/eam.h +++ b/common/includes/eam.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg. + * Copyright (C) NHR@FAU, University Erlangen-Nuremberg. * All rights reserved. This file is part of MD-Bench. * Use of this source code is governed by a LGPL-3.0 * license that can be found in the LICENSE file. diff --git a/common/includes/likwid-marker.h b/common/includes/likwid-marker.h index 0d36f27..e7cb709 100644 --- a/common/includes/likwid-marker.h +++ b/common/includes/likwid-marker.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg. + * Copyright (C) NHR@FAU, University Erlangen-Nuremberg. * All rights reserved. This file is part of MD-Bench. * Use of this source code is governed by a LGPL-3.0 * license that can be found in the LICENSE file. diff --git a/common/includes/parameter.h b/common/includes/parameter.h index 614be9f..867b15d 100644 --- a/common/includes/parameter.h +++ b/common/includes/parameter.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg. + * Copyright (C) NHR@FAU, University Erlangen-Nuremberg. * All rights reserved. This file is part of MD-Bench. * Use of this source code is governed by a LGPL-3.0 * license that can be found in the LICENSE file. diff --git a/common/includes/simd.h b/common/includes/simd.h index b14d546..cb02ad5 100644 --- a/common/includes/simd.h +++ b/common/includes/simd.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg. + * Copyright (C) NHR@FAU, University Erlangen-Nuremberg. * All rights reserved. This file is part of MD-Bench. * Use of this source code is governed by a LGPL-3.0 * license that can be found in the LICENSE file. diff --git a/common/includes/simd/avx2_double.h b/common/includes/simd/avx2_double.h index e57df9b..7b9d19e 100644 --- a/common/includes/simd/avx2_double.h +++ b/common/includes/simd/avx2_double.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg. + * Copyright (C) NHR@FAU, University Erlangen-Nuremberg. * All rights reserved. This file is part of MD-Bench. * Use of this source code is governed by a LGPL-3.0 * license that can be found in the LICENSE file. diff --git a/common/includes/simd/avx2_float.h b/common/includes/simd/avx2_float.h index 4ebe09a..31ef5ff 100644 --- a/common/includes/simd/avx2_float.h +++ b/common/includes/simd/avx2_float.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg. + * Copyright (C) NHR@FAU, University Erlangen-Nuremberg. * All rights reserved. This file is part of MD-Bench. * Use of this source code is governed by a LGPL-3.0 * license that can be found in the LICENSE file. diff --git a/common/includes/simd/avx512_double.h b/common/includes/simd/avx512_double.h index 76c4bc0..c078899 100644 --- a/common/includes/simd/avx512_double.h +++ b/common/includes/simd/avx512_double.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg. + * Copyright (C) NHR@FAU, University Erlangen-Nuremberg. * All rights reserved. This file is part of MD-Bench. * Use of this source code is governed by a LGPL-3.0 * license that can be found in the LICENSE file. diff --git a/common/includes/simd/avx512_float.h b/common/includes/simd/avx512_float.h index 3d5bea4..d77efa1 100644 --- a/common/includes/simd/avx512_float.h +++ b/common/includes/simd/avx512_float.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg. + * Copyright (C) NHR@FAU, University Erlangen-Nuremberg. * All rights reserved. This file is part of MD-Bench. * Use of this source code is governed by a LGPL-3.0 * license that can be found in the LICENSE file. diff --git a/common/includes/simd/avx_double.h b/common/includes/simd/avx_double.h index 40774e1..268d20a 100644 --- a/common/includes/simd/avx_double.h +++ b/common/includes/simd/avx_double.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg. + * Copyright (C) NHR@FAU, University Erlangen-Nuremberg. * All rights reserved. This file is part of MD-Bench. * Use of this source code is governed by a LGPL-3.0 * license that can be found in the LICENSE file. diff --git a/common/includes/simd/avx_float.h b/common/includes/simd/avx_float.h index 4ebe09a..31ef5ff 100644 --- a/common/includes/simd/avx_float.h +++ b/common/includes/simd/avx_float.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg. + * Copyright (C) NHR@FAU, University Erlangen-Nuremberg. * All rights reserved. This file is part of MD-Bench. * Use of this source code is governed by a LGPL-3.0 * license that can be found in the LICENSE file. diff --git a/common/includes/thermo.h b/common/includes/thermo.h index a9d8357..c6af8ca 100644 --- a/common/includes/thermo.h +++ b/common/includes/thermo.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg. + * Copyright (C) NHR@FAU, University Erlangen-Nuremberg. * All rights reserved. This file is part of MD-Bench. * Use of this source code is governed by a LGPL-3.0 * license that can be found in the LICENSE file. diff --git a/common/includes/timers.h b/common/includes/timers.h index 28e17cd..de93132 100644 --- a/common/includes/timers.h +++ b/common/includes/timers.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg. + * Copyright (C) NHR@FAU, University Erlangen-Nuremberg. * All rights reserved. This file is part of MD-Bench. * Use of this source code is governed by a LGPL-3.0 * license that can be found in the LICENSE file. diff --git a/common/includes/timing.h b/common/includes/timing.h index 7792085..8ea6540 100644 --- a/common/includes/timing.h +++ b/common/includes/timing.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg. + * Copyright (C) NHR@FAU, University Erlangen-Nuremberg. * All rights reserved. This file is part of MD-Bench. * Use of this source code is governed by a LGPL-3.0 * license that can be found in the LICENSE file. diff --git a/common/includes/util.h b/common/includes/util.h index 00de105..f9c080f 100644 --- a/common/includes/util.h +++ b/common/includes/util.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg. + * Copyright (C) NHR@FAU, University Erlangen-Nuremberg. * All rights reserved. This file is part of MD-Bench. * Use of this source code is governed by a LGPL-3.0 * license that can be found in the LICENSE file. @@ -7,40 +7,41 @@ #ifndef __UTIL_H_ #define __UTIL_H_ +#include #ifndef MIN -# define MIN(x,y) ((x)<(y)?(x):(y)) +#define MIN(x, y) ((x) < (y) ? (x) : (y)) #endif #ifndef MAX -# define MAX(x,y) ((x)>(y)?(x):(y)) +#define MAX(x, y) ((x) > (y) ? (x) : (y)) #endif #ifndef ABS -# define ABS(a) ((a) >= 0 ? (a) : -(a)) +#define ABS(a) ((a) >= 0 ? (a) : -(a)) #endif #define DEBUG_MESSAGE debug_printf #ifndef MAXLINE -# define MAXLINE 4096 +#define MAXLINE 4096 #endif -#define FF_LJ 0 -#define FF_EAM 1 -#define FF_DEM 2 +#define FF_LJ 0 +#define FF_EAM 1 +#define FF_DEM 2 #if PRECISION == 1 -# define PRECISION_STRING "single" +#define PRECISION_STRING "single" #else -# define PRECISION_STRING "double" +#define PRECISION_STRING "double" #endif -extern double myrandom(int*); +extern double myrandom(int *); extern void random_reset(int *seed, int ibase, double *coord); extern int str2ff(const char *string); -extern const char* ff2str(int ff); +extern const char *ff2str(int ff); extern void readline(char *line, FILE *fp); extern void debug_printf(const char *format, ...); -extern int get_cuda_num_threads(); +extern int get_cuda_num_threads(void); #endif diff --git a/common/parameter.c b/common/parameter.c index 8aab646..43772e7 100644 --- a/common/parameter.c +++ b/common/parameter.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg. + * Copyright (C) NHR@FAU, University Erlangen-Nuremberg. * All rights reserved. This file is part of MD-Bench. * Use of this source code is governed by a LGPL-3.0 * license that can be found in the LICENSE file. diff --git a/common/thermo.c b/common/thermo.c index 0683876..d82655d 100644 --- a/common/thermo.c +++ b/common/thermo.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg. + * Copyright (C) NHR@FAU, University Erlangen-Nuremberg. * All rights reserved. This file is part of MD-Bench. * Use of this source code is governed by a LGPL-3.0 * license that can be found in the LICENSE file. diff --git a/common/timing.c b/common/timing.c index 8889ef6..ba8cbbd 100644 --- a/common/timing.c +++ b/common/timing.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg. + * Copyright (C) NHR@FAU, University Erlangen-Nuremberg. * All rights reserved. This file is part of MD-Bench. * Use of this source code is governed by a LGPL-3.0 * license that can be found in the LICENSE file. diff --git a/common/util.c b/common/util.c index 350c96f..ee96197 100644 --- a/common/util.c +++ b/common/util.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg. + * Copyright (C) NHR@FAU, University Erlangen-Nuremberg. * All rights reserved. This file is part of MD-Bench. * Use of this source code is governed by a LGPL-3.0 * license that can be found in the LICENSE file. diff --git a/config.mk b/config.mk index f8e1ede..a1662cc 100644 --- a/config.mk +++ b/config.mk @@ -1,17 +1,17 @@ # Compiler tag (GCC/CLANG/ICC/ICX/ONEAPI/NVCC) -TAG ?= ICC +TAG ?= CLANG # Instruction set (SSE/AVX/AVX_FMA/AVX2/AVX512) -ISA ?= AVX512 -# Optimization scheme (lammps/gromacs/clusters_per_bin) -OPT_SCHEME ?= lammps +ISA ?= SSE +# Optimization scheme (verletlist/clusterpair/clusters_per_bin) +OPT_SCHEME ?= verletlist # Enable likwid (true or false) -ENABLE_LIKWID ?= true +ENABLE_LIKWID ?= false # SP or DP DATA_TYPE ?= DP # AOS or SOA DATA_LAYOUT ?= AOS # Assembly syntax to generate (ATT/INTEL) -ASM_SYNTAX ?= ATT +ASM_SYNTAX ?= INTEL # Debug DEBUG ?= false @@ -28,7 +28,7 @@ COMPUTE_STATS ?= true # Configurations for lammps optimization scheme # Use omp simd pragma when running with half neighbor-lists -ENABLE_OMP_SIMD ?= true +ENABLE_OMP_SIMD ?= false # Use kernel with explicit SIMD intrinsics USE_SIMD_KERNEL ?= false diff --git a/lammps/force_lj.c b/lammps/force_lj.c deleted file mode 100644 index 599d14d..0000000 --- a/lammps/force_lj.c +++ /dev/null @@ -1,278 +0,0 @@ -/* - * Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg. - * All rights reserved. This file is part of MD-Bench. - * Use of this source code is governed by a LGPL-3.0 - * license that can be found in the LICENSE file. - */ -#include -#include -//--- -#include -#include -#include -#include -#include -#include - -#ifdef __SIMD_KERNEL__ -#include -#endif - -double computeForceLJFullNeigh_plain_c(Parameter *param, Atom *atom, Neighbor *neighbor, Stats *stats) { - int Nlocal = atom->Nlocal; - int* neighs; - #ifndef EXPLICIT_TYPES - MD_FLOAT cutforcesq = param->cutforce * param->cutforce; - MD_FLOAT sigma6 = param->sigma6; - MD_FLOAT epsilon = param->epsilon; - #endif - const MD_FLOAT num1 = 1.0; - const MD_FLOAT num48 = 48.0; - const MD_FLOAT num05 = 0.5; - - for(int i = 0; i < Nlocal; i++) { - atom_fx(i) = 0.0; - atom_fy(i) = 0.0; - atom_fz(i) = 0.0; - } - double S = getTimeStamp(); - - #pragma omp parallel - { - LIKWID_MARKER_START("force"); - - #pragma omp for schedule(runtime) - for(int i = 0; i < Nlocal; i++) { - neighs = &neighbor->neighbors[i * neighbor->maxneighs]; - int numneighs = neighbor->numneigh[i]; - MD_FLOAT xtmp = atom_x(i); - MD_FLOAT ytmp = atom_y(i); - MD_FLOAT ztmp = atom_z(i); - MD_FLOAT fix = 0; - MD_FLOAT fiy = 0; - MD_FLOAT fiz = 0; - - #ifdef EXPLICIT_TYPES - const int type_i = atom->type[i]; - #endif - - for(int k = 0; k < numneighs; k++) { - int j = neighs[k]; - MD_FLOAT delx = xtmp - atom_x(j); - MD_FLOAT dely = ytmp - atom_y(j); - MD_FLOAT delz = ztmp - atom_z(j); - MD_FLOAT rsq = delx * delx + dely * dely + delz * delz; - - #ifdef EXPLICIT_TYPES - const int type_j = atom->type[j]; - const int type_ij = type_i * atom->ntypes + type_j; - const MD_FLOAT cutforcesq = atom->cutforcesq[type_ij]; - const MD_FLOAT sigma6 = atom->sigma6[type_ij]; - const MD_FLOAT epsilon = atom->epsilon[type_ij]; - #endif - - if(rsq < cutforcesq) { - MD_FLOAT sr2 = num1 / rsq; - MD_FLOAT sr6 = sr2 * sr2 * sr2 * sigma6; - MD_FLOAT force = num48 * sr6 * (sr6 - num05) * sr2 * epsilon; - fix += delx * force; - fiy += dely * force; - fiz += delz * force; - #ifdef USE_REFERENCE_VERSION - addStat(stats->atoms_within_cutoff, 1); - } else { - addStat(stats->atoms_outside_cutoff, 1); - #endif - } - } - - atom_fx(i) += fix; - atom_fy(i) += fiy; - atom_fz(i) += fiz; - - #ifdef USE_REFERENCE_VERSION - if(numneighs % VECTOR_WIDTH > 0) { - addStat(stats->atoms_outside_cutoff, VECTOR_WIDTH - (numneighs % VECTOR_WIDTH)); - } - #endif - - addStat(stats->total_force_neighs, numneighs); - addStat(stats->total_force_iters, (numneighs + VECTOR_WIDTH - 1) / VECTOR_WIDTH); - } - - LIKWID_MARKER_STOP("force"); - } - - double E = getTimeStamp(); - return E-S; -} - -double computeForceLJHalfNeigh(Parameter *param, Atom *atom, Neighbor *neighbor, Stats *stats) { - int Nlocal = atom->Nlocal; - int* neighs; - #ifndef EXPLICIT_TYPES - MD_FLOAT cutforcesq = param->cutforce * param->cutforce; - MD_FLOAT sigma6 = param->sigma6; - MD_FLOAT epsilon = param->epsilon; - #endif - const MD_FLOAT num1 = 1.0; - const MD_FLOAT num48 = 48.0; - const MD_FLOAT num05 = 0.5; - - for(int i = 0; i < Nlocal; i++) { - atom_fx(i) = 0.0; - atom_fy(i) = 0.0; - atom_fz(i) = 0.0; - } - - double S = getTimeStamp(); - - #pragma omp parallel - { - LIKWID_MARKER_START("forceLJ-halfneigh"); - - #pragma omp for schedule(runtime) - for(int i = 0; i < Nlocal; i++) { - neighs = &neighbor->neighbors[i * neighbor->maxneighs]; - int numneighs = neighbor->numneigh[i]; - MD_FLOAT xtmp = atom_x(i); - MD_FLOAT ytmp = atom_y(i); - MD_FLOAT ztmp = atom_z(i); - MD_FLOAT fix = 0; - MD_FLOAT fiy = 0; - MD_FLOAT fiz = 0; - - #ifdef EXPLICIT_TYPES - const int type_i = atom->type[i]; - #endif - - // Pragma required to vectorize the inner loop - #ifdef ENABLE_OMP_SIMD - #pragma omp simd reduction(+: fix,fiy,fiz) - #endif - for(int k = 0; k < numneighs; k++) { - int j = neighs[k]; - MD_FLOAT delx = xtmp - atom_x(j); - MD_FLOAT dely = ytmp - atom_y(j); - MD_FLOAT delz = ztmp - atom_z(j); - MD_FLOAT rsq = delx * delx + dely * dely + delz * delz; - - #ifdef EXPLICIT_TYPES - const int type_j = atom->type[j]; - const int type_ij = type_i * atom->ntypes + type_j; - const MD_FLOAT cutforcesq = atom->cutforcesq[type_ij]; - const MD_FLOAT sigma6 = atom->sigma6[type_ij]; - const MD_FLOAT epsilon = atom->epsilon[type_ij]; - #endif - - if(rsq < cutforcesq) { - MD_FLOAT sr2 = num1 / rsq; - MD_FLOAT sr6 = sr2 * sr2 * sr2 * sigma6; - MD_FLOAT force = num48 * sr6 * (sr6 - num05) * sr2 * epsilon; - fix += delx * force; - fiy += dely * force; - fiz += delz * force; - - // We do not need to update forces for ghost atoms - if(j < Nlocal) { - atom_fx(j) -= delx * force; - atom_fy(j) -= dely * force; - atom_fz(j) -= delz * force; - } - } - } - - atom_fx(i) += fix; - atom_fy(i) += fiy; - atom_fz(i) += fiz; - - addStat(stats->total_force_neighs, numneighs); - addStat(stats->total_force_iters, (numneighs + VECTOR_WIDTH - 1) / VECTOR_WIDTH); - } - - LIKWID_MARKER_STOP("forceLJ-halfneigh"); - } - - double E = getTimeStamp(); - return E-S; -} - -double computeForceLJFullNeigh_simd(Parameter *param, Atom *atom, Neighbor *neighbor, Stats *stats) { - int Nlocal = atom->Nlocal; - int* neighs; - MD_FLOAT cutforcesq = param->cutforce * param->cutforce; - MD_FLOAT sigma6 = param->sigma6; - MD_FLOAT epsilon = param->epsilon; - - for(int i = 0; i < Nlocal; i++) { - atom_fx(i) = 0.0; - atom_fy(i) = 0.0; - atom_fz(i) = 0.0; - } - - double S = getTimeStamp(); - - #ifndef __SIMD_KERNEL__ - fprintf(stderr, "Error: SIMD kernel not implemented for specified instruction set!"); - exit(-1); - #else - MD_SIMD_FLOAT cutforcesq_vec = simd_broadcast(cutforcesq); - MD_SIMD_FLOAT sigma6_vec = simd_broadcast(sigma6); - MD_SIMD_FLOAT eps_vec = simd_broadcast(epsilon); - MD_SIMD_FLOAT c48_vec = simd_broadcast(48.0); - MD_SIMD_FLOAT c05_vec = simd_broadcast(0.5); - - - #pragma omp parallel - { - LIKWID_MARKER_START("force"); - - #pragma omp for schedule(runtime) - for(int i = 0; i < Nlocal; i++) { - neighs = &neighbor->neighbors[i * neighbor->maxneighs]; - int numneighs = neighbor->numneigh[i]; - MD_SIMD_INT numneighs_vec = simd_int_broadcast(numneighs); - MD_SIMD_FLOAT xtmp = simd_broadcast(atom_x(i)); - MD_SIMD_FLOAT ytmp = simd_broadcast(atom_y(i)); - MD_SIMD_FLOAT ztmp = simd_broadcast(atom_z(i)); - MD_SIMD_FLOAT fix = simd_zero(); - MD_SIMD_FLOAT fiy = simd_zero(); - MD_SIMD_FLOAT fiz = simd_zero(); - - for(int k = 0; k < numneighs; k += VECTOR_WIDTH) { - // If the last iteration of this loop is separated from the rest, this mask can be set only there - MD_SIMD_MASK mask_numneighs = simd_mask_int_cond_lt(simd_int_add(simd_int_broadcast(k), simd_int_seq()), numneighs_vec); - MD_SIMD_INT j = simd_int_mask_load(&neighs[k], mask_numneighs); - #ifdef AOS - MD_SIMD_INT j3 = simd_int_add(simd_int_add(j, j), j); // j * 3 - MD_SIMD_FLOAT delx = xtmp - simd_gather(j3, &(atom->x[0]), sizeof(MD_FLOAT)); - MD_SIMD_FLOAT dely = ytmp - simd_gather(j3, &(atom->x[1]), sizeof(MD_FLOAT)); - MD_SIMD_FLOAT delz = ztmp - simd_gather(j3, &(atom->x[2]), sizeof(MD_FLOAT)); - #else - MD_SIMD_FLOAT delx = xtmp - simd_gather(j, atom->x, sizeof(MD_FLOAT)); - MD_SIMD_FLOAT dely = ytmp - simd_gather(j, atom->y, sizeof(MD_FLOAT)); - MD_SIMD_FLOAT delz = ztmp - simd_gather(j, atom->z, sizeof(MD_FLOAT)); - #endif - MD_SIMD_FLOAT rsq = simd_fma(delx, delx, simd_fma(dely, dely, simd_mul(delz, delz))); - MD_SIMD_MASK cutoff_mask = simd_mask_and(mask_numneighs, simd_mask_cond_lt(rsq, cutforcesq_vec)); - MD_SIMD_FLOAT sr2 = simd_reciprocal(rsq); - MD_SIMD_FLOAT sr6 = simd_mul(sr2, simd_mul(sr2, simd_mul(sr2, sigma6_vec))); - MD_SIMD_FLOAT force = simd_mul(c48_vec, simd_mul(sr6, simd_mul(simd_sub(sr6, c05_vec), simd_mul(sr2, eps_vec)))); - - fix = simd_masked_add(fix, simd_mul(delx, force), cutoff_mask); - fiy = simd_masked_add(fiy, simd_mul(dely, force), cutoff_mask); - fiz = simd_masked_add(fiz, simd_mul(delz, force), cutoff_mask); - } - - atom_fx(i) += simd_h_reduce_sum(fix); - atom_fy(i) += simd_h_reduce_sum(fiy); - atom_fz(i) += simd_h_reduce_sum(fiz); - } - - LIKWID_MARKER_STOP("force"); - } - #endif - - double E = getTimeStamp(); - return E-S; -} diff --git a/lammps/pbc.c b/lammps/pbc.c deleted file mode 100644 index 5028c5b..0000000 --- a/lammps/pbc.c +++ /dev/null @@ -1,171 +0,0 @@ -/* - * Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg. - * All rights reserved. This file is part of MD-Bench. - * Use of this source code is governed by a LGPL-3.0 - * license that can be found in the LICENSE file. - */ -#include -#include -#include -//--- -#include -#include -#include - -#define DELTA 20000 - -int NmaxGhost; -int *PBCx, *PBCy, *PBCz; - -static void growPbc(Atom*); - -/* exported subroutines */ -void initPbc(Atom* atom) { - NmaxGhost = 0; - atom->border_map = NULL; - PBCx = NULL; PBCy = NULL; PBCz = NULL; -} - -/* update coordinates of ghost atoms */ -/* uses mapping created in setupPbc */ -void updatePbc_cpu(Atom *atom, Parameter *param, bool doReneighbor) { - int *border_map = atom->border_map; - int nlocal = atom->Nlocal; - MD_FLOAT xprd = param->xprd; - MD_FLOAT yprd = param->yprd; - MD_FLOAT zprd = param->zprd; - - for(int i = 0; i < atom->Nghost; i++) { - atom_x(nlocal + i) = atom_x(border_map[i]) + PBCx[i] * xprd; - atom_y(nlocal + i) = atom_y(border_map[i]) + PBCy[i] * yprd; - atom_z(nlocal + i) = atom_z(border_map[i]) + PBCz[i] * zprd; - } -} - -/* relocate atoms that have left domain according - * to periodic boundary conditions */ -void updateAtomsPbc_cpu(Atom *atom, Parameter *param) { - MD_FLOAT xprd = param->xprd; - MD_FLOAT yprd = param->yprd; - MD_FLOAT zprd = param->zprd; - - for(int i = 0; i < atom->Nlocal; i++) { - if(atom_x(i) < 0.0) { - atom_x(i) += xprd; - } else if(atom_x(i) >= xprd) { - atom_x(i) -= xprd; - } - - if(atom_y(i) < 0.0) { - atom_y(i) += yprd; - } else if(atom_y(i) >= yprd) { - atom_y(i) -= yprd; - } - - if(atom_z(i) < 0.0) { - atom_z(i) += zprd; - } else if(atom_z(i) >= zprd) { - atom_z(i) -= zprd; - } - } -} - -/* setup periodic boundary conditions by - * defining ghost atoms around domain - * only creates mapping and coordinate corrections - * that are then enforced in updatePbc */ -#define ADDGHOST(dx,dy,dz) \ - Nghost++; \ - border_map[Nghost] = i; \ - PBCx[Nghost] = dx; \ - PBCy[Nghost] = dy; \ - PBCz[Nghost] = dz; \ - atom->type[atom->Nlocal + Nghost] = atom->type[i] - -void setupPbc(Atom *atom, Parameter *param) { - int *border_map = atom->border_map; - MD_FLOAT xprd = param->xprd; - MD_FLOAT yprd = param->yprd; - MD_FLOAT zprd = param->zprd; - MD_FLOAT Cutneigh = param->cutneigh; - int Nghost = -1; - - for(int i = 0; i < atom->Nlocal; i++) { - if (atom->Nlocal + Nghost + 7 >= atom->Nmax) { - growAtom(atom); - } - - if (Nghost + 7 >= NmaxGhost) { - growPbc(atom); - border_map = atom->border_map; - } - - MD_FLOAT x = atom_x(i); - MD_FLOAT y = atom_y(i); - MD_FLOAT z = atom_z(i); - - /* Setup ghost atoms */ - /* 6 planes */ - if(param->pbc_x != 0) { - if (x < Cutneigh) { ADDGHOST(+1,0,0); } - if (x >= (xprd-Cutneigh)) { ADDGHOST(-1,0,0); } - } - - if(param->pbc_y != 0) { - if (y < Cutneigh) { ADDGHOST(0,+1,0); } - if (y >= (yprd-Cutneigh)) { ADDGHOST(0,-1,0); } - } - - if(param->pbc_z != 0) { - if (z < Cutneigh) { ADDGHOST(0,0,+1); } - if (z >= (zprd-Cutneigh)) { ADDGHOST(0,0,-1); } - } - - /* 8 corners */ - if(param->pbc_x != 0 && param->pbc_y != 0 && param->pbc_z != 0) { - if (x < Cutneigh && y < Cutneigh && z < Cutneigh) { ADDGHOST(+1,+1,+1); } - if (x < Cutneigh && y >= (yprd-Cutneigh) && z < Cutneigh) { ADDGHOST(+1,-1,+1); } - if (x < Cutneigh && y < Cutneigh && z >= (zprd-Cutneigh)) { ADDGHOST(+1,+1,-1); } - if (x < Cutneigh && y >= (yprd-Cutneigh) && z >= (zprd-Cutneigh)) { ADDGHOST(+1,-1,-1); } - if (x >= (xprd-Cutneigh) && y < Cutneigh && z < Cutneigh) { ADDGHOST(-1,+1,+1); } - if (x >= (xprd-Cutneigh) && y >= (yprd-Cutneigh) && z < Cutneigh) { ADDGHOST(-1,-1,+1); } - if (x >= (xprd-Cutneigh) && y < Cutneigh && z >= (zprd-Cutneigh)) { ADDGHOST(-1,+1,-1); } - if (x >= (xprd-Cutneigh) && y >= (yprd-Cutneigh) && z >= (zprd-Cutneigh)) { ADDGHOST(-1,-1,-1); } - } - - /* 12 edges */ - if(param->pbc_x != 0 && param->pbc_z != 0) { - if (x < Cutneigh && z < Cutneigh) { ADDGHOST(+1,0,+1); } - if (x < Cutneigh && z >= (zprd-Cutneigh)) { ADDGHOST(+1,0,-1); } - if (x >= (xprd-Cutneigh) && z < Cutneigh) { ADDGHOST(-1,0,+1); } - if (x >= (xprd-Cutneigh) && z >= (zprd-Cutneigh)) { ADDGHOST(-1,0,-1); } - } - - if(param->pbc_y != 0 && param->pbc_z != 0) { - if (y < Cutneigh && z < Cutneigh) { ADDGHOST(0,+1,+1); } - if (y < Cutneigh && z >= (zprd-Cutneigh)) { ADDGHOST(0,+1,-1); } - if (y >= (yprd-Cutneigh) && z < Cutneigh) { ADDGHOST(0,-1,+1); } - if (y >= (yprd-Cutneigh) && z >= (zprd-Cutneigh)) { ADDGHOST(0,-1,-1); } - } - - if(param->pbc_x != 0 && param->pbc_y != 0) { - if (y < Cutneigh && x < Cutneigh) { ADDGHOST(+1,+1,0); } - if (y < Cutneigh && x >= (xprd-Cutneigh)) { ADDGHOST(-1,+1,0); } - if (y >= (yprd-Cutneigh) && x < Cutneigh) { ADDGHOST(+1,-1,0); } - if (y >= (yprd-Cutneigh) && x >= (xprd-Cutneigh)) { ADDGHOST(-1,-1,0); } - } - } - // increase by one to make it the ghost atom count - atom->Nghost = Nghost + 1; -} - -/* internal subroutines */ -void growPbc(Atom* atom) { - int nold = NmaxGhost; - NmaxGhost += DELTA; - - atom->border_map = (int*) reallocate(atom->border_map, ALIGNMENT, NmaxGhost * sizeof(int), nold * sizeof(int)); - PBCx = (int*) reallocate(PBCx, ALIGNMENT, NmaxGhost * sizeof(int), nold * sizeof(int)); - PBCy = (int*) reallocate(PBCy, ALIGNMENT, NmaxGhost * sizeof(int), nold * sizeof(int)); - PBCz = (int*) reallocate(PBCz, ALIGNMENT, NmaxGhost * sizeof(int), nold * sizeof(int)); -} diff --git a/util/gather-bench/LICENSE b/util/gather-bench/LICENSE index 56d4399..7a6aa02 100644 --- a/util/gather-bench/LICENSE +++ b/util/gather-bench/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2021 RRZE-HPC +Copyright (c) RRZE-HPC Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/util/gather-bench/src/main-md-trace.c b/util/gather-bench/src/main-md-trace.c index 7094a76..9fade75 100644 --- a/util/gather-bench/src/main-md-trace.c +++ b/util/gather-bench/src/main-md-trace.c @@ -2,7 +2,7 @@ * ======================================================================================= * * Author: Jan Eitzinger (je), jan.eitzinger@fau.de - * Copyright (c) 2021 RRZE, University Erlangen-Nuremberg + * Copyright (c) RRZE, University Erlangen-Nuremberg * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/util/gather-bench/src/main-md.c b/util/gather-bench/src/main-md.c index fc7018c..2ad8c9a 100644 --- a/util/gather-bench/src/main-md.c +++ b/util/gather-bench/src/main-md.c @@ -2,7 +2,7 @@ * ======================================================================================= * * Author: Jan Eitzinger (je), jan.eitzinger@fau.de - * Copyright (c) 2021 RRZE, University Erlangen-Nuremberg + * Copyright (c) RRZE, University Erlangen-Nuremberg * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/util/gather-bench/src/main.c b/util/gather-bench/src/main.c index e8665ae..a0b9972 100644 --- a/util/gather-bench/src/main.c +++ b/util/gather-bench/src/main.c @@ -2,7 +2,7 @@ * ======================================================================================= * * Author: Jan Eitzinger (je), jan.eitzinger@fau.de - * Copyright (c) 2021 RRZE, University Erlangen-Nuremberg + * Copyright (c) RRZE, University Erlangen-Nuremberg * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/util/mdBench.c b/util/mdBench.c index 5311965..3bea419 100644 --- a/util/mdBench.c +++ b/util/mdBench.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg. + * Copyright (C) NHR@FAU, University Erlangen-Nuremberg. * All rights reserved. This file is part of MD-Bench. * Use of this source code is governed by a LGPL-3.0 * license that can be found in the LICENSE file. diff --git a/lammps/atom.c b/verletlist/atom.c similarity index 99% rename from lammps/atom.c rename to verletlist/atom.c index 5dd0cdf..acd2802 100644 --- a/lammps/atom.c +++ b/verletlist/atom.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg. + * Copyright (C) NHR@FAU, University Erlangen-Nuremberg. * All rights reserved. This file is part of MD-Bench. * Use of this source code is governed by a LGPL-3.0 * license that can be found in the LICENSE file. diff --git a/lammps/cuda/force.cu b/verletlist/cuda/force.cu similarity index 98% rename from lammps/cuda/force.cu rename to verletlist/cuda/force.cu index f96c826..0c0a744 100644 --- a/lammps/cuda/force.cu +++ b/verletlist/cuda/force.cu @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg. + * Copyright (C) NHR@FAU, University Erlangen-Nuremberg. * All rights reserved. This file is part of MD-Bench. * Use of this source code is governed by a LGPL-3.0 * license that can be found in the LICENSE file. diff --git a/lammps/cuda/neighbor.cu b/verletlist/cuda/neighbor.cu similarity index 99% rename from lammps/cuda/neighbor.cu rename to verletlist/cuda/neighbor.cu index 1e40e56..7787e05 100644 --- a/lammps/cuda/neighbor.cu +++ b/verletlist/cuda/neighbor.cu @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg. + * Copyright (C) NHR@FAU, University Erlangen-Nuremberg. * All rights reserved. This file is part of MD-Bench. * Use of this source code is governed by a LGPL-3.0 * license that can be found in the LICENSE file. diff --git a/lammps/cuda/pbc.cu b/verletlist/cuda/pbc.cu similarity index 98% rename from lammps/cuda/pbc.cu rename to verletlist/cuda/pbc.cu index 0c7df50..fb616ae 100644 --- a/lammps/cuda/pbc.cu +++ b/verletlist/cuda/pbc.cu @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg. + * Copyright (C) NHR@FAU, University Erlangen-Nuremberg. * All rights reserved. This file is part of MD-Bench. * Use of this source code is governed by a LGPL-3.0 * license that can be found in the LICENSE file. diff --git a/lammps/device_spec.c b/verletlist/device_spec.c similarity index 96% rename from lammps/device_spec.c rename to verletlist/device_spec.c index 42d6002..2a58c77 100644 --- a/lammps/device_spec.c +++ b/verletlist/device_spec.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg. + * Copyright (C) NHR@FAU, University Erlangen-Nuremberg. * All rights reserved. This file is part of MD-Bench. * Use of this source code is governed by a LGPL-3.0 * license that can be found in the LICENSE file. diff --git a/lammps/force_dem.c b/verletlist/force_dem.c similarity index 98% rename from lammps/force_dem.c rename to verletlist/force_dem.c index d40de02..1970196 100644 --- a/lammps/force_dem.c +++ b/verletlist/force_dem.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg. + * Copyright (C) NHR@FAU, University Erlangen-Nuremberg. * All rights reserved. This file is part of MD-Bench. * Use of this source code is governed by a LGPL-3.0 * license that can be found in the LICENSE file. diff --git a/lammps/force_eam.c b/verletlist/force_eam.c similarity index 99% rename from lammps/force_eam.c rename to verletlist/force_eam.c index 982dd7c..af0b38f 100644 --- a/lammps/force_eam.c +++ b/verletlist/force_eam.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg. + * Copyright (C) NHR@FAU, University Erlangen-Nuremberg. * All rights reserved. This file is part of MD-Bench. * Use of this source code is governed by a LGPL-3.0 * license that can be found in the LICENSE file. diff --git a/verletlist/force_lj.c b/verletlist/force_lj.c new file mode 100644 index 0000000..a5d9e2e --- /dev/null +++ b/verletlist/force_lj.c @@ -0,0 +1,298 @@ +/* + * Copyright (C) NHR@FAU, University Erlangen-Nuremberg. + * All rights reserved. This file is part of MD-Bench. + * Use of this source code is governed by a LGPL-3.0 + * license that can be found in the LICENSE file. + */ +#include +#include +//--- +#include +#include +#include +#include +#include +#include + +#ifdef __SIMD_KERNEL__ +#include +#endif + +double computeForceLJFullNeigh( + Parameter* param, Atom* atom, Neighbor* neighbor, Stats* stats) +{ + int nLocal = atom->Nlocal; + int* neighs; +#ifndef EXPLICIT_TYPES + MD_FLOAT cutforcesq = param->cutforce * param->cutforce; + MD_FLOAT sigma6 = param->sigma6; + MD_FLOAT epsilon = param->epsilon; +#endif + const MD_FLOAT num1 = 1.0; + const MD_FLOAT num48 = 48.0; + const MD_FLOAT num05 = 0.5; + + for (int i = 0; i < nLocal; i++) { + atom_fx(i) = 0.0; + atom_fy(i) = 0.0; + atom_fz(i) = 0.0; + } + double timeStart = getTimeStamp(); + +#pragma omp parallel + { + LIKWID_MARKER_START("force"); + +#pragma omp for schedule(runtime) + for (int i = 0; i < nLocal; i++) { + neighs = &neighbor->neighbors[i * neighbor->maxneighs]; + int numneighs = neighbor->numneigh[i]; + MD_FLOAT xtmp = atom_x(i); + MD_FLOAT ytmp = atom_y(i); + MD_FLOAT ztmp = atom_z(i); + MD_FLOAT fix = 0; + MD_FLOAT fiy = 0; + MD_FLOAT fiz = 0; + +#ifdef EXPLICIT_TYPES + const int type_i = atom->type[i]; +#endif + + for (int k = 0; k < numneighs; k++) { + int j = neighs[k]; + MD_FLOAT delx = xtmp - atom_x(j); + MD_FLOAT dely = ytmp - atom_y(j); + MD_FLOAT delz = ztmp - atom_z(j); + MD_FLOAT rsq = delx * delx + dely * dely + delz * delz; + +#ifdef EXPLICIT_TYPES + const int type_j = atom->type[j]; + const int type_ij = type_i * atom->ntypes + type_j; + const MD_FLOAT cutforcesq = atom->cutforcesq[type_ij]; + const MD_FLOAT sigma6 = atom->sigma6[type_ij]; + const MD_FLOAT epsilon = atom->epsilon[type_ij]; +#endif + + if (rsq < cutforcesq) { + MD_FLOAT sr2 = num1 / rsq; + MD_FLOAT sr6 = sr2 * sr2 * sr2 * sigma6; + MD_FLOAT force = num48 * sr6 * (sr6 - num05) * sr2 * epsilon; + fix += delx * force; + fiy += dely * force; + fiz += delz * force; +#ifdef USE_REFERENCE_VERSION + addStat(stats->atoms_within_cutoff, 1); + } else { + addStat(stats->atoms_outside_cutoff, 1); +#endif + } + } + + atom_fx(i) += fix; + atom_fy(i) += fiy; + atom_fz(i) += fiz; + +#ifdef USE_REFERENCE_VERSION + if (numneighs % VECTOR_WIDTH > 0) { + addStat(stats->atoms_outside_cutoff, + VECTOR_WIDTH - (numneighs % VECTOR_WIDTH)); + } +#endif + + addStat(stats->total_force_neighs, numneighs); + addStat(stats->total_force_iters, + (numneighs + VECTOR_WIDTH - 1) / VECTOR_WIDTH); + } + + LIKWID_MARKER_STOP("force"); + } + + double timeStop = getTimeStamp(); + return timeStop - timeStart; +} + +double computeForceLJHalfNeigh( + Parameter* param, Atom* atom, Neighbor* neighbor, Stats* stats) +{ + int nlocal = atom->Nlocal; + int* neighs; +#ifndef EXPLICIT_TYPES + MD_FLOAT cutforcesq = param->cutforce * param->cutforce; + MD_FLOAT sigma6 = param->sigma6; + MD_FLOAT epsilon = param->epsilon; +#endif + const MD_FLOAT num1 = 1.0; + const MD_FLOAT num48 = 48.0; + const MD_FLOAT num05 = 0.5; + + for (int i = 0; i < nlocal; i++) { + atom_fx(i) = 0.0; + atom_fy(i) = 0.0; + atom_fz(i) = 0.0; + } + + double timeStart = getTimeStamp(); + +#pragma omp parallel + { + LIKWID_MARKER_START("forceLJ-halfneigh"); + +#pragma omp for schedule(runtime) + for (int i = 0; i < nlocal; i++) { + neighs = &neighbor->neighbors[i * neighbor->maxneighs]; + int numneighs = neighbor->numneigh[i]; + MD_FLOAT xtmp = atom_x(i); + MD_FLOAT ytmp = atom_y(i); + MD_FLOAT ztmp = atom_z(i); + MD_FLOAT fix = 0; + MD_FLOAT fiy = 0; + MD_FLOAT fiz = 0; + +#ifdef EXPLICIT_TYPES + const int type_i = atom->type[i]; +#endif + +// Pragma required to vectorize the inner loop +#ifdef ENABLE_OMP_SIMD +#pragma omp simd reduction(+ : fix, fiy, fiz) +#endif + for (int k = 0; k < numneighs; k++) { + int j = neighs[k]; + MD_FLOAT delx = xtmp - atom_x(j); + MD_FLOAT dely = ytmp - atom_y(j); + MD_FLOAT delz = ztmp - atom_z(j); + MD_FLOAT rsq = delx * delx + dely * dely + delz * delz; + +#ifdef EXPLICIT_TYPES + const int type_j = atom->type[j]; + const int type_ij = type_i * atom->ntypes + type_j; + const MD_FLOAT cutforcesq = atom->cutforcesq[type_ij]; + const MD_FLOAT sigma6 = atom->sigma6[type_ij]; + const MD_FLOAT epsilon = atom->epsilon[type_ij]; +#endif + + if (rsq < cutforcesq) { + MD_FLOAT sr2 = num1 / rsq; + MD_FLOAT sr6 = sr2 * sr2 * sr2 * sigma6; + MD_FLOAT force = num48 * sr6 * (sr6 - num05) * sr2 * epsilon; + fix += delx * force; + fiy += dely * force; + fiz += delz * force; + + // We do not need to update forces for ghost atoms + if (j < nlocal) { + atom_fx(j) -= delx * force; + atom_fy(j) -= dely * force; + atom_fz(j) -= delz * force; + } + } + } + + atom_fx(i) += fix; + atom_fy(i) += fiy; + atom_fz(i) += fiz; + + addStat(stats->total_force_neighs, numneighs); + addStat(stats->total_force_iters, + (numneighs + VECTOR_WIDTH - 1) / VECTOR_WIDTH); + } + + LIKWID_MARKER_STOP("forceLJ-halfneigh"); + } + + double timeStop = getTimeStamp(); + return timeStop - timeStart; +} + +double computeForceLJFullNeigh_simd( + Parameter* param, Atom* atom, Neighbor* neighbor, Stats* stats) +{ + int Nlocal = atom->Nlocal; + int* neighs; + MD_FLOAT cutforcesq = param->cutforce * param->cutforce; + MD_FLOAT sigma6 = param->sigma6; + MD_FLOAT epsilon = param->epsilon; + + for (int i = 0; i < Nlocal; i++) { + atom_fx(i) = 0.0; + atom_fy(i) = 0.0; + atom_fz(i) = 0.0; + } + + double S = getTimeStamp(); + +#ifndef __SIMD_KERNEL__ + fprintf(stderr, "Error: SIMD kernel not implemented for specified instruction set!"); + exit(-1); +#else + MD_SIMD_FLOAT cutforcesq_vec = simd_broadcast(cutforcesq); + MD_SIMD_FLOAT sigma6_vec = simd_broadcast(sigma6); + MD_SIMD_FLOAT eps_vec = simd_broadcast(epsilon); + MD_SIMD_FLOAT c48_vec = simd_broadcast(48.0); + MD_SIMD_FLOAT c05_vec = simd_broadcast(0.5); + +#pragma omp parallel + { + LIKWID_MARKER_START("force"); + +#pragma omp for schedule(runtime) + for (int i = 0; i < Nlocal; i++) { + neighs = &neighbor->neighbors[i * neighbor->maxneighs]; + int numneighs = neighbor->numneigh[i]; + MD_SIMD_INT numneighs_vec = simd_int_broadcast(numneighs); + MD_SIMD_FLOAT xtmp = simd_broadcast(atom_x(i)); + MD_SIMD_FLOAT ytmp = simd_broadcast(atom_y(i)); + MD_SIMD_FLOAT ztmp = simd_broadcast(atom_z(i)); + MD_SIMD_FLOAT fix = simd_zero(); + MD_SIMD_FLOAT fiy = simd_zero(); + MD_SIMD_FLOAT fiz = simd_zero(); + + for (int k = 0; k < numneighs; k += VECTOR_WIDTH) { + // If the last iteration of this loop is separated from the rest, this + // mask can be set only there + MD_SIMD_MASK mask_numneighs = simd_mask_int_cond_lt( + simd_int_add(simd_int_broadcast(k), simd_int_seq()), + numneighs_vec); + MD_SIMD_INT j = simd_int_mask_load(&neighs[k], mask_numneighs); +#ifdef AOS + MD_SIMD_INT j3 = simd_int_add(simd_int_add(j, j), j); // j * 3 + MD_SIMD_FLOAT delx = xtmp - + simd_gather(j3, &(atom->x[0]), sizeof(MD_FLOAT)); + MD_SIMD_FLOAT dely = ytmp - + simd_gather(j3, &(atom->x[1]), sizeof(MD_FLOAT)); + MD_SIMD_FLOAT delz = ztmp - + simd_gather(j3, &(atom->x[2]), sizeof(MD_FLOAT)); +#else + MD_SIMD_FLOAT delx = xtmp - simd_gather(j, atom->x, sizeof(MD_FLOAT)); + MD_SIMD_FLOAT dely = ytmp - simd_gather(j, atom->y, sizeof(MD_FLOAT)); + MD_SIMD_FLOAT delz = ztmp - simd_gather(j, atom->z, sizeof(MD_FLOAT)); +#endif + MD_SIMD_FLOAT rsq = simd_fma(delx, + delx, + simd_fma(dely, dely, simd_mul(delz, delz))); + MD_SIMD_MASK cutoff_mask = simd_mask_and(mask_numneighs, + simd_mask_cond_lt(rsq, cutforcesq_vec)); + MD_SIMD_FLOAT sr2 = simd_reciprocal(rsq); + MD_SIMD_FLOAT sr6 = simd_mul(sr2, + simd_mul(sr2, simd_mul(sr2, sigma6_vec))); + MD_SIMD_FLOAT force = simd_mul(c48_vec, + simd_mul(sr6, + simd_mul(simd_sub(sr6, c05_vec), simd_mul(sr2, eps_vec)))); + + fix = simd_masked_add(fix, simd_mul(delx, force), cutoff_mask); + fiy = simd_masked_add(fiy, simd_mul(dely, force), cutoff_mask); + fiz = simd_masked_add(fiz, simd_mul(delz, force), cutoff_mask); + } + + atom_fx(i) += simd_h_reduce_sum(fix); + atom_fy(i) += simd_h_reduce_sum(fiy); + atom_fz(i) += simd_h_reduce_sum(fiz); + } + + LIKWID_MARKER_STOP("force"); + } +#endif + + double E = getTimeStamp(); + return E - S; +} diff --git a/lammps/includes/atom.h b/verletlist/includes/atom.h similarity index 98% rename from lammps/includes/atom.h rename to verletlist/includes/atom.h index 0fe3b51..a877f98 100644 --- a/lammps/includes/atom.h +++ b/verletlist/includes/atom.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg. + * Copyright (C) NHR@FAU, University Erlangen-Nuremberg. * All rights reserved. This file is part of MD-Bench. * Use of this source code is governed by a LGPL-3.0 * license that can be found in the LICENSE file. diff --git a/lammps/includes/integrate.h b/verletlist/includes/integrate.h similarity index 94% rename from lammps/includes/integrate.h rename to verletlist/includes/integrate.h index 56b5730..df8e125 100644 --- a/lammps/includes/integrate.h +++ b/verletlist/includes/integrate.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg. + * Copyright (C) NHR@FAU, University Erlangen-Nuremberg. * All rights reserved. This file is part of MD-Bench. * Use of this source code is governed by a LGPL-3.0 * license that can be found in the LICENSE file. diff --git a/lammps/includes/neighbor.h b/verletlist/includes/neighbor.h similarity index 94% rename from lammps/includes/neighbor.h rename to verletlist/includes/neighbor.h index 3b94175..89f2de8 100644 --- a/lammps/includes/neighbor.h +++ b/verletlist/includes/neighbor.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg. + * Copyright (C) NHR@FAU, University Erlangen-Nuremberg. * All rights reserved. This file is part of MD-Bench. * Use of this source code is governed by a LGPL-3.0 * license that can be found in the LICENSE file. diff --git a/lammps/includes/pbc.h b/verletlist/includes/pbc.h similarity index 86% rename from lammps/includes/pbc.h rename to verletlist/includes/pbc.h index 0703b8b..c351e32 100644 --- a/lammps/includes/pbc.h +++ b/verletlist/includes/pbc.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg. + * Copyright (C) NHR@FAU, University Erlangen-Nuremberg. * All rights reserved. This file is part of MD-Bench. * Use of this source code is governed by a LGPL-3.0 * license that can be found in the LICENSE file. @@ -11,7 +11,7 @@ #ifndef __PBC_H_ #define __PBC_H_ -extern void initPbc(); +extern void initPbc(Atom*); extern void updatePbc_cpu(Atom*, Parameter*, bool); extern void updateAtomsPbc_cpu(Atom*, Parameter*); extern void setupPbc(Atom*, Parameter*); diff --git a/lammps/includes/stats.h b/verletlist/includes/stats.h similarity index 93% rename from lammps/includes/stats.h rename to verletlist/includes/stats.h index fff315d..f426278 100644 --- a/lammps/includes/stats.h +++ b/verletlist/includes/stats.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg. + * Copyright (C) NHR@FAU, University Erlangen-Nuremberg. * All rights reserved. This file is part of MD-Bench. * Use of this source code is governed by a LGPL-3.0 * license that can be found in the LICENSE file. diff --git a/lammps/includes/tracing.h b/verletlist/includes/tracing.h similarity index 98% rename from lammps/includes/tracing.h rename to verletlist/includes/tracing.h index 7c4c59e..1ae2c0b 100644 --- a/lammps/includes/tracing.h +++ b/verletlist/includes/tracing.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg. + * Copyright (C) NHR@FAU, University Erlangen-Nuremberg. * All rights reserved. This file is part of MD-Bench. * Use of this source code is governed by a LGPL-3.0 * license that can be found in the LICENSE file. diff --git a/lammps/includes/vtk.h b/verletlist/includes/vtk.h similarity index 83% rename from lammps/includes/vtk.h rename to verletlist/includes/vtk.h index db5bfa4..d78a428 100644 --- a/lammps/includes/vtk.h +++ b/verletlist/includes/vtk.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg. + * Copyright (C) NHR@FAU, University Erlangen-Nuremberg. * All rights reserved. This file is part of MD-Bench. * Use of this source code is governed by a LGPL-3.0 * license that can be found in the LICENSE file. diff --git a/lammps/main-stub.c b/verletlist/main-stub.c similarity index 99% rename from lammps/main-stub.c rename to verletlist/main-stub.c index a41babe..c02c7c1 100644 --- a/lammps/main-stub.c +++ b/verletlist/main-stub.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg. + * Copyright (C) NHR@FAU, University Erlangen-Nuremberg. * All rights reserved. This file is part of MD-Bench. * Use of this source code is governed by a LGPL-3.0 * license that can be found in the LICENSE file. diff --git a/lammps/main.c b/verletlist/main.c similarity index 58% rename from lammps/main.c rename to verletlist/main.c index b291b52..970bf03 100644 --- a/lammps/main.c +++ b/verletlist/main.c @@ -1,18 +1,16 @@ /* - * Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg. + * Copyright (C) NHR@FAU, University Erlangen-Nuremberg. * All rights reserved. This file is part of MD-Bench. * Use of this source code is governed by a LGPL-3.0 * license that can be found in the LICENSE file. */ -#include +#include #include +#include #include #include -#include -#include -#include -#include +// #include #include #include @@ -20,20 +18,19 @@ #include #include #include -#include -#include #include #include #include #include +#include #include +#include #include #include -#define HLINE "----------------------------------------------------------------------------\n" +#define HLINE "------------------------------------------------------------------\n" extern double computeForceLJFullNeigh_plain_c(Parameter*, Atom*, Neighbor*, Stats*); -extern double computeForceLJFullNeigh_simd(Parameter*, Atom*, Neighbor*, Stats*); extern double computeForceLJHalfNeigh(Parameter*, Atom*, Neighbor*, Stats*); extern double computeForceEam(Eam*, Parameter*, Atom*, Neighbor*, Stats*); extern double computeForceDemFullNeigh(Parameter*, Atom*, Neighbor*, Stats*); @@ -42,20 +39,23 @@ extern double computeForceDemFullNeigh(Parameter*, Atom*, Neighbor*, Stats*); extern double computeForceLJFullNeigh_cuda(Parameter*, Atom*, Neighbor*); #endif -double setup(Parameter *param, Eam *eam, Atom *atom, Neighbor *neighbor, Stats *stats) { - if(param->force_field == FF_EAM) { initEam(eam, param); } - double S, E; +double setup(Parameter* param, Eam* eam, Atom* atom, Neighbor* neighbor, Stats* stats) +{ + if (param->force_field == FF_EAM) { + initEam(eam, param); + } + double timeStart, timeStop; param->lattice = pow((4.0 / param->rho), (1.0 / 3.0)); - param->xprd = param->nx * param->lattice; - param->yprd = param->ny * param->lattice; - param->zprd = param->nz * param->lattice; + param->xprd = param->nx * param->lattice; + param->yprd = param->ny * param->lattice; + param->zprd = param->nz * param->lattice; - S = getTimeStamp(); + timeStart = getTimeStamp(); initAtom(atom); initPbc(atom); initStats(stats); initNeighbor(neighbor, param); - if(param->input_file == NULL) { + if (param->input_file == NULL) { createAtom(atom, param); } else { readAtom(atom, param); @@ -63,49 +63,59 @@ double setup(Parameter *param, Eam *eam, Atom *atom, Neighbor *neighbor, Stats * setupNeighbor(param); setupThermo(param, atom->Natoms); - if(param->input_file == NULL) { adjustThermo(param, atom); } - #ifdef SORT_ATOMS + if (param->input_file == NULL) { + adjustThermo(param, atom); + } +#ifdef SORT_ATOMS atom->Nghost = 0; sortAtom(atom); - #endif +#endif setupPbc(atom, param); initDevice(atom, neighbor); updatePbc(atom, param, true); buildNeighbor(atom, neighbor); - E = getTimeStamp(); - return E-S; + timeStop = getTimeStamp(); + return timeStop - timeStart; } -double reneighbour(Parameter *param, Atom *atom, Neighbor *neighbor) { - double S, E; - S = getTimeStamp(); +double reneighbour(Parameter* param, Atom* atom, Neighbor* neighbor) +{ + double timeStart, timeStop; + timeStart = getTimeStamp(); LIKWID_MARKER_START("reneighbour"); updateAtomsPbc(atom, param); - #ifdef SORT_ATOMS +#ifdef SORT_ATOMS atom->Nghost = 0; sortAtom(atom); - #endif +#endif setupPbc(atom, param); updatePbc(atom, param, true); buildNeighbor(atom, neighbor); LIKWID_MARKER_STOP("reneighbour"); - E = getTimeStamp(); - return E-S; + timeStop = getTimeStamp(); + return timeStop - timeStart; } -void printAtomState(Atom *atom) { - printf("Atom counts: Natoms=%d Nlocal=%d Nghost=%d Nmax=%d\n", atom->Natoms, atom->Nlocal, atom->Nghost, atom->Nmax); +void printAtomState(Atom* atom) +{ + printf("Atom counts: Natoms=%d Nlocal=%d Nghost=%d Nmax=%d\n", + atom->Natoms, + atom->Nlocal, + atom->Nghost, + atom->Nmax); // int nall = atom->Nlocal + atom->Nghost; // for (int i=0; ix[i], atom->y[i], atom->z[i]); // } } -double computeForce(Eam *eam, Parameter *param, Atom *atom, Neighbor *neighbor, Stats *stats) { - if(param->force_field == FF_EAM) { +double computeForce( + Eam* eam, Parameter* param, Atom* atom, Neighbor* neighbor, Stats* stats) +{ + if (param->force_field == FF_EAM) { return computeForceEam(eam, param, atom, neighbor, stats); - } else if(param->force_field == FF_DEM) { - if(param->half_neigh) { + } else if (param->force_field == FF_DEM) { + if (param->half_neigh) { fprintf(stderr, "Error: DEM cannot use half neighbor-lists!\n"); return 0.0; } else { @@ -113,29 +123,38 @@ double computeForce(Eam *eam, Parameter *param, Atom *atom, Neighbor *neighbor, } } - if(param->half_neigh) { + if (param->half_neigh) { return computeForceLJHalfNeigh(param, atom, neighbor, stats); } - #ifdef CUDA_TARGET +#ifdef CUDA_TARGET return computeForceLJFullNeigh(param, atom, neighbor); - #else +#else return computeForceLJFullNeigh(param, atom, neighbor, stats); - #endif +#endif } -void writeInput(Parameter *param, Atom *atom) { - FILE *fpin = fopen("input.in", "w"); +void writeInput(Parameter* param, Atom* atom) +{ + FILE* fpin = fopen("input.in", "w"); fprintf(fpin, "0,%f,0,%f,0,%f\n", param->xprd, param->yprd, param->zprd); - for(int i = 0; i < atom->Nlocal; i++) { - fprintf(fpin, "1,%f,%f,%f,%f,%f,%f\n", atom_x(i), atom_y(i), atom_z(i), atom_vx(i), atom_vy(i), atom_vz(i)); + for (int i = 0; i < atom->Nlocal; i++) { + fprintf(fpin, + "1,%f,%f,%f,%f,%f,%f\n", + atom_x(i), + atom_y(i), + atom_z(i), + atom_vx(i), + atom_vy(i), + atom_vz(i)); } fclose(fpin); } -int main(int argc, char** argv) { +int main(int argc, char** argv) +{ double timer[NUMTIMER]; Eam eam; Atom atom; @@ -147,81 +166,87 @@ int main(int argc, char** argv) { #pragma omp parallel { LIKWID_MARKER_REGISTER("force"); - //LIKWID_MARKER_REGISTER("reneighbour"); - //LIKWID_MARKER_REGISTER("pbc"); + // LIKWID_MARKER_REGISTER("reneighbour"); + // LIKWID_MARKER_REGISTER("pbc"); } initParameter(¶m); - for(int i = 0; i < argc; i++) { - if((strcmp(argv[i], "-p") == 0) || strcmp(argv[i], "--params") == 0) { + for (int i = 0; i < argc; i++) { + if ((strcmp(argv[i], "-p") == 0) || strcmp(argv[i], "--params") == 0) { readParameter(¶m, argv[++i]); continue; } - if((strcmp(argv[i], "-f") == 0)) { - if((param.force_field = str2ff(argv[++i])) < 0) { + if ((strcmp(argv[i], "-f") == 0)) { + if ((param.force_field = str2ff(argv[++i])) < 0) { fprintf(stderr, "Invalid force field!\n"); exit(-1); } continue; } - if((strcmp(argv[i], "-i") == 0)) { + if ((strcmp(argv[i], "-i") == 0)) { param.input_file = strdup(argv[++i]); continue; } - if((strcmp(argv[i], "-e") == 0)) { + if ((strcmp(argv[i], "-e") == 0)) { param.eam_file = strdup(argv[++i]); continue; } - if((strcmp(argv[i], "-n") == 0) || (strcmp(argv[i], "--nsteps") == 0)) { + if ((strcmp(argv[i], "-n") == 0) || (strcmp(argv[i], "--nsteps") == 0)) { param.ntimes = atoi(argv[++i]); continue; } - if((strcmp(argv[i], "-nx") == 0)) { + if ((strcmp(argv[i], "-nx") == 0)) { param.nx = atoi(argv[++i]); continue; } - if((strcmp(argv[i], "-ny") == 0)) { + if ((strcmp(argv[i], "-ny") == 0)) { param.ny = atoi(argv[++i]); continue; } - if((strcmp(argv[i], "-nz") == 0)) { + if ((strcmp(argv[i], "-nz") == 0)) { param.nz = atoi(argv[++i]); continue; } - if((strcmp(argv[i], "-half") == 0)) { + if ((strcmp(argv[i], "-half") == 0)) { param.half_neigh = atoi(argv[++i]); continue; } - if((strcmp(argv[i], "-r") == 0) || (strcmp(argv[i], "--radius") == 0)) { + if ((strcmp(argv[i], "-r") == 0) || (strcmp(argv[i], "--radius") == 0)) { param.cutforce = atof(argv[++i]); continue; } - if((strcmp(argv[i], "-s") == 0) || (strcmp(argv[i], "--skin") == 0)) { + if ((strcmp(argv[i], "-s") == 0) || (strcmp(argv[i], "--skin") == 0)) { param.skin = atof(argv[++i]); continue; } - if((strcmp(argv[i], "--freq") == 0)) { + if ((strcmp(argv[i], "--freq") == 0)) { param.proc_freq = atof(argv[++i]); continue; } - if((strcmp(argv[i], "--vtk") == 0)) { + if ((strcmp(argv[i], "--vtk") == 0)) { param.vtk_file = strdup(argv[++i]); continue; } - if((strcmp(argv[i], "-w") == 0)) { + if ((strcmp(argv[i], "-w") == 0)) { param.write_atom_file = strdup(argv[++i]); continue; } - if((strcmp(argv[i], "-h") == 0) || (strcmp(argv[i], "--help") == 0)) { + if ((strcmp(argv[i], "-h") == 0) || (strcmp(argv[i], "--help") == 0)) { printf("MD Bench: A minimalistic re-implementation of miniMD\n"); printf(HLINE); - printf("-p / --params : file to read parameters from (can be specified more than once)\n"); - printf("-f : force field (lj, eam or dem), default lj\n"); - printf("-i : input file with atom positions (dump)\n"); + printf("-p / --params : file to read parameters from (can be " + "specified more than once)\n"); + printf("-f : force field (lj, eam or dem), " + "default lj\n"); + printf("-i : input file with atom positions " + "(dump)\n"); printf("-e : input file for EAM\n"); - printf("-n / --nsteps : set number of timesteps for simulation\n"); - printf("-nx/-ny/-nz : set linear dimension of systembox in x/y/z direction\n"); - printf("-half : use half (1) or full (0) neighbor lists\n"); + printf("-n / --nsteps : set number of timesteps for " + "simulation\n"); + printf("-nx/-ny/-nz : set linear dimension of systembox in " + "x/y/z direction\n"); + printf("-half : use half (1) or full (0) neighbor " + "lists\n"); printf("-r / --radius : set cutoff radius\n"); printf("-s / --skin : set skin (verlet buffer)\n"); printf("-w : write input atoms to file\n"); @@ -239,48 +264,48 @@ int main(int argc, char** argv) { printf("step\ttemp\t\tpressure\n"); computeThermo(0, ¶m, &atom); - #if defined(MEM_TRACER) || defined(INDEX_TRACER) +#if defined(MEM_TRACER) || defined(INDEX_TRACER) traceAddresses(¶m, &atom, &neighbor, n + 1); - #endif +#endif - if(param.write_atom_file != NULL) { + if (param.write_atom_file != NULL) { writeAtom(&atom, ¶m); } - //writeInput(¶m, &atom); + // writeInput(¶m, &atom); timer[FORCE] = computeForce(&eam, ¶m, &atom, &neighbor, &stats); timer[NEIGH] = 0.0; timer[TOTAL] = getTimeStamp(); - if(param.vtk_file != NULL) { + if (param.vtk_file != NULL) { write_atoms_to_vtk_file(param.vtk_file, &atom, 0); } - for(int n = 0; n < param.ntimes; n++) { + for (int n = 0; n < param.ntimes; n++) { bool reneigh = (n + 1) % param.reneigh_every == 0; initialIntegrate(reneigh, ¶m, &atom); - if((n + 1) % param.reneigh_every) { + if ((n + 1) % param.reneigh_every) { updatePbc(&atom, ¶m, false); } else { timer[NEIGH] += reneighbour(¶m, &atom, &neighbor); } - #if defined(MEM_TRACER) || defined(INDEX_TRACER) +#if defined(MEM_TRACER) || defined(INDEX_TRACER) traceAddresses(¶m, &atom, &neighbor, n + 1); - #endif +#endif timer[FORCE] += computeForce(&eam, ¶m, &atom, &neighbor, &stats); finalIntegrate(reneigh, ¶m, &atom); - if(!((n + 1) % param.nstat) && (n+1) < param.ntimes) { - #ifdef CUDA_TARGET + if (!((n + 1) % param.nstat) && (n + 1) < param.ntimes) { +#ifdef CUDA_TARGET memcpyFromGPU(atom.x, atom.d_atom.x, atom.Nmax * sizeof(MD_FLOAT) * 3); - #endif +#endif computeThermo(n + 1, ¶m, &atom); } - if(param.vtk_file != NULL) { + if (param.vtk_file != NULL) { write_atoms_to_vtk_file(param.vtk_file, &atom, n + 1); } } @@ -289,36 +314,49 @@ int main(int argc, char** argv) { computeThermo(-1, ¶m, &atom); printf(HLINE); - printf("System: %d atoms %d ghost atoms, Steps: %d\n", atom.Natoms, atom.Nghost, param.ntimes); + printf("System: %d atoms %d ghost atoms, Steps: %d\n", + atom.Natoms, + atom.Nghost, + param.ntimes); printf("TOTAL %.2fs FORCE %.2fs NEIGH %.2fs REST %.2fs\n", - timer[TOTAL], timer[FORCE], timer[NEIGH], timer[TOTAL]-timer[FORCE]-timer[NEIGH]); + timer[TOTAL], + timer[FORCE], + timer[NEIGH], + timer[TOTAL] - timer[FORCE] - timer[NEIGH]); printf(HLINE); - int nthreads = 0; - int chunkSize = 0; - omp_sched_t schedKind; - char schedType[10]; -#pragma omp parallel -#pragma omp master - { - omp_get_schedule(&schedKind, &chunkSize); + // int nthreads = 0; + // int chunkSize = 0; + // omp_sched_t schedKind; + // char schedType[10]; + // #pragma omp parallel + // #pragma omp master + // { + // omp_get_schedule(&schedKind, &chunkSize); + // + // switch (schedKind) { + // case omp_sched_static: + // strcpy(schedType, "static"); + // break; + // case omp_sched_dynamic: + // strcpy(schedType, "dynamic"); + // break; + // case omp_sched_guided: + // strcpy(schedType, "guided"); + // break; + // case omp_sched_auto: + // strcpy(schedType, "auto"); + // break; + // } + // + // nthreads = omp_get_max_threads(); + // } + // + // printf("Num threads: %d\n", nthreads); + // printf("Schedule: (%s,%d)\n", schedType, chunkSize); - switch (schedKind) - { - case omp_sched_static: strcpy(schedType, "static"); break; - case omp_sched_dynamic: strcpy(schedType, "dynamic"); break; - case omp_sched_guided: strcpy(schedType, "guided"); break; - case omp_sched_auto: strcpy(schedType, "auto"); break; - } - - nthreads = omp_get_max_threads(); - } - - printf("Num threads: %d\n", nthreads); - printf("Schedule: (%s,%d)\n", schedType, chunkSize); - printf("Performance: %.2f million atom updates per second\n", - 1e-6 * (double) atom.Natoms * param.ntimes / timer[TOTAL]); + 1e-6 * (double)atom.Natoms * param.ntimes / timer[TOTAL]); #ifdef COMPUTE_STATS displayStatistics(&atom, ¶m, &stats, timer); #endif diff --git a/lammps/neighbor.c b/verletlist/neighbor.c similarity index 99% rename from lammps/neighbor.c rename to verletlist/neighbor.c index c06f678..2c0dc25 100644 --- a/lammps/neighbor.c +++ b/verletlist/neighbor.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg. + * Copyright (C) NHR@FAU, University Erlangen-Nuremberg. * All rights reserved. This file is part of MD-Bench. * Use of this source code is governed by a LGPL-3.0 * license that can be found in the LICENSE file. diff --git a/verletlist/pbc.c b/verletlist/pbc.c new file mode 100644 index 0000000..59032a3 --- /dev/null +++ b/verletlist/pbc.c @@ -0,0 +1,234 @@ +/* + * Copyright (C) NHR@FAU, University Erlangen-Nuremberg. + * All rights reserved. This file is part of MD-Bench. + * Use of this source code is governed by a LGPL-3.0 + * license that can be found in the LICENSE file. + */ +#include +#include +#include +//--- +#include +#include +#include + +#define DELTA 20000 + +int nmaxGhost; +int *PBCx, *PBCy, *PBCz; + +static void growPbc(Atom*); + +/* exported subroutines */ +void initPbc(Atom* atom) +{ + nmaxGhost = 0; + atom->border_map = NULL; + PBCx = NULL; + PBCy = NULL; + PBCz = NULL; +} + +/* update coordinates of ghost atoms */ +/* uses mapping created in setupPbc */ +void updatePbc_cpu(Atom* atom, Parameter* param, bool doReneighbor) +{ + int* borderMap = atom->border_map; + int nlocal = atom->Nlocal; + MD_FLOAT xprd = param->xprd; + MD_FLOAT yprd = param->yprd; + MD_FLOAT zprd = param->zprd; + + for (int i = 0; i < atom->Nghost; i++) { + atom_x(nlocal + i) = atom_x(borderMap[i]) + PBCx[i] * xprd; + atom_y(nlocal + i) = atom_y(borderMap[i]) + PBCy[i] * yprd; + atom_z(nlocal + i) = atom_z(borderMap[i]) + PBCz[i] * zprd; + } +} + +/* relocate atoms that have left domain according + * to periodic boundary conditions */ +void updateAtomsPbc_cpu(Atom* atom, Parameter* param) +{ + MD_FLOAT xprd = param->xprd; + MD_FLOAT yprd = param->yprd; + MD_FLOAT zprd = param->zprd; + + for (int i = 0; i < atom->Nlocal; i++) { + if (atom_x(i) < 0.0) { + atom_x(i) += xprd; + } else if (atom_x(i) >= xprd) { + atom_x(i) -= xprd; + } + + if (atom_y(i) < 0.0) { + atom_y(i) += yprd; + } else if (atom_y(i) >= yprd) { + atom_y(i) -= yprd; + } + + if (atom_z(i) < 0.0) { + atom_z(i) += zprd; + } else if (atom_z(i) >= zprd) { + atom_z(i) -= zprd; + } + } +} + +/* setup periodic boundary conditions by + * defining ghost atoms around domain + * only creates mapping and coordinate corrections + * that are then enforced in updatePbc */ +#define ADDGHOST(dx, dy, dz) \ + Nghost++; \ + border_map[Nghost] = i; \ + PBCx[Nghost] = dx; \ + PBCy[Nghost] = dy; \ + PBCz[Nghost] = dz; \ + atom->type[atom->Nlocal + Nghost] = atom->type[i] + +void setupPbc(Atom* atom, Parameter* param) +{ + int* border_map = atom->border_map; + MD_FLOAT xprd = param->xprd; + MD_FLOAT yprd = param->yprd; + MD_FLOAT zprd = param->zprd; + MD_FLOAT cutneigh = param->cutneigh; + int Nghost = -1; + + for (int i = 0; i < atom->Nlocal; i++) { + if (atom->Nlocal + Nghost + 7 >= atom->Nmax) { + growAtom(atom); + } + + if (Nghost + 7 >= nmaxGhost) { + growPbc(atom); + border_map = atom->border_map; + } + + MD_FLOAT x = atom_x(i); + MD_FLOAT y = atom_y(i); + MD_FLOAT z = atom_z(i); + + /* Setup ghost atoms */ + /* 6 planes */ + if (param->pbc_x != 0) { + if (x < cutneigh) { + ADDGHOST(+1, 0, 0); + } + if (x >= (xprd - cutneigh)) { + ADDGHOST(-1, 0, 0); + } + } + + if (param->pbc_y != 0) { + if (y < cutneigh) { + ADDGHOST(0, +1, 0); + } + if (y >= (yprd - cutneigh)) { + ADDGHOST(0, -1, 0); + } + } + + if (param->pbc_z != 0) { + if (z < cutneigh) { + ADDGHOST(0, 0, +1); + } + if (z >= (zprd - cutneigh)) { + ADDGHOST(0, 0, -1); + } + } + + /* 8 corners */ + if (param->pbc_x != 0 && param->pbc_y != 0 && param->pbc_z != 0) { + if (x < cutneigh && y < cutneigh && z < cutneigh) { + ADDGHOST(+1, +1, +1); + } + if (x < cutneigh && y >= (yprd - cutneigh) && z < cutneigh) { + ADDGHOST(+1, -1, +1); + } + if (x < cutneigh && y < cutneigh && z >= (zprd - cutneigh)) { + ADDGHOST(+1, +1, -1); + } + if (x < cutneigh && y >= (yprd - cutneigh) && z >= (zprd - cutneigh)) { + ADDGHOST(+1, -1, -1); + } + if (x >= (xprd - cutneigh) && y < cutneigh && z < cutneigh) { + ADDGHOST(-1, +1, +1); + } + if (x >= (xprd - cutneigh) && y >= (yprd - cutneigh) && z < cutneigh) { + ADDGHOST(-1, -1, +1); + } + if (x >= (xprd - cutneigh) && y < cutneigh && z >= (zprd - cutneigh)) { + ADDGHOST(-1, +1, -1); + } + if (x >= (xprd - cutneigh) && y >= (yprd - cutneigh) && + z >= (zprd - cutneigh)) { + ADDGHOST(-1, -1, -1); + } + } + + /* 12 edges */ + if (param->pbc_x != 0 && param->pbc_z != 0) { + if (x < cutneigh && z < cutneigh) { + ADDGHOST(+1, 0, +1); + } + if (x < cutneigh && z >= (zprd - cutneigh)) { + ADDGHOST(+1, 0, -1); + } + if (x >= (xprd - cutneigh) && z < cutneigh) { + ADDGHOST(-1, 0, +1); + } + if (x >= (xprd - cutneigh) && z >= (zprd - cutneigh)) { + ADDGHOST(-1, 0, -1); + } + } + + if (param->pbc_y != 0 && param->pbc_z != 0) { + if (y < cutneigh && z < cutneigh) { + ADDGHOST(0, +1, +1); + } + if (y < cutneigh && z >= (zprd - cutneigh)) { + ADDGHOST(0, +1, -1); + } + if (y >= (yprd - cutneigh) && z < cutneigh) { + ADDGHOST(0, -1, +1); + } + if (y >= (yprd - cutneigh) && z >= (zprd - cutneigh)) { + ADDGHOST(0, -1, -1); + } + } + + if (param->pbc_x != 0 && param->pbc_y != 0) { + if (y < cutneigh && x < cutneigh) { + ADDGHOST(+1, +1, 0); + } + if (y < cutneigh && x >= (xprd - cutneigh)) { + ADDGHOST(-1, +1, 0); + } + if (y >= (yprd - cutneigh) && x < cutneigh) { + ADDGHOST(+1, -1, 0); + } + if (y >= (yprd - cutneigh) && x >= (xprd - cutneigh)) { + ADDGHOST(-1, -1, 0); + } + } + } + // increase by one to make it the ghost atom count + atom->Nghost = Nghost + 1; +} + +/* internal subroutines */ +void growPbc(Atom* atom) +{ + int nold = nmaxGhost; + nmaxGhost += DELTA; + + atom->border_map = (int*)reallocate(atom->border_map, + ALIGNMENT, + nmaxGhost * sizeof(int), + nold * sizeof(int)); + PBCx = (int*)reallocate(PBCx, ALIGNMENT, nmaxGhost * sizeof(int), nold * sizeof(int)); + PBCy = (int*)reallocate(PBCy, ALIGNMENT, nmaxGhost * sizeof(int), nold * sizeof(int)); + PBCz = (int*)reallocate(PBCz, ALIGNMENT, nmaxGhost * sizeof(int), nold * sizeof(int)); +} diff --git a/lammps/stats.c b/verletlist/stats.c similarity index 97% rename from lammps/stats.c rename to verletlist/stats.c index 636f934..4b9e222 100644 --- a/lammps/stats.c +++ b/verletlist/stats.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg. + * Copyright (C) NHR@FAU, University Erlangen-Nuremberg. * All rights reserved. This file is part of MD-Bench. * Use of this source code is governed by a LGPL-3.0 * license that can be found in the LICENSE file. diff --git a/lammps/tracing.c b/verletlist/tracing.c similarity index 96% rename from lammps/tracing.c rename to verletlist/tracing.c index 13e68fe..8536914 100644 --- a/lammps/tracing.c +++ b/verletlist/tracing.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg. + * Copyright (C) NHR@FAU, University Erlangen-Nuremberg. * All rights reserved. This file is part of MD-Bench. * Use of this source code is governed by a LGPL-3.0 * license that can be found in the LICENSE file. diff --git a/lammps/vtk.c b/verletlist/vtk.c similarity index 96% rename from lammps/vtk.c rename to verletlist/vtk.c index c02ba1e..6c404be 100644 --- a/lammps/vtk.c +++ b/verletlist/vtk.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg. + * Copyright (C) NHR@FAU, University Erlangen-Nuremberg. * All rights reserved. This file is part of MD-Bench. * Use of this source code is governed by a LGPL-3.0 * license that can be found in the LICENSE file.