Skip to content

Commit

Permalink
added experimental support for multiple processors
Browse files Browse the repository at this point in the history
  • Loading branch information
steffennissen committed Nov 30, 2013
1 parent e57924c commit 3d07691
Show file tree
Hide file tree
Showing 24 changed files with 1,883 additions and 6 deletions.
8 changes: 8 additions & 0 deletions VS2010/fann.sln
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "steepness_train", "steepnes
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "xor_cpp_sample", "xor_cpp_sample\xor_cpp_sample.vcxproj", "{F556FB08-2D23-450B-AF1F-1E226DE08421}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "parallel_train", "parallel_train\parallel_train.vcxproj", "{2C326817-564B-40ED-BB25-BC10B1AB505F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Expand Down Expand Up @@ -139,6 +141,12 @@ Global
{F556FB08-2D23-450B-AF1F-1E226DE08421}.Release|Win32.ActiveCfg = Release|Win32
{F556FB08-2D23-450B-AF1F-1E226DE08421}.Release|Win32.Build.0 = Release|Win32
{F556FB08-2D23-450B-AF1F-1E226DE08421}.Release|x64.ActiveCfg = Release|Win32
{2C326817-564B-40ED-BB25-BC10B1AB505F}.Debug|Win32.ActiveCfg = Debug|Win32
{2C326817-564B-40ED-BB25-BC10B1AB505F}.Debug|Win32.Build.0 = Debug|Win32
{2C326817-564B-40ED-BB25-BC10B1AB505F}.Debug|x64.ActiveCfg = Debug|Win32
{2C326817-564B-40ED-BB25-BC10B1AB505F}.Release|Win32.ActiveCfg = Release|Win32
{2C326817-564B-40ED-BB25-BC10B1AB505F}.Release|Win32.Build.0 = Release|Win32
{2C326817-564B-40ED-BB25-BC10B1AB505F}.Release|x64.ActiveCfg = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
8 changes: 8 additions & 0 deletions VS2010/fanndouble/fanndouble.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;_USRDLL;FANN_DLL_EXPORTS;WIN32;_WINDOWS;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\..\src\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<ForcedIncludeFiles>..\..\src\include\doublefann.h</ForcedIncludeFiles>
<CompileAs>CompileAsCpp</CompileAs>
<OpenMPSupport>true</OpenMPSupport>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
Expand All @@ -74,6 +76,8 @@
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;_USRDLL;FANN_DLL_EXPORTS;WIN32;_WINDOWS;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\..\src\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<ForcedIncludeFiles>..\..\src\include\doublefann.h</ForcedIncludeFiles>
<CompileAs>CompileAsCpp</CompileAs>
<OpenMPSupport>true</OpenMPSupport>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
Expand All @@ -89,6 +93,8 @@
<ClCompile Include="..\..\src\fann_io.c" />
<ClCompile Include="..\..\src\fann_train.c" />
<ClCompile Include="..\..\src\fann_train_data.c" />
<ClCompile Include="..\..\src\parallel_fann.c" />
<ClCompile Include="..\..\src\parallel_fann_cpp.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\src\include\compat_time.h" />
Expand All @@ -102,6 +108,8 @@
<ClInclude Include="..\..\src\include\fann_internal.h" />
<ClInclude Include="..\..\src\include\fann_io.h" />
<ClInclude Include="..\..\src\include\fann_train.h" />
<ClInclude Include="..\..\src\include\parallel_fann.h" />
<ClInclude Include="..\..\src\include\parallel_fann.hpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
Expand Down
12 changes: 12 additions & 0 deletions VS2010/fanndouble/fanndouble.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@
<ClCompile Include="..\..\src\fann_train_data.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\src\parallel_fann.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\src\parallel_fann_cpp.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\src\include\compat_time.h">
Expand Down Expand Up @@ -64,5 +70,11 @@
<ClInclude Include="..\..\src\include\fann_train.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\src\include\parallel_fann.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\src\include\parallel_fann.hpp">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>
9 changes: 8 additions & 1 deletion VS2010/fannfloat/fannfloat.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;_USRDLL;FANN_DLL_EXPORTS;WIN32;_WINDOWS;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\..\src\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<CompileAs>CompileAsCpp</CompileAs>
<OpenMPSupport>true</OpenMPSupport>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
Expand Down Expand Up @@ -121,6 +123,8 @@
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;_USRDLL;FANN_DLL_EXPORTS;WIN32;_WINDOWS;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\..\src\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<CompileAs>CompileAsCpp</CompileAs>
<OpenMPSupport>true</OpenMPSupport>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
Expand Down Expand Up @@ -154,9 +158,10 @@
<ClCompile Include="..\..\src\fann_io.c" />
<ClCompile Include="..\..\src\fann_train.c" />
<ClCompile Include="..\..\src\fann_train_data.c" />
<ClCompile Include="..\..\src\parallel_fann.c" />
<ClCompile Include="..\..\src\parallel_fann_cpp.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\src\include\compat_time.h" />
<ClInclude Include="..\..\src\include\config.h" />
<ClInclude Include="..\..\src\include\fann.h" />
<ClInclude Include="..\..\src\include\fann_activation.h" />
Expand All @@ -167,6 +172,8 @@
<ClInclude Include="..\..\src\include\fann_internal.h" />
<ClInclude Include="..\..\src\include\fann_io.h" />
<ClInclude Include="..\..\src\include\fann_train.h" />
<ClInclude Include="..\..\src\include\parallel_fann.h" />
<ClInclude Include="..\..\src\include\parallel_fann.hpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
Expand Down
15 changes: 12 additions & 3 deletions VS2010/fannfloat/fannfloat.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,14 @@
<ClCompile Include="..\..\src\fann_train_data.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\src\parallel_fann.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\src\parallel_fann_cpp.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\src\include\compat_time.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\src\include\config.h">
<Filter>Header Files</Filter>
</ClInclude>
Expand Down Expand Up @@ -64,5 +67,11 @@
<ClInclude Include="..\..\src\include\fann_train.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\src\include\parallel_fann.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\src\include\parallel_fann.hpp">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>
97 changes: 97 additions & 0 deletions VS2010/parallel_train/parallel_train.vcxproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{2C326817-564B-40ED-BB25-BC10B1AB505F}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>simple_train</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<OutDir>$(SolutionDir)..\bin\</OutDir>
<TargetName>$(ProjectName)d</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
<OutDir>$(SolutionDir)..\bin\</OutDir>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\..\src\include</AdditionalIncludeDirectories>
<ForcedIncludeFiles>..\..\src\include\doublefann.h</ForcedIncludeFiles>
<CompileAs>CompileAsCpp</CompileAs>
<OpenMPSupport>true</OpenMPSupport>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\..\src\include</AdditionalIncludeDirectories>
<CompileAs>CompileAsCpp</CompileAs>
<OpenMPSupport>true</OpenMPSupport>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ProjectReference Include="..\fanndouble\fanndouble.vcxproj">
<Project>{7ffd0423-9ee1-4cb9-aaf0-6fc5f82535ff}</Project>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\examples\parallel_train.c" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
6 changes: 6 additions & 0 deletions VS2010/parallel_train/parallel_train.vcxproj.filters
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<ClCompile Include="..\..\examples\parallel_train.c" />
</ItemGroup>
</Project>
Binary file modified bin/fanndouble.dll
Binary file not shown.
Binary file modified bin/fanndouble.lib
Binary file not shown.
Binary file modified bin/fannfixed.dll
Binary file not shown.
Binary file modified bin/fannfixed.lib
Binary file not shown.
Binary file modified bin/fannfloat.dll
Binary file not shown.
Binary file modified bin/fannfloat.lib
Binary file not shown.
Binary file modified bin/simple_train_double.exe
Binary file not shown.
Binary file modified bin/simple_train_float.exe
Binary file not shown.
Binary file modified bin/xor_test_fixed.exe
Binary file not shown.
Binary file modified bin/xor_test_float.exe
Binary file not shown.
Binary file modified bin/xor_train.exe
Binary file not shown.
4 changes: 2 additions & 2 deletions examples/mushroom.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ int main()

printf("Training network.\n");

fann_set_activation_function_hidden(ann, FANN_SIGMOID_SYMMETRIC_STEPWISE);
fann_set_activation_function_output(ann, FANN_SIGMOID_STEPWISE);
fann_set_activation_function_hidden(ann, FANN_SIGMOID_SYMMETRIC);
fann_set_activation_function_output(ann, FANN_SIGMOID);

/*fann_set_training_algorithm(ann, FANN_TRAIN_INCREMENTAL); */

Expand Down
48 changes: 48 additions & 0 deletions examples/parallel_train.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
Fast Artificial Neural Network Library (fann)
Copyright (C) 2003-2012 Steffen Nissen ([email protected])
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/

#include "fann.h"
#include "parallel_fann.h"

int main(int argc, const char* argv[])
{
const unsigned int max_epochs = 1000;
unsigned int num_threads = 1;
if(argc == 2)
num_threads = atoi(argv[1]);

struct fann_train_data *data = fann_read_train_from_file("../datasets/mushroom.train");
struct fann *ann = fann_create_standard(3, fann_num_input_train_data(data), 32, fann_num_output_train_data(data));

fann_set_activation_function_hidden(ann, FANN_SIGMOID_SYMMETRIC);
fann_set_activation_function_output(ann, FANN_SIGMOID);

long before = GetTickCount();
for(int i = 1; i <= max_epochs; i++)
{
float error = num_threads > 1 ? fann_train_epoch_irpropm_parallel(ann, data, num_threads) : fann_train_epoch(ann, data);
printf("Epochs %8d. Current error: %.10f\n", i, error);
}
printf("ticks %d", GetTickCount()-before);

fann_destroy(ann);
fann_destroy_train(data);

return 0;
}
25 changes: 25 additions & 0 deletions src/include/parallel_fann.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* parallel_FANN.h
*
* Author: Alessandro Pietro Bardelli
*/
#ifndef DISABLE_PARALLEL_FANN
#ifndef PARALLEL_FANN_H_
#define PARALLEL_FANN_H_

#include <fann.h>

FANN_EXTERNAL float FANN_API fann_train_epoch_batch_parallel(struct fann *ann, struct fann_train_data *data, const unsigned int threadnumb);

FANN_EXTERNAL float FANN_API fann_train_epoch_irpropm_parallel(struct fann *ann, struct fann_train_data *data, const unsigned int threadnumb);

FANN_EXTERNAL float FANN_API fann_train_epoch_quickprop_parallel(struct fann *ann, struct fann_train_data *data, const unsigned int threadnumb);

FANN_EXTERNAL float FANN_API fann_train_epoch_sarprop_parallel(struct fann *ann, struct fann_train_data *data, const unsigned int threadnumb);

FANN_EXTERNAL float FANN_API fann_train_epoch_incremental_mod(struct fann *ann, struct fann_train_data *data);

FANN_EXTERNAL float FANN_API fann_test_data_parallel(struct fann *ann, struct fann_train_data *data, const unsigned int threadnumb);

#endif /* PARALLEL_FANN_H_ */
#endif /* DISABLE_PARALLEL_FANN */
37 changes: 37 additions & 0 deletions src/include/parallel_fann.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* parallel_FANN.hpp
* Author: Alessandro Pietro Bardelli
*/
#ifndef DISABLE_PARALLEL_FANN
#ifndef PARALLEL_FANN_HPP_
#define PARALLEL_FANN_HPP_
#include <omp.h>
#include <vector>
#include <fann.h>

namespace parallel_fann {
float train_epoch_batch_parallel(struct fann *ann, struct fann_train_data *data, const unsigned int threadnumb);

float train_epoch_irpropm_parallel(struct fann *ann, struct fann_train_data *data, const unsigned int threadnumb);

float train_epoch_quickprop_parallel(struct fann *ann, struct fann_train_data *data, const unsigned int threadnumb);

float train_epoch_sarprop_parallel(struct fann *ann, struct fann_train_data *data, const unsigned int threadnumb);

float train_epoch_incremental_mod(struct fann *ann, struct fann_train_data *data);

float train_epoch_batch_parallel(struct fann *ann, struct fann_train_data *data, const unsigned int threadnumb,std::vector< std::vector<fann_type> >& predicted_outputs);

float train_epoch_irpropm_parallel(struct fann *ann, struct fann_train_data *data, const unsigned int threadnumb, std::vector< std::vector<fann_type> >& predicted_outputs);

float train_epoch_quickprop_parallel(struct fann *ann, struct fann_train_data *data, const unsigned int threadnumb, std::vector< std::vector<fann_type> >& predicted_outputs);

float train_epoch_sarprop_parallel(struct fann *ann, struct fann_train_data *data, const unsigned int threadnumb, std::vector< std::vector<fann_type> >& predicted_outputs);

float train_epoch_incremental_mod(struct fann *ann, struct fann_train_data *data, std::vector< std::vector<fann_type> >& predicted_outputs);

float test_data_parallel(struct fann *ann, struct fann_train_data *data, const unsigned int threadnumb);
float test_data_parallel(struct fann *ann, struct fann_train_data *data, const unsigned int threadnumb, std::vector< std::vector<fann_type> >& predicted_outputs);
}
#endif /* PARALLEL_FANN_HPP_ */
#endif /* DISABLE_PARALLEL_FANN */
Loading

0 comments on commit 3d07691

Please sign in to comment.