696310614dd443ff9bd32adfc6e25acb95d73e90
[charm.git] / tests / ampi / privatization / Makefile
1 -include ../../common.mk
2 AMPICC=../../../bin/ampicxx $(OPTS)
3 AMPIF90=../../../bin/ampif90 $(OPTS)
4
5
6 LANGUAGES := \
7   cxx \
8   f90 \
9
10
11 # for constructing individual build rules
12 VARIANTS := \
13   control \
14   swapglobals \
15   tlsglobals \
16   roseomptlsglobals \
17
18
19 # for determining `all`, `test` rules
20 CANDIDATES := \
21   swapglobals \
22   tlsglobals \
23
24
25 # Define what options to pass to charmc for each method.
26 $(foreach i,$(VARIANTS),$(foreach j,$(LANGUAGES),$(eval OPTS_$j_$i := -$i)))
27 OPTS_cxx_control :=
28 OPTS_f90_control :=
29 OPTS_f90_tlsglobals += -fopenmp
30
31 # Define the features that each privatization method supports.
32 FEATURES_cxx_control := staticvars sharedlib dynamiclib
33 FEATURES_cxx_swapglobals :=
34 FEATURES_cxx_tlsglobals := staticvars sharedlib
35 FEATURES_cxx_roseomptlsglobals := staticvars sharedlib
36
37
38 # Determine which methods to test in the current environment and target.
39 TARGETS :=
40
41 define TEST_TARGET_AVAILABILITY
42   AMPICC_OUTPUT_$1 := $$(shell $$(AMPICC) -print-building-blocks $$(OPTS_cxx_$1) 2>&1)
43   ifeq (,$$(findstring Error:,$$(AMPICC_OUTPUT_$1)))
44     ifeq (,$$(findstring Warning: -$1,$$(AMPICC_OUTPUT_$1)))
45       TARGETS += cxx-$1
46     endif
47   endif
48
49   AMPIF90_OUTPUT_$1 := $$(shell $$(AMPIF90) -print-building-blocks $$(OPTS_f90_$1) 2>&1)
50   ifeq (,$$(findstring Error:,$$(AMPIF90_OUTPUT_$1)))
51     ifeq (,$$(findstring Warning: -$1,$$(AMPIF90_OUTPUT_$1)))
52       TARGETS += f90-$1
53     endif
54   endif
55 endef
56
57 $(foreach i,$(CANDIDATES),$(eval $(call TEST_TARGET_AVAILABILITY,$i)))
58
59
60 EMPTY_MESSAGE := "No privatization methods supported for current AMPI target."
61
62 all: $(foreach i,$(TARGETS),$i)
63 ifeq (,$(TARGETS))
64         @echo $(EMPTY_MESSAGE)
65 endif
66 test: $(foreach i,$(TARGETS),test-$i)
67 ifeq (,$(TARGETS))
68         @echo $(EMPTY_MESSAGE)
69 endif
70
71 everything: $(foreach i,$(VARIANTS),$(foreach j,$(LANGUAGES),$j-$i))
72 test-everything: $(foreach i,$(VARIANTS),$(foreach j,$(LANGUAGES),test-$j-$i))
73
74
75 add_if_contains = $(subst $2,$3,$(findstring $2,$1))
76
77 define VARIANT_RULES
78
79 $1: $$(foreach j,$$(LANGUAGES),$$j-$1)
80
81 # link
82 cxx-$1: $1-test.o $1-test-cxx.o cxx-$1-other-object.o | libcxx-$1-static-library.a $$(call add_if_contains,$$(FEATURES_cxx_$1),sharedlib,libcxx-$1-shared-library.so) $$(call add_if_contains,$$(FEATURES_cxx_$1),dynamiclib,libcxx-$1-shared-library-dynamic.so)
83         $$(AMPICC) -o $$@ $$(OPTS_cxx_$1) $$^ -balancer RotateLB -rpath-origin -L. -lcxx-$1-static-library $$(call add_if_contains,$$(FEATURES_cxx_$1),sharedlib,-lcxx-$1-shared-library) $$(call add_if_contains,$$(FEATURES_cxx_$1),dynamiclib,-ldl)
84
85 f90-$1: $1-test.o $1-test-f90.o
86         $$(AMPIF90) -o $$@ $$(OPTS_f90_$1) $$^ -balancer RotateLB
87
88 libcxx-$1-%.so: cxx-$1-%-so.o
89         $$(AMPICC) -o $$@ $$(OPTS_cxx_$1) -shared -standalone $$<
90
91 libcxx-$1-%.a: cxx-$1-%.o
92         ar cr $$@ $$^
93         ranlib $$@
94
95 $1-%.o cxx-$1-%.o: %.C
96         $$(AMPICC) -o $$@ $$(OPTS_cxx_$1) -Dtest_using_$1 -Dprivatization_method=$1 $$(foreach i,$$(FEATURES_cxx_$1),-Dtest_$$i) -c $$<
97
98 $1-%-so.o cxx-$1-%-so.o: %.C
99         $$(AMPICC) -o $$@ $$(OPTS_cxx_$1) -Dtest_using_$1 -Dprivatization_method=$1 $$(foreach i,$$(FEATURES_cxx_$1),-Dtest_$$i) -shared -c $$<
100
101 $1-%.o f90-$1-%.o: %.f90
102         $$(AMPIF90) -o $$@ $$(OPTS_f90_$1) -c $$<
103
104 # test
105 test-cxx-$1: cxx-$1
106         $$(call run, ./cxx-$1 +p1 +vp2 )
107         $$(call run, ./cxx-$1 +p1 +vp4 )
108         $$(call run, ./cxx-$1 +p2 +vp2 )
109         $$(call run, ./cxx-$1 +p2 +vp4 )
110
111 test-f90-$1: f90-$1
112         $$(call run, ./f90-$1 +p1 +vp2 )
113         $$(call run, ./f90-$1 +p1 +vp4 )
114         $$(call run, ./f90-$1 +p2 +vp2 )
115         $$(call run, ./f90-$1 +p2 +vp4 )
116
117 test-$1: $$(foreach j,$$(LANGUAGES),test-$$j-$1)
118
119 endef
120
121 $(foreach i,$(VARIANTS),$(eval $(call VARIANT_RULES,$i)))
122
123 # overrides
124 tlsglobals-test-f90.o: test-f90-tlsglobals.f90
125         $(AMPIF90) -o $@ $(OPTS_f90_tlsglobals) -c $<
126
127
128 clean:
129         rm -f *.o *.a *.so *.mod $(foreach i,$(VARIANTS),$(foreach j,$(LANGUAGES),$j-$i)) charmrun ampirun
130
131 .SUFFIXES:
132 .PHONY: all test everything test-everything $(foreach i,$(VARIANTS),$(foreach j,$(LANGUAGES),test-$j-$i) test-$i $i)