fix
This commit is contained in:
BIN
T1/suma.asan
Executable file
BIN
T1/suma.asan
Executable file
Binary file not shown.
20
T1/suma.asan.dSYM/Contents/Info.plist
Normal file
20
T1/suma.asan.dSYM/Contents/Info.plist
Normal 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>
|
||||
BIN
T1/suma.asan.dSYM/Contents/Resources/DWARF/suma.asan
Normal file
BIN
T1/suma.asan.dSYM/Contents/Resources/DWARF/suma.asan
Normal file
Binary file not shown.
@@ -0,0 +1,5 @@
|
||||
---
|
||||
triple: 'arm64-apple-darwin'
|
||||
binary-path: suma.asan
|
||||
relocations: []
|
||||
...
|
||||
BIN
T1/suma.bin
Executable file
BIN
T1/suma.bin
Executable file
Binary file not shown.
34
T1/suma.c
34
T1/suma.c
@@ -7,6 +7,7 @@ enum { NTHREADS = 8 };
|
||||
|
||||
typedef struct {
|
||||
int *a;
|
||||
long long *prefix;
|
||||
int n;
|
||||
Set start;
|
||||
Set end;
|
||||
@@ -19,12 +20,7 @@ static Set total_combinaciones(int n) {
|
||||
return ((Set)1 << n) - 1;
|
||||
}
|
||||
|
||||
static Set buscar_rango(int a[], int n, Set start, Set end) {
|
||||
if (start == 0 || start > end)
|
||||
return 0;
|
||||
|
||||
Set k = start;
|
||||
while (1) {
|
||||
static long long suma_inicial(int a[], int n, Set k) {
|
||||
long long sum = 0;
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
@@ -32,11 +28,26 @@ static Set buscar_rango(int a[], int n, Set start, Set end) {
|
||||
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) {
|
||||
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
BIN
T1/suma.debug
Executable file
Binary file not shown.
20
T1/suma.debug.dSYM/Contents/Info.plist
Normal file
20
T1/suma.debug.dSYM/Contents/Info.plist
Normal 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>
|
||||
BIN
T1/suma.debug.dSYM/Contents/Resources/DWARF/suma.debug
Normal file
BIN
T1/suma.debug.dSYM/Contents/Resources/DWARF/suma.debug
Normal file
Binary file not shown.
@@ -0,0 +1,5 @@
|
||||
---
|
||||
triple: 'arm64-apple-darwin'
|
||||
binary-path: suma.debug
|
||||
relocations: []
|
||||
...
|
||||
BIN
T1/suma.tsan
Executable file
BIN
T1/suma.tsan
Executable file
Binary file not shown.
20
T1/suma.tsan.dSYM/Contents/Info.plist
Normal file
20
T1/suma.tsan.dSYM/Contents/Info.plist
Normal 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>
|
||||
BIN
T1/suma.tsan.dSYM/Contents/Resources/DWARF/suma.tsan
Normal file
BIN
T1/suma.tsan.dSYM/Contents/Resources/DWARF/suma.tsan
Normal file
Binary file not shown.
@@ -0,0 +1,5 @@
|
||||
---
|
||||
triple: 'arm64-apple-darwin'
|
||||
binary-path: suma.tsan
|
||||
relocations: []
|
||||
...
|
||||
Reference in New Issue
Block a user