First Commit
This commit is contained in:
42
wasm_add_pthread.c
Normal file
42
wasm_add_pthread.c
Normal file
@@ -0,0 +1,42 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <emscripten/emscripten.h> // For EMSCRIPTEN_KEEPALIVE
|
||||
|
||||
#define ARRAY_SIZE 15000576 // 15 million items (still define for context, but not used directly in loops anymore)
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE
|
||||
int* alloc( int size ) {
|
||||
return ( int * ) malloc( size );
|
||||
}
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE
|
||||
void dealloc( int * ptr, int size ) {
|
||||
free( ptr );
|
||||
}
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE
|
||||
float* alloc_float_array(int size) {
|
||||
return ( float * ) malloc(size * sizeof(float));
|
||||
}
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE
|
||||
void dealloc_float_array(float* ptr) {
|
||||
free(ptr);
|
||||
}
|
||||
|
||||
// Modified init_arrays to operate on a specific range
|
||||
EMSCRIPTEN_KEEPALIVE
|
||||
void init_arrays_range(float* a, float* b, int start_idx, int end_idx) {
|
||||
for (int i = start_idx; i < end_idx; i++) {
|
||||
a[i] = (float)i;
|
||||
b[i] = (float)i * 2.0f;
|
||||
}
|
||||
}
|
||||
|
||||
// Modified calculate to operate on a specific range
|
||||
EMSCRIPTEN_KEEPALIVE
|
||||
void calculate_range(float* a, float* b, float* c, int start_idx, int end_idx) {
|
||||
for (int i = start_idx; i < end_idx; i++) {
|
||||
c[i] = a[i] + b[i];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user