Skip to content

Commit 993c76c

Browse files
committed
shuffle example Makefile added. Also, added an option to indicate if managed_dir is local
1 parent 7c49d7c commit 993c76c

File tree

2 files changed

+66
-6
lines changed

2 files changed

+66
-6
lines changed

use_cases/shuffle/Makefile

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
ifeq ($(DYAD_SRC_DIR),)
2+
DYAD_SRC_DIR = ../../src
3+
endif
4+
5+
DYAD_OPTIONS += -g -O3 -Wall -fPIC -Wno-stringop-truncation -Wno-stringop-overflow
6+
7+
ifeq ($(MPICXX),)
8+
MPICXX = mpicxx
9+
endif
10+
11+
C_VER=-std=c11
12+
CXX_VER=-std=c++11
13+
CXX11_ABI=-D_GLIBCXX_USE_CXX11_ABI=0
14+
15+
CFLAGS += -D_POSIX_C_SOURCE=200112L $(DYAD_OPTIONS) \
16+
-I./ -I$(DYAD_SRC_DIR)/common -I$(DYAD_SRC_DIR)/modules
17+
CXXFLAGS += -D_POSIX_C_SOURCE=200112L $(DYAD_OPTIONS) \
18+
-I./ -I$(DYAD_SRC_DIR)/common -I$(DYAD_SRC_DIR)/modules \
19+
$(CXX_VER) $(CXX11_ABI)
20+
LDFLAGS =
21+
HEADERS = $(DYAD_SRC_DIR)/modules/read_all.h \
22+
$(DYAD_SRC_DIR)/common/dyad.h \
23+
$(DYAD_SRC_DIR)/common/utils.h
24+
OBJS = worker.o read_all.o utils.o
25+
26+
all: shuffle utils.o read_all.o worker.o
27+
28+
shuffle: shuffle.cpp $(OBJS) $(HEADERS)
29+
$(MPICXX) $(CXXFLAGS) $< $(OBJS) -o $@ $(LDFLAGS)
30+
31+
utils.o: $(DYAD_SRC_DIR)/common/utils.c $(DYAD_SRC_DIR)/common/utils.h $(DYAD_SRC_DIR)/common/dyad.h
32+
$(CC) $(CFLAGS) $< -c
33+
34+
read_all.o: $(DYAD_SRC_DIR)/modules/read_all.c $(DYAD_SRC_DIR)/modules/read_all.h
35+
$(CC) $(CFLAGS) $< -c
36+
37+
worker.o: worker.cpp worker.hpp
38+
$(CXX) $(CXXFLAGS) $< -c
39+
40+
41+
.PHONY: clean
42+
43+
clean:
44+
@rm -f *.o *.so *breakpoint* *.core
45+
@rm -f shuffle

use_cases/shuffle/shuffle.cpp

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,28 +115,33 @@ int main (int argc, char** argv)
115115
{
116116
int rank;
117117
int n_ranks;
118+
bool is_managed_local = false;
118119
unsigned seed = 0u;
119120
unsigned n_epochs = 3u;
120121
int rc = 0;
121122
std::string list_name;
122123
std::string managed_dir;
123124

124-
if ((argc != 3) && (argc != 4) && (argc != 5)) {
125-
cout << "usage: " << argv[0] << " list_file managed_dir [n_epochs [seed]]"
125+
if ((argc < 4) || (argc > 6)) {
126+
cout << "usage: " << argv[0] << " list_file managed_dir is_local [n_epochs [seed]]"
126127
<< endl;
127-
cout << " if seed is not given, a random seed is used" << endl;
128+
cout << " list_file: constains a list of files to be generated and used," << endl
129+
<< " one per line, without managed_dir prefix." << endl;
130+
cout << " is_local: indicates if the managed_dir is local (1) or shared (0)" << endl;
131+
cout << " seed: if not given, a random seed is used" << endl;
128132
return EXIT_SUCCESS;
129133
}
130134

131135
list_name = argv[1];
132136
managed_dir = argv[2];
137+
is_managed_local = static_cast<bool> (atoi (argv[3]));
133138

134139
if (argc == 4) {
135-
n_epochs = static_cast<unsigned> (atoi (argv[3]));
140+
n_epochs = static_cast<unsigned> (atoi (argv[4]));
136141
}
137142

138143
if (argc == 5) {
139-
seed = static_cast<unsigned> (atoi (argv[4]));
144+
seed = static_cast<unsigned> (atoi (argv[5]));
140145
}
141146

142147
std::vector<std::string> flist;
@@ -155,7 +160,17 @@ int main (int argc, char** argv)
155160
return rc;
156161
}
157162

158-
if (rank == 0) { // if directory is local, everyone should do
163+
if (is_managed_local) { // if directory is local, everyone should create
164+
mode_t m = (S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH | S_ISGID);
165+
int c = mkdir_as_needed (managed_dir.c_str (), m);
166+
if (c < 0) {
167+
cout << "Rank " << rank
168+
<< " could not create directory: '" << managed_dir << "'" << endl;
169+
MPI_Abort (MPI_COMM_WORLD, errno);
170+
return EXIT_FAILURE;
171+
}
172+
}
173+
else if (rank == 0) {
159174
mode_t m = (S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH | S_ISGID);
160175
int c = mkdir_as_needed (managed_dir.c_str (), m);
161176
if (c < 0) {

0 commit comments

Comments
 (0)