Debian Codegraph @

src/thirdparty/PoissonRecon/PoissonReconClient.cpp

raw
1 /*
2 Copyright (c) 2023, Michael Kazhdan
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without modification,
6 are permitted provided that the following conditions are met:
7
8 Redistributions of source code must retain the above copyright notice, this list of
9 conditions and the following disclaimer. Redistributions in binary form must reproduce
10 the above copyright notice, this list of conditions and the following disclaimer
11 in the documentation and/or other materials provided with the distribution.
12
13 Neither the name of the Johns Hopkins University nor the names of its contributors
14 may be used to endorse or promote products derived from this software without specific
15 prior written permission.
16
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
18 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO THE IMPLIED WARRANTIES
19 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
20 SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
21 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
22 TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23 BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
25 ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
26 DAMAGE.
27 */
28
29 #define BIG_DATA
30 #include "PreProcessor.h"
31
32 #include "Socket.h"
33 #include "PoissonReconClientServer.h"
34 #include "PointPartitionClientServer.h"
35 #include "MergePlyClientServer.h"
36
37 #include <stdio.h>
38 #include <stdlib.h>
39 #include <algorithm>
40 #include "MyMiscellany.h"
41 #include "Reconstructors.h"
42 #include "CmdLineParser.h"
43
44 #define DEFAULT_DIMENSION 3
45
46 using namespace PoissonRecon;
47
48 CmdLineParameter< std::string >
49 Address( "address" , "127.0.0.1" );
50
51 CmdLineParameter< int >
52 MaxMemoryGB( "maxMemory" , 0 ) ,
53 ParallelType( "parallel" , 0 ) ,
54 ScheduleType( "schedule" , (int)ThreadPool::Schedule ) ,
55 ThreadChunkSize( "chunkSize" , (int)ThreadPool::ChunkSize ) ,
56 MultiClient( "multi" , 1 ) ,
57 Port( "port" , 0 ) ,
58 PeakMemorySampleMS( "sampleMS" , 10 );
59
60 CmdLineReadable
61 Pause( "pause" );
62
63
64 CmdLineReadable* params[] =
65 {
66 &Port , &MultiClient , &Address ,
67 &MaxMemoryGB , &ParallelType , &ScheduleType , &ThreadChunkSize ,
68 &Pause ,
69 &PeakMemorySampleMS ,
70 NULL
71 };
72
73 void ShowUsage( char* ex )
74 {
75 printf( "Usage: %s\n" , ex );
76 printf( "\t --%s <server port>\n" , Port.name );
77 printf( "\t[--%s <multiplicity of serial sub-clients>=%d]\n" , MultiClient.name , MultiClient.value );
78 printf( "\t[--%s <server connection address>=%s]\n" , Address.name , Address.value.c_str() );
79 printf( "\t[--%s <parallel type>=%d]\n" , ParallelType.name , ParallelType.value );
80 for( size_t i=0 ; i<ThreadPool::ParallelNames.size() ; i++ ) printf( "\t\t%d] %s\n" , (int)i , ThreadPool::ParallelNames[i].c_str() );
81 printf( "\t[--%s <schedue type>=%d]\n" , ScheduleType.name , ScheduleType.value );
82 for( size_t i=0 ; i<ThreadPool::ScheduleNames.size() ; i++ ) printf( "\t\t%d] %s\n" , (int)i , ThreadPool::ScheduleNames[i].c_str() );
83 printf( "\t[--%s <thread chunk size>=%d]\n" , ThreadChunkSize.name , ThreadChunkSize.value );
84 printf( "\t[--%s <peak memory sampling rate (ms)>=%d]\n" , PeakMemorySampleMS.name , PeakMemorySampleMS.value );
85 printf( "\t[--%s <maximum memory (in GB)>=%d]\n" , MaxMemoryGB.name , MaxMemoryGB.value );
86 printf( "\t[--%s]\n" , Pause.name );
87 }
88
89 template< typename Real , unsigned int Dim >
90 void Partition( std::vector< Socket > &serverSockets )
91 {
92 PointPartitionClientServer::RunClients< Real , Dim >( serverSockets );
93 unsigned int peakMem = MemoryInfo::PeakMemoryUsageMB();
94 for( unsigned int i=0 ; i<serverSockets.size() ; i++ ) SocketStream( serverSockets[i] ).write( peakMem );
95 }
96
97 template< typename Real , unsigned int Dim , BoundaryType BType , unsigned int Degree >
98 void Reconstruct( std::vector< Socket > &serverSockets )
99 {
100 PoissonReconClientServer::RunClient< Real , Dim , BType , Degree >( serverSockets , PeakMemorySampleMS.value );
101 unsigned int peakMem = MemoryInfo::PeakMemoryUsageMB();
102 for( unsigned int i=0 ; i<serverSockets.size() ; i++ ) SocketStream( serverSockets[i] ).write( peakMem );
103 }
104
105 template< typename Real , unsigned int Dim >
106 void Merge( std::vector< Socket > &serverSockets )
107 {
108 MergePlyClientServer::RunClients< Real , Dim >( serverSockets , PeakMemorySampleMS.value );
109 unsigned int peakMem = MemoryInfo::PeakMemoryUsageMB();
110 for( unsigned int i=0 ; i<serverSockets.size() ; i++ ) SocketStream( serverSockets[i] ).write( peakMem );
111 }
112
113 #ifdef FAST_COMPILE
114 #else // !FAST_COMPILE
115 template< typename Real , unsigned int Dim , BoundaryType BType >
116 void Reconstruct( unsigned int degree , std::vector< Socket > &serverSockets )
117 {
118 switch( degree )
119 {
120 case 1: return Reconstruct< Real , Dim , BType , 1 >( serverSockets );
121 case 2: return Reconstruct< Real , Dim , BType , 2 >( serverSockets );
122 default: MK_THROW( "Only B-Splines of degree 1 - 2 are supported" );
123 }
124 }
125
126 template< typename Real , unsigned int Dim >
127 void Reconstruct( BoundaryType bType , unsigned int degree , std::vector< Socket > &serverSockets )
128 {
129 switch( bType )
130 {
131 case BOUNDARY_FREE: return Reconstruct< Real , Dim , BOUNDARY_FREE >( degree , serverSockets );
132 case BOUNDARY_NEUMANN: return Reconstruct< Real , Dim , BOUNDARY_NEUMANN >( degree , serverSockets );
133 case BOUNDARY_DIRICHLET: return Reconstruct< Real , Dim , BOUNDARY_DIRICHLET >( degree , serverSockets );
134 default: MK_THROW( "Not a valid boundary type: " , bType );
135 }
136 }
137
138 template< typename Real , unsigned int Dim >
139 void Reconstruct( std::vector< Socket > &serverSockets )
140 {
141 BoundaryType bType;
142 unsigned int degree;
143 for( unsigned int i=0 ; i<serverSockets.size() ; i++ )
144 {
145 if( !SocketStream( serverSockets[i] ).read( bType ) ) MK_THROW( "Failed to read boundary-type" );
146 if( !SocketStream( serverSockets[i] ).read( degree ) ) MK_THROW( "Failed to read degree" );
147 }
148 Reconstruct< Real , Dim >( bType , degree , serverSockets );
149 }
150
151 #endif // FAST_COMPILE
152
153 int main( int argc , char* argv[] )
154 {
155 #ifdef ARRAY_DEBUG
156 MK_WARN( "Array debugging enabled" );
157 #endif // ARRAY_DEBUG
158 #ifdef USE_DOUBLE
159 typedef double Real;
160 #else // !USE_DOUBLE
161 typedef float Real;
162 #endif // USE_DOUBLE
163 static const unsigned int Dim = DEFAULT_DIMENSION;
164
165 Timer timer;
166 CmdLineParse( argc-1 , &argv[1] , params );
167
168 if( !Port.set )
169 {
170 ShowUsage( argv[0] );
171 return 0;
172 }
173
174 if( MaxMemoryGB.value>0 ) SetPeakMemoryMB( MaxMemoryGB.value<<10 );
175 ThreadPool::ChunkSize = ThreadChunkSize.value;
176 ThreadPool::Schedule = (ThreadPool::ScheduleType)ScheduleType.value;
177 ThreadPool::ParallelizationType= (ThreadPool::ParallelType)ParallelType.value;
178
179 std::vector< Socket > serverSockets( MultiClient.value , NULL );
180 for( unsigned int i=0 ; i<(unsigned int)MultiClient.value ; i++ ) serverSockets[i] = GetConnectSocket( Address.value.c_str() , Port.value , SOCKET_CONNECT_WAIT , false );
181
182 {
183 Partition< Real , Dim >( serverSockets );
184
185 #ifdef FAST_COMPILE
186 Reconstruct< Real , Dim , Reconstructor::Poisson::DefaultFEMBoundary , Reconstructor::Poisson::DefaultFEMDegree >( serverSockets );
187 #else // !FAST_COMPILE
188 Reconstruct< Real , Dim >( serverSockets );
189 #endif // FAST_COMPILE
190
191 if constexpr( Dim==3 ) Merge< Real , Dim >( serverSockets );
192
193 for( unsigned int i=0 ; i<serverSockets.size() ; i++ ) CloseSocket( serverSockets[i] );
194 }
195
196 if( Pause.set )
197 {
198 std::cout << "Hit [ENTER] to terminate" << std::endl;
199 std::string foo;
200 std::getline( std::cin , foo );
201 }
202
203 return EXIT_SUCCESS;
204 }