Skip to content

Commit ac434bc

Browse files
committed
fix(mpi): build & test
1 parent de803fa commit ac434bc

7 files changed

Lines changed: 68 additions & 50 deletions

File tree

CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,17 @@ include("dep/cmake_fetchcontent/mddglu.cmake")
3333
include(ExternalProject)
3434
include("dep/cmake_externalproject/peg.cmake")
3535

36+
find_library (M_LIB m)
37+
find_package(MPI)
38+
find_package(OpenMP)
39+
3640
#### Build ####
3741
include_directories(
3842
"${PROJECT_SOURCE_DIR}"
3943
${Fildesh_INCLUDE_DIRS}
4044
)
4145
add_subdirectory(src)
46+
set(Protocon_EXECUTABLE "$<TARGET_FILE:protocon>")
4247

4348
#### Test ####
4449
# (The src/ subdirectory has some tests too.)

src/CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11

2-
find_library (M_LIB m)
3-
find_package(MPI)
4-
find_package(OpenMP)
5-
62
add_definitions(-DPROTOCON_NAMESPACE=protocon)
73

84
add_subdirectory(inline)

src/main-mpi.cc

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
#include <errno.h>
2+
#include <signal.h>
13

24
#include <mpi.h>
3-
#include "main-all.hh"
5+
#include <fildesh/string.hh>
46

5-
#include <errno.h>
7+
#include "main-all.hh"
68
#include "mpidissem.hh"
79

810
#include "namespace.hh"
@@ -50,7 +52,7 @@ handle_dissem_msg(MpiDissem::Tag tag,
5052
}
5153

5254
static
53-
Bool
55+
bool
5456
done_ck (void* dat)
5557
{
5658
Table<uint> msg;
@@ -85,12 +87,10 @@ stabilization_search_init
8587
(SynthesisCtx& synctx,
8688
Xn::Sys& sys,
8789
LgTable<Xn::Sys>& systems,
88-
lace::ofstream& log_ofile,
8990
AddConvergenceOpt& opt,
9091
const ProtoconFileOpt& infile_opt,
9192
const ProtoconOpt& exec_opt,
92-
Table< Table<uint> >& act_layers
93-
);
93+
Table< Table<uint> >& act_layers);
9494

9595
static
9696
int
@@ -120,7 +120,6 @@ stabilization_search(vector<uint>& ret_actions,
120120

121121
DeclLegit( good );
122122
AddConvergenceOpt opt(global_opt);
123-
lace::ofstream log_ofile;
124123

125124
opt.sys_pcidx = PcIdx;
126125
opt.sys_npcs = NPcs;
@@ -129,12 +128,13 @@ stabilization_search(vector<uint>& ret_actions,
129128
LgTable<Xn::Sys> systems;
130129
SynthesisCtx synctx( PcIdx, NPcs );
131130
synctx.conflicts = conflicts;
131+
std::ostream& log_out = synctx.log;
132132

133133
Table< Table<uint> > act_layers;
134134

135135
DoLegitLine( "Could not initialize." )
136136
stabilization_search_init
137-
(synctx, sys, systems, log_ofile, opt, infile_opt, exec_opt, act_layers);
137+
(synctx, sys, systems, opt, infile_opt, exec_opt, act_layers);
138138

139139
PartialSynthesis& synlvl = synctx.base_partial;
140140
synctx.done_ck_fn = done_ck;
@@ -147,7 +147,7 @@ stabilization_search(vector<uint>& ret_actions,
147147

148148
if (exec_opt.task == ProtoconOpt::VerifyTask)
149149
{
150-
for (uint i = PcIdx; i < exec_opt.xfilepaths.sz(); i += NPcs) {
150+
for (uint i = PcIdx; i < exec_opt.xfilepaths.size(); i += NPcs) {
151151
if (synctx.done_ck()) break;
152152
multi_verify_stabilization
153153
(i, synctx, ret_actions,
@@ -160,7 +160,7 @@ stabilization_search(vector<uint>& ret_actions,
160160
for (uint conflict_idx = PcIdx; conflict_idx < flat_conflicts.sz(); conflict_idx += NPcs) {
161161
uint old_sz = flat_conflicts[conflict_idx].sz();
162162
if (!synctx.done_ck() && old_sz > 1) {
163-
*opt.log
163+
log_out
164164
<< "pcidx:" << PcIdx
165165
<< " conflict:" << conflict_idx << "/" << flat_conflicts.sz()
166166
<< " sz:" << old_sz
@@ -169,7 +169,7 @@ stabilization_search(vector<uint>& ret_actions,
169169
uint new_sz =
170170
synlvl.add_small_conflict_set(flat_conflicts[conflict_idx]);
171171

172-
*opt.log
172+
log_out
173173
<< "DONE: pcidx:" << PcIdx
174174
<< " conflict:" << conflict_idx << "/" << flat_conflicts.sz()
175175
<< " old_sz:" << old_sz << " new_sz:" << new_sz
@@ -222,7 +222,7 @@ stabilization_search(vector<uint>& ret_actions,
222222
{}
223223
else if (found)
224224
{
225-
*opt.log << "SOLUTION FOUND!" << std::endl;
225+
log_out << "SOLUTION FOUND!" << std::endl;
226226
bool count_solution = true;
227227
if (opt.solution_as_conflict || global_opt.optimize_soln) {
228228
FlatSet<uint> flat_actions( actions );
@@ -234,10 +234,12 @@ stabilization_search(vector<uint>& ret_actions,
234234
}
235235
}
236236

237-
if (global_opt.try_all && !!exec_opt.ofilepath && count_solution) {
238-
lace::ofstream prot_out((exec_opt.ofilepath + "." + PcIdx + "." + trial_idx).c_str());
237+
if (global_opt.try_all && !exec_opt.ofilepath.empty() && count_solution) {
238+
fildesh::ostringstream oss;
239+
oss << exec_opt.ofilepath << "." << PcIdx << "." << trial_idx;
240+
fildesh::ofstream prot_out(oss.c_str());
239241
oput_protocon_file(prot_out, sys, actions,
240-
exec_opt.use_espresso,
242+
exec_opt.maybe_espresso,
241243
exec_opt.argline.c_str());
242244
}
243245

@@ -257,11 +259,11 @@ stabilization_search(vector<uint>& ret_actions,
257259
set_term_flag (1);
258260
}
259261

260-
synctx.conflicts.oput_conflict_sizes(*opt.log);
262+
synctx.conflicts.oput_conflict_sizes(log_out);
261263

262264
for (std::ostream* ofile = &std::cerr;
263265
true; // See end of loop.
264-
ofile = opt.log)
266+
ofile = &log_out)
265267
{
266268
*ofile << "pcidx:" << PcIdx << " trial:" << trial_idx+1;
267269

@@ -276,7 +278,7 @@ stabilization_search(vector<uint>& ret_actions,
276278
*ofile << '\n';
277279
ofile->flush();
278280

279-
if (ofile == opt.log)
281+
if (ofile == &log_out)
280282
break;
281283
}
282284

@@ -298,10 +300,10 @@ stabilization_search(vector<uint>& ret_actions,
298300

299301
mpi_dissem->finish();
300302

301-
if (!!exec_opt.conflicts_ofilepath) {
303+
if (!exec_opt.conflicts_ofilepath.empty()) {
302304
Table<uint> flattest_conflicts;
303-
synctx.conflicts.oput_conflict_sizes(*opt.log);
304-
opt.log->flush();
305+
synctx.conflicts.oput_conflict_sizes(log_out);
306+
log_out.flush();
305307
if (PcIdx == 0) {
306308
synctx.conflicts.flush_new_conflicts();
307309
for (uint source_idx = 1; source_idx < NPcs; ++source_idx) {
@@ -314,12 +316,13 @@ stabilization_search(vector<uint>& ret_actions,
314316
src_and_sz[0], MpiTag_Conflict, MPI_COMM_WORLD, &status);
315317
synctx.conflicts.add_conflicts(flattest_conflicts);
316318
synctx.conflicts.flush_new_conflicts();
317-
synctx.conflicts.oput_conflict_sizes(*opt.log);
318-
opt.log->flush();
319+
synctx.conflicts.oput_conflict_sizes(log_out);
320+
log_out.flush();
319321
}
320322

321323
synctx.conflicts.trim(global_opt.max_conflict_sz);
322-
oput_conflicts(synctx.conflicts, exec_opt.conflicts_ofilepath);
324+
fildesh::ofstream conflict_out(exec_opt.conflicts_ofilepath.c_str());
325+
conflict_out << synctx.conflicts;
323326
}
324327
else {
325328
synctx.conflicts.flush_new_conflicts(flattest_conflicts);
@@ -369,7 +372,6 @@ int main(int argc, char** argv)
369372
int argi = 1;
370373
DeclLegit( good );
371374
struct timespec begtime, endtime;
372-
push_losefn_sysCx ((void (*) ()) MPI_Finalize);
373375
uint PcIdx = 0;
374376
uint NPcs = 1;
375377
MPI_Comm_rank (MPI_COMM_WORLD, (int*) &PcIdx);
@@ -393,10 +395,10 @@ int main(int argc, char** argv)
393395
stabilization_search(sys.actions, infile_opt, exec_opt, opt, PcIdx, NPcs);
394396
if (found_papc == (int)PcIdx) {
395397
DBog1("Solution found! (By PcIdx %u)", PcIdx);
396-
if (!exec_opt.ofilepath.empty_ck())
398+
if (!exec_opt.ofilepath.empty())
397399
{
398400
oput_protocon_file (exec_opt.ofilepath, sys,
399-
exec_opt.use_espresso,
401+
exec_opt.maybe_espresso,
400402
exec_opt.argline.c_str());
401403
}
402404
else {
@@ -434,7 +436,7 @@ END_NAMESPACE
434436

435437
int main(int argc, char** argv)
436438
{
437-
MPI_Init (&argc, &argv);
438-
return PROTOCON_NAMESPACE::main(argc, argv);
439+
MPI_Init(&argc, &argv);
440+
int exstatus = PROTOCON_NAMESPACE::main(argc, argv);
441+
MPI_Finalize();
439442
}
440-

src/mpidissem.hh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
namespace Cx {
1010
class MpiDissem
1111
{
12+
public:
13+
typedef unsigned char Bool;
1214
private:
1315
bool done;
1416
bool term;

src/verif/include.cmake

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -85,20 +85,6 @@ foreach (f SortRing TokenRingDijkstra)
8585
COMMAND protocon -x ${SpecPath}/${f}.prot)
8686
endforeach ()
8787

88-
foreach (f LeaderRingHuang)
89-
list (APPEND ExampleSpecs ${f})
90-
add_test (NAME SynthOpenMP_${f}
91-
COMMAND protocon -parallel 4 -x ${SpecPath}/${f}.prot -prep-conflicts)
92-
set_tests_properties (SynthOpenMP_${f} PROPERTIES PROCESSORS 4)
93-
94-
if (MPI_FOUND)
95-
add_test (NAME SynthMPI_${f}
96-
COMMAND ${MPIEXEC} ${MPIEXEC_NUMPROC_FLAG} 4 ${MPIEXEC_PREFLAGS}
97-
"$<TARGET_FILE:protocon-mpi>" ${MPIEXEC_POSTFLAGS} -x ${SpecPath}/${f}.prot -prep-conflicts)
98-
set_tests_properties (SynthMPI_${f} PROPERTIES PROCESSORS 4)
99-
endif ()
100-
endforeach ()
101-
10288
add_test (NAME Synth_Sat_sat
10389
COMMAND protocon -def ExpectSat 1 -x ${SpecPath}/Sat.prot)
10490
add_test (NAME Synth_Sat_unsat
@@ -108,6 +94,7 @@ set_tests_properties (Synth_Sat_unsat PROPERTIES WILL_FAIL TRUE)
10894
list (APPEND ExampleSolns
10995
${ExampleSpecs}
11096
DiningPhilo
97+
LeaderRingHuang
11198
OrientRing
11299
OrientRingViaToken
113100
TokenChainDijkstra

test/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
1+
add_subdirectory(examplespec)
22
add_subdirectory(examplesoln)
33
add_subdirectory(src)
4-

test/examplespec/CMakeLists.txt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
if (MPI_FOUND)
2+
set(host_process_count 4)
3+
if (${MPIEXEC_MAX_NUMPROCS} LESS ${host_process_count})
4+
set(host_process_count ${MPIEXEC_MAX_NUMPROCS})
5+
endif()
6+
add_test(NAME MPI_LeaderRingHuang_test COMMAND ${MPIEXEC}
7+
${MPIEXEC_NUMPROC_FLAG} ${host_process_count}
8+
# --use-hwthread-cpus
9+
${MPIEXEC_PREFLAGS}
10+
"$<TARGET_FILE:protocon-mpi>"
11+
${MPIEXEC_POSTFLAGS}
12+
-x "${PROJECT_SOURCE_DIR}/examplespec/LeaderRingHuang.prot"
13+
-prep-conflicts
14+
)
15+
set_tests_properties(MPI_LeaderRingHuang_test PROPERTIES
16+
PROCESSORS ${host_process_count}
17+
)
18+
endif()
19+
20+
if (OPENMP_FOUND)
21+
add_test(NAME OpenMP_LeaderRingHuang_test COMMAND ${Protocon_EXECUTABLE}
22+
-parallel 4
23+
-x "${PROJECT_SOURCE_DIR}/examplespec/LeaderRingHuang.prot"
24+
-prep-conflicts
25+
)
26+
set_tests_properties(OpenMP_LeaderRingHuang_test PROPERTIES PROCESSORS 4)
27+
endif()

0 commit comments

Comments
 (0)