diff --git a/T1/suma.asan b/T1/suma.asan
new file mode 100755
index 0000000..f1db01e
Binary files /dev/null and b/T1/suma.asan differ
diff --git a/T1/suma.asan.dSYM/Contents/Info.plist b/T1/suma.asan.dSYM/Contents/Info.plist
new file mode 100644
index 0000000..ea64c90
--- /dev/null
+++ b/T1/suma.asan.dSYM/Contents/Info.plist
@@ -0,0 +1,20 @@
+
+
+
+
+ CFBundleDevelopmentRegion
+ English
+ CFBundleIdentifier
+ com.apple.xcode.dsym.suma.asan
+ CFBundleInfoDictionaryVersion
+ 6.0
+ CFBundlePackageType
+ dSYM
+ CFBundleSignature
+ ????
+ CFBundleShortVersionString
+ 1.0
+ CFBundleVersion
+ 1
+
+
diff --git a/T1/suma.asan.dSYM/Contents/Resources/DWARF/suma.asan b/T1/suma.asan.dSYM/Contents/Resources/DWARF/suma.asan
new file mode 100644
index 0000000..1d829ba
Binary files /dev/null and b/T1/suma.asan.dSYM/Contents/Resources/DWARF/suma.asan differ
diff --git a/T1/suma.asan.dSYM/Contents/Resources/Relocations/aarch64/suma.asan.yml b/T1/suma.asan.dSYM/Contents/Resources/Relocations/aarch64/suma.asan.yml
new file mode 100644
index 0000000..cb97bac
--- /dev/null
+++ b/T1/suma.asan.dSYM/Contents/Resources/Relocations/aarch64/suma.asan.yml
@@ -0,0 +1,5 @@
+---
+triple: 'arm64-apple-darwin'
+binary-path: suma.asan
+relocations: []
+...
diff --git a/T1/suma.bin b/T1/suma.bin
new file mode 100755
index 0000000..03ef411
Binary files /dev/null and b/T1/suma.bin differ
diff --git a/T1/suma.c b/T1/suma.c
index b6368cb..373a242 100644
--- a/T1/suma.c
+++ b/T1/suma.c
@@ -7,6 +7,7 @@ enum { NTHREADS = 8 };
typedef struct {
int *a;
+ long long *prefix;
int n;
Set start;
Set end;
@@ -19,24 +20,34 @@ static Set total_combinaciones(int n) {
return ((Set)1 << n) - 1;
}
-static Set buscar_rango(int a[], int n, Set start, Set end) {
+static long long suma_inicial(int a[], int n, Set k) {
+ long long sum = 0;
+
+ for (int i = 0; i < n; i++) {
+ if (k & ((Set)1 << i))
+ sum += a[i];
+ }
+
+ return sum;
+}
+
+static Set buscar_rango(int a[], long long prefix[], int n, Set start, Set end) {
if (start == 0 || start > end)
return 0;
Set k = start;
+ long long sum = suma_inicial(a, n, k);
+
while (1) {
- long long sum = 0;
-
- for (int i = 0; i < n; i++) {
- if (k & ((Set)1 << i))
- sum += a[i];
- }
-
if (sum == 0)
return k;
if (k == end)
break;
+
+ unsigned int shift = (unsigned int)__builtin_ctzll(~k);
+ sum -= prefix[shift];
+ sum += a[shift];
k++;
}
@@ -45,7 +56,8 @@ static Set buscar_rango(int a[], int n, Set start, Set end) {
static void *buscar_thread(void *ptr) {
BuscarArgs *args = ptr;
- args->found = buscar_rango(args->a, args->n, args->start, args->end);
+ args->found = buscar_rango(args->a, args->prefix, args->n, args->start,
+ args->end);
return NULL;
}
@@ -56,12 +68,18 @@ Set buscar(int a[], int n) {
Set next = 1;
pthread_t tids[NTHREADS];
BuscarArgs args[NTHREADS];
+ long long prefix[CHAR_BIT * sizeof(Set) + 1];
int created = 0;
+ prefix[0] = 0;
+ for (int i = 0; i < n; i++)
+ prefix[i + 1] = prefix[i] + a[i];
+
for (int t = 0; t < NTHREADS; t++) {
Set len = base + (Set)(t < (int)extra);
args[t].a = a;
+ args[t].prefix = prefix;
args[t].n = n;
args[t].start = next;
args[t].end = (len == 0) ? next - 1
@@ -74,7 +92,7 @@ Set buscar(int a[], int n) {
if (pthread_create(&tids[t], NULL, buscar_thread, &args[t]) != 0) {
for (int i = 0; i < created; i++)
pthread_join(tids[i], NULL);
- return buscar_rango(a, n, 1, comb);
+ return buscar_rango(a, prefix, n, 1, comb);
}
created++;
}
diff --git a/T1/suma.debug b/T1/suma.debug
new file mode 100755
index 0000000..836e461
Binary files /dev/null and b/T1/suma.debug differ
diff --git a/T1/suma.debug.dSYM/Contents/Info.plist b/T1/suma.debug.dSYM/Contents/Info.plist
new file mode 100644
index 0000000..dabdb8b
--- /dev/null
+++ b/T1/suma.debug.dSYM/Contents/Info.plist
@@ -0,0 +1,20 @@
+
+
+
+
+ CFBundleDevelopmentRegion
+ English
+ CFBundleIdentifier
+ com.apple.xcode.dsym.suma.debug
+ CFBundleInfoDictionaryVersion
+ 6.0
+ CFBundlePackageType
+ dSYM
+ CFBundleSignature
+ ????
+ CFBundleShortVersionString
+ 1.0
+ CFBundleVersion
+ 1
+
+
diff --git a/T1/suma.debug.dSYM/Contents/Resources/DWARF/suma.debug b/T1/suma.debug.dSYM/Contents/Resources/DWARF/suma.debug
new file mode 100644
index 0000000..62a57f1
Binary files /dev/null and b/T1/suma.debug.dSYM/Contents/Resources/DWARF/suma.debug differ
diff --git a/T1/suma.debug.dSYM/Contents/Resources/Relocations/aarch64/suma.debug.yml b/T1/suma.debug.dSYM/Contents/Resources/Relocations/aarch64/suma.debug.yml
new file mode 100644
index 0000000..7cec44f
--- /dev/null
+++ b/T1/suma.debug.dSYM/Contents/Resources/Relocations/aarch64/suma.debug.yml
@@ -0,0 +1,5 @@
+---
+triple: 'arm64-apple-darwin'
+binary-path: suma.debug
+relocations: []
+...
diff --git a/T1/suma.tsan b/T1/suma.tsan
new file mode 100755
index 0000000..9dda27c
Binary files /dev/null and b/T1/suma.tsan differ
diff --git a/T1/suma.tsan.dSYM/Contents/Info.plist b/T1/suma.tsan.dSYM/Contents/Info.plist
new file mode 100644
index 0000000..5759ffb
--- /dev/null
+++ b/T1/suma.tsan.dSYM/Contents/Info.plist
@@ -0,0 +1,20 @@
+
+
+
+
+ CFBundleDevelopmentRegion
+ English
+ CFBundleIdentifier
+ com.apple.xcode.dsym.suma.tsan
+ CFBundleInfoDictionaryVersion
+ 6.0
+ CFBundlePackageType
+ dSYM
+ CFBundleSignature
+ ????
+ CFBundleShortVersionString
+ 1.0
+ CFBundleVersion
+ 1
+
+
diff --git a/T1/suma.tsan.dSYM/Contents/Resources/DWARF/suma.tsan b/T1/suma.tsan.dSYM/Contents/Resources/DWARF/suma.tsan
new file mode 100644
index 0000000..c6bd76d
Binary files /dev/null and b/T1/suma.tsan.dSYM/Contents/Resources/DWARF/suma.tsan differ
diff --git a/T1/suma.tsan.dSYM/Contents/Resources/Relocations/aarch64/suma.tsan.yml b/T1/suma.tsan.dSYM/Contents/Resources/Relocations/aarch64/suma.tsan.yml
new file mode 100644
index 0000000..280cae5
--- /dev/null
+++ b/T1/suma.tsan.dSYM/Contents/Resources/Relocations/aarch64/suma.tsan.yml
@@ -0,0 +1,5 @@
+---
+triple: 'arm64-apple-darwin'
+binary-path: suma.tsan
+relocations: []
+...