我想通过将不同的参数传递给#define变量,通过Makefile多次编译C代码。我应该把Noobie放在哪里?
在我的C代码中,我为矩阵的尺寸定义了尺寸
#define N 500
我想在一个循环中多次编译它,但是我无法理解如何传递
-DN=(different sizes)
在Makefile中。
该工作的结构如下: 1.清洁 2.用-DN =确定尺寸 3.运行性能测试并获取结果 4.以不同的大小重复。
我的Makefile现在看起来像这样:
exe_name = exe
CC = gcc
CFLAGS = -g -O2 -ggdb
LDFLAGS = -lm -L. -Wall -Wextra
OMPFLAGS = -fopenmp
OBJS = ompmatmul.o
default: $(exe_name)
$(exe_name): $(OBJS)
$(CC) -o $@ $^ $(LDFLAGS) $(OMPFLAGS)
%.o: %.c
$(CC) -c $< -o $@ $(CFLAGS) $(OMPFLAGS)
clean:
rm -f $(OBJS) $(exe_name) *~
.PHONY: clean #Don't look for a file named 'clean'
在将make插入到循环中时,如下所示:
for size in $(seq 500 500 3000); do
make clean
make #define_new_size
#do_performance_and_acquire_results
done
答案 0 :(得分:5)
要将参数传递给make文件,请添加如下参数:
make N=500
然后您的makefile将包含:
ifndef N
# provide a default
N=500
endif
...
$(exe_name): $(OBJS)
$(CC) -DN=$(N) -o $@ $^ $(LDFLAGS) $(OMPFLAGS)
答案 1 :(得分:1)
要基于dbush提出的出色解决方案来自动化测试,可以将以下内容添加到Makefile中:
List<Statement> newlistAllow = new ArrayList <>();
for (CommonPrefix objectToDelete:listAllow) {
Statement allowRestrictedWriteStatement = new Statement(Statement.Effect.Allow)
.withPrincipals(new Principal("12345678910"))
.withActions(S3Actions.DeleteObject)
.withResources(new S3ObjectResource(bucketNameToUse,objectToDelete.toString()));
newlistAllow.add(allowRestrictedWriteStatement);
}
List<Statement> newlistDeny = new ArrayList <>();
for (CommonPrefix objectToRetain:listDeny) {
Statement denyRestrictedWriteStatement = new Statement(Statement.Effect.Deny)
.withPrincipals(new Principal("12345678910"))
.withActions(S3Actions.DeleteObject)
.withResources(new S3ObjectResource(bucketNameToUse,objectToRetain.toString()));
newlistDeny.add(denyRestrictedWriteStatement);
}
Policy policyDeny = new Policy();
policyDeny.setStatements(newlistDeny);
Policy policyAllow = new Policy();
policyAllow.setStatements(newlistAllow);
AWSCredentials credentials = new BasicAWSCredentials("xxxxxxxxxxxxxxxxx", "yyyyyyyyyyyyyyyyyyyy");
AmazonS3 s3client = new AmazonS3Client(credentials);
s3client.setBucketPolicy(bucketNameToUse,policyAllow.toJson());
s3client.setBucketPolicy(bucketNameToUse,policyDeny.toJson());