This commit is contained in:
2026-03-24 16:11:02 -03:00
parent 9dc9f3827e
commit fdc9b068ca
14 changed files with 103 additions and 10 deletions

BIN
T1/suma.asan Executable file

Binary file not shown.

View File

@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleIdentifier</key>
<string>com.apple.xcode.dsym.suma.asan</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>dSYM</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
</plist>

Binary file not shown.

View File

@@ -0,0 +1,5 @@
---
triple: 'arm64-apple-darwin'
binary-path: suma.asan
relocations: []
...

BIN
T1/suma.bin Executable file

Binary file not shown.

View File

@@ -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++;
}

BIN
T1/suma.debug Executable file

Binary file not shown.

View File

@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleIdentifier</key>
<string>com.apple.xcode.dsym.suma.debug</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>dSYM</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
</plist>

Binary file not shown.

View File

@@ -0,0 +1,5 @@
---
triple: 'arm64-apple-darwin'
binary-path: suma.debug
relocations: []
...

BIN
T1/suma.tsan Executable file

Binary file not shown.

View File

@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleIdentifier</key>
<string>com.apple.xcode.dsym.suma.tsan</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>dSYM</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
</plist>

Binary file not shown.

View File

@@ -0,0 +1,5 @@
---
triple: 'arm64-apple-darwin'
binary-path: suma.tsan
relocations: []
...