fix memory allocation for YapOR

This commit is contained in:
Joao 2011-04-14 19:19:13 +01:00
parent 47f7ff0ad7
commit b6e0a64e56
18 changed files with 348 additions and 380 deletions

View File

@ -1236,8 +1236,9 @@ Yap_CloseScratchPad(void)
#include "ilocals.h"
#if defined(YAPOR) && !defined(THREADS)
#if defined(YAPOR) && !defined(THREADS)
struct global_data *Yap_global;
long Yap_worker_area_size;
#else
struct global_data Yap_Global;
#endif
@ -1351,7 +1352,7 @@ Yap_InitWorkspace(UInt Heap, UInt Stack, UInt Trail, UInt Atts, UInt max_table_s
#else /* YAPOR_SBA */
INFORMATION_MESSAGE("YapOr: sba model with %d worker%s", n_workers, n_workers == 1 ? "":"s");
#endif /* YAPOR_COPY - YAPOR_COW - YAPOR_SBA */
map_memory(Heap, Stack+Atts, Trail, n_workers);
Yap_init_optyap_memory(Trail, Heap, Stack+Atts, n_workers);
#else
Yap_InitMemory (Trail, Heap, Stack+Atts);
#endif /* YAPOR && !THREADS */
@ -1414,8 +1415,8 @@ void
Yap_exit (int value)
{
#if defined(YAPOR) && !defined(THREADS)
unmap_memory();
#endif /* YAPOR */
Yap_unmap_optyap_memory();
#endif /* YAPOR && !THREADS */
if (! (Yap_PrologMode & BootMode) ) {
#ifdef LOW_PROF

View File

@ -1110,8 +1110,8 @@ Yap_plwrite(Term t, int (*mywrite) (int, wchar_t), int flags, int priority)
wglb.Quote_illegal = flags & Quote_illegal_f;
wglb.Handle_vars = flags & Handle_vars_f;
wglb.Use_portray = flags & Use_portray_f;
wglb.MaxDepth = 10L;
wglb.MaxArgs = 10L;
wglb.MaxDepth = 15L;
wglb.MaxArgs = 15L;
/* notice: we must have ASP well set when using portray, otherwise
we cannot make recursive Prolog calls */
wglb.keep_terms = (flags & (Use_portray_f|To_heap_f));

34
H/Yap.h
View File

@ -16,8 +16,24 @@
#ifndef YAP_H
#define YAP_H 1
#if defined(YAPOR)
#error Do not explicitly define YAPOR
#endif /* YAPOR */
#if (defined(YAPOR_COPY) && (defined(YAPOR_COW) || defined(YAPOR_SBA))) || (defined(YAPOR_COW) && defined(YAPOR_SBA))
#error Do not define multiple or-parallel models
#endif /* (YAPOR_COPY && (YAPOR_COW || YAPOR_SBA)) || (YAPOR_COW && YAPOR_SBA) */
#if defined(YAPOR_COPY) || defined(YAPOR_COW) || defined(YAPOR_SBA) || defined(THREADS)
#define YAPOR 1
#endif /* YAPOR_COPY || YAPOR_COW || YAPOR_SBA */
#if defined(TABLING) && (defined(YAPOR_COW) || defined(YAPOR_SBA))
#error Currently TABLING only works with YAPOR_COPY
#endif /* TABLING && (YAPOR_COW || YAPOR_SBA) */
#include "config.h"
#if defined(YAPOR_COPY) || defined(TABLING) || defined(THREADS)
#if defined(YAPOR) || defined(TABLING) || defined(THREADS)
#include "opt.config.h"
#endif /* YAPOR || TABLING */
@ -35,22 +51,6 @@
#define MULTI_ASSIGNMENT_VARIABLES 1
#if defined(YAPOR)
#error Do not explicitly define YAPOR
#endif /* YAPOR */
#if (defined(YAPOR_COPY) && (defined(YAPOR_COW) || defined(YAPOR_SBA))) || (defined(YAPOR_COW) && defined(YAPOR_SBA))
#error Do not define multiple or-parallel models
#endif /* (YAPOR_COPY && (YAPOR_COW || YAPOR_SBA)) || (YAPOR_COW && YAPOR_SBA) */
#if defined(YAPOR_COPY) || defined(YAPOR_COW) || defined(YAPOR_SBA) || defined(THREADS)
#define YAPOR 1
#endif /* YAPOR_COPY || YAPOR_COW || YAPOR_SBA */
#if defined(TABLING) && (defined(YAPOR_COW) || defined(YAPOR_SBA))
#error Currently TABLING only works with YAPOR_COPY
#endif /* TABLING && (YAPOR_COW || YAPOR_SBA) */
#ifdef YAPOR
#define FIXED_STACKS 1
#ifdef THREADS

View File

@ -182,6 +182,7 @@ typedef struct various_codes {
#if defined(YAPOR) && !defined(THREADS)
extern struct global_data *Yap_global;
extern long Yap_worker_area_size;
#else
extern struct global_data Yap_Global;
#define Yap_global (&Yap_Global)

View File

@ -20,6 +20,7 @@
/**********************************************************
** memory alloc scheme (mandatory, define one) **
**********************************************************/
#ifdef USE_SYSTEM_MALLOC
#define MALLOC_MEMORY_ALLOC_SCHEME 1
#else
@ -96,7 +97,7 @@
** memory mapping scheme (mandatory, define one) **
************************************************************/
#define MMAP_MEMORY_MAPPING_SCHEME 1
/* #define SHM_MEMORY_MAPPING_SCHEME 1 */
//#define SHM_MEMORY_MAPPING_SCHEME 1
/*************************************************
** enable error checking ? (optional) **

View File

@ -27,34 +27,15 @@
#endif /* YAPOR */
#ifdef TABLING
#include "tab.macros.h"
#endif /* TABLING */
#if defined(TABLING) || !defined(YAPOR_COW)
#ifndef TABLING
#elif !defined(YAPOR_COW)
#include "opt.mavar.h"
#endif /* !TABLING */
#ifdef MULTI_ASSIGNMENT_VARIABLES
ma_hash_entry Yap_ma_hash_table[MAVARS_HASH_SIZE];
UInt Yap_ma_timestamp; /* an unsigned int */
ma_h_inner_struct *Yap_ma_h_top;
#endif /* MULTI_ASSIGNMENT_VARIABLES */
#endif /* TABLING || !YAPOR_COW */
#endif /* TABLING */
#ifdef YAPOR_COW
#include "sys/wait.h"
#endif /* YAPOR_COW */
/************************************************
** Global variables are defined here **
************************************************/
#if defined(YAPOR) && ! defined(THREADS)
struct worker WORKER;
#endif /* YAPOR && ! THREADS */
/*********************
** Macros **
*********************/
@ -283,7 +264,7 @@ void init_workers(void) {
if (son == 0) {
/* new worker */
worker_id = proc;
remap_memory();
Yap_remap_optyap_memory();
break;
}
else Yap_worker_pid(proc) = son;

View File

@ -19,10 +19,11 @@ extern int Yap_page_size;
#ifdef SHM_MEMORY_ALLOC_SCHEME
#include <sys/shm.h>
#endif /* SHM_MEMORY_ALLOC_SCHEME */
#define SHMMAX 0x2000000 /* 32 Mbytes: works fine with linux */
/* #define SHMMAX 0x400000 - 4 Mbytes: shmget limit for Mac (?) */
/* #define SHMMAX 0x800000 - 8 Mbytes: shmget limit for Solaris (?) */
#endif /* SHM_MEMORY_ALLOC_SCHEME */
#if SIZEOF_INT_P == 4
#define ALIGN 3

View File

@ -19,28 +19,12 @@
#ifndef OPT_MAVAR_STATIC
#define OPT_MAVAR_STATIC inline static
#endif
#endif /* !OPT_MAVAR_STATIC */
#define MAVARS_HASH_SIZE 512
typedef struct ma_h_entry {
CELL* addr;
struct ma_h_entry *next;
} ma_h_inner_struct;
typedef struct {
UInt timestmp;
struct ma_h_entry val;
} ma_hash_entry;
extern ma_hash_entry Yap_ma_hash_table[MAVARS_HASH_SIZE];
extern UInt Yap_ma_timestamp; /* an unsigned int */
OPT_MAVAR_STATIC unsigned int Yap_MAVAR_HASH(CELL *);
OPT_MAVAR_STATIC struct ma_h_entry *Yap_ALLOC_NEW_MASPACE(void);
OPT_MAVAR_STATIC int Yap_lookup_ma_var(CELL *);
OPT_MAVAR_STATIC UInt Yap_NEW_MAHASH(ma_h_inner_struct *);
OPT_MAVAR_STATIC unsigned int Yap_MAVAR_HASH(CELL *addr);
OPT_MAVAR_STATIC struct ma_h_entry * Yap_ALLOC_NEW_MASPACE(void);
OPT_MAVAR_STATIC int Yap_lookup_ma_var(CELL *addr);
OPT_MAVAR_STATIC UInt Yap_NEW_MAHASH(ma_h_inner_struct *top);
OPT_MAVAR_STATIC unsigned int
Yap_MAVAR_HASH(CELL *addr) {
@ -51,13 +35,11 @@ Yap_MAVAR_HASH(CELL *addr) {
#endif
}
extern ma_h_inner_struct *Yap_ma_h_top;
OPT_MAVAR_STATIC struct ma_h_entry *
Yap_ALLOC_NEW_MASPACE(void)
{
ma_h_inner_struct *new = Yap_ma_h_top;
Yap_ma_h_top++;
ma_h_inner_struct *new = LOCAL_ma_h_top;
LOCAL_ma_h_top++;
return new;
}
@ -66,16 +48,16 @@ Yap_lookup_ma_var(CELL *addr) {
unsigned int i = Yap_MAVAR_HASH(addr);
struct ma_h_entry *nptr, *optr;
if (Yap_ma_hash_table[i].timestmp != Yap_ma_timestamp) {
Yap_ma_hash_table[i].timestmp = Yap_ma_timestamp;
Yap_ma_hash_table[i].val.addr = addr;
Yap_ma_hash_table[i].val.next = NULL;
if (LOCAL_ma_hash_table[i].timestmp != LOCAL_ma_timestamp) {
LOCAL_ma_hash_table[i].timestmp = LOCAL_ma_timestamp;
LOCAL_ma_hash_table[i].val.addr = addr;
LOCAL_ma_hash_table[i].val.next = NULL;
return FALSE;
}
if (Yap_ma_hash_table[i].val.addr == addr)
if (LOCAL_ma_hash_table[i].val.addr == addr)
return TRUE;
optr = &(Yap_ma_hash_table[i].val);
nptr = Yap_ma_hash_table[i].val.next;
optr = &(LOCAL_ma_hash_table[i].val);
nptr = LOCAL_ma_hash_table[i].val.next;
while (nptr != NULL) {
if (nptr->addr == addr) {
return TRUE;
@ -91,16 +73,15 @@ Yap_lookup_ma_var(CELL *addr) {
OPT_MAVAR_STATIC UInt
Yap_NEW_MAHASH(ma_h_inner_struct *top) {
UInt time = ++Yap_ma_timestamp;
UInt time = ++LOCAL_ma_timestamp;
if (time == 0) {
unsigned int i;
/* damn, we overflowed */
for (i = 0; i < MAVARS_HASH_SIZE; i++)
Yap_ma_hash_table[i].timestmp = 0;
time = ++Yap_ma_timestamp;
LOCAL_ma_hash_table[i].timestmp = 0;
time = ++LOCAL_ma_timestamp;
}
Yap_ma_h_top = top;
LOCAL_ma_h_top = top;
return time;
}
#endif /* MULTI_ASSIGNMENT_VARIABLES */

View File

@ -30,6 +30,13 @@
#include "YapHeap.h"
#include "alloc.h"
#include "heapgc.h"
#include "or.macros.h"
/************************************
** Macros & Declarations **
************************************/
#define KBYTES 1024
@ -39,27 +46,209 @@ int fd_mapfile;
int shm_mapid[MAX_WORKERS + 1];
#endif /* MEMORY_MAPPING_SCHEME */
static Int extra_area = 0;
/******************************************
** Local functions declaration **
******************************************/
#ifdef MMAP_MEMORY_MAPPING_SCHEME
void open_mapfile(long TotalArea);
#else /* SHM_MEMORY_MAPPING_SCHEME */
void shm_map_memory(int id, int size, void *shmaddr);
#endif /* MEMORY_MAPPING_SCHEME */
/********************************
** Global functions **
********************************/
#ifdef SHM_MEMORY_MAPPING_SCHEME
void shm_map_memory(int id, int size, void *shmaddr) {
#define SHMMAX 0x2000000 /* as in <asm/shmparam.h> */
if (size > SHMMAX)
Yap_Error(FATAL_ERROR, TermNil, "maximum size for a shm segment exceeded (shm_map_memory)");
if ((shm_mapid[id] = shmget(IPC_PRIVATE, size, SHM_R|SHM_W)) == -1)
Yap_Error(FATAL_ERROR, TermNil, "shmget error (shm_map_memory)");
if (shmat(shm_mapid[id], shmaddr, 0) == (void *) -1)
Yap_Error(FATAL_ERROR, TermNil, "shmat error (shm_map_memory)");
void Yap_init_optyap_memory(long TrailAuxArea, long HeapArea, long GlobalLocalArea, int n_workers) {
#ifdef YAPOR_COW
int private_fd_mapfile;
#if MMAP_MEMORY_MAPPING_SCHEME
long TotalArea;
#endif /* MMAP_MEMORY_MAPPING_SCHEME */
#else /* YAPOR_COPY || YAPOR_SBA */
long TotalArea;
#endif /* YAPOR_MODEL */
long ExtraArea;
HeapArea = ADJUST_SIZE_TO_PAGE(HeapArea);
GlobalLocalArea = ADJUST_SIZE(GlobalLocalArea);
TrailAuxArea = ADJUST_SIZE(TrailAuxArea);
/* initial allocation - model independent */
ExtraArea = ADJUST_SIZE_TO_PAGE(sizeof(struct global_data) + MAX_WORKERS * sizeof(struct worker_local));
Yap_WLocal = (struct worker_local *)(MMAP_ADDR - ExtraArea);
Yap_global = (struct global_data *)(MMAP_ADDR - sizeof(struct global_data));
Yap_HeapBase = (ADDR) MMAP_ADDR;
Yap_GlobalBase = (ADDR) (MMAP_ADDR + HeapArea);
/* shared memory allocation - model dependent */
#ifdef YAPOR_COW
/* acow just needs one stack */
#ifdef MMAP_MEMORY_MAPPING_SCHEME
/* I need this for MMAP to know what it must allocate */
TotalArea = HeapArea;
#endif /* MMAP_MEMORY_MAPPING_SCHEME */
#else /* YAPOR_COPY || YAPOR_SBA */
/* the others need n stacks */
Yap_worker_area_size = ADJUST_SIZE_TO_PAGE(GlobalLocalArea + TrailAuxArea);
TotalArea = ExtraArea + HeapArea + Yap_worker_area_size * n_workers;
#endif /* YAPOR_MODEL */
#ifdef MMAP_MEMORY_MAPPING_SCHEME
/* map total area in a single go */
open_mapfile(TotalArea);
if (mmap((void *) Yap_WLocal, (size_t) TotalArea, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_FIXED, fd_mapfile, 0) == (void *) -1)
Yap_Error(FATAL_ERROR, TermNil, "mmap error (Yap_init_optyap_memory)");
#else /* SHM_MEMORY_MAPPING_SCHEME */
/* most systems are limited regarding what we can allocate */
#ifdef YAPOR_COW
/* single shared segment in ACOW */
shm_map_memory(0, ExtraArea + HeapArea, (void *) MMAP_ADDR);
#else /* YAPOR_COPY || YAPOR_SBA */
/* place as segment n otherwise (0..n-1 reserved for worker areas */
shm_map_memory(n_workers, ExtraArea + HeapArea, (void *) Yap_WLocal);
{ int i;
for (i = 0; i < n_workers; i++)
shm_map_memory(i, Yap_worker_area_size, Yap_GlobalBase + Yap_worker_area_size * i);
}
#endif /* YAPOR_MODEL */
#endif /* MEMORY_MAPPING_SCHEME */
#ifdef YAPOR_COW
/* just allocate local space for stacks */
if ((private_fd_mapfile = open("/dev/zero", O_RDWR)) < 0)
Yap_Error(FATAL_ERROR, TermNil, "open error (Yap_init_optyap_memory)");
if (mmap(Yap_GlobalBase, GlobalLocalArea + TrailAuxArea, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_FIXED, private_fd_mapfile, 0) == (void *) -1)
Yap_Error(FATAL_ERROR, TermNil, "mmap error (Yap_init_optyap_memory)");
close(private_fd_mapfile);
#endif /* YAPOR_COW */
#ifdef YAPOR_SBA
/* alloc space for the sparse binding array */
sba_size = Yap_worker_area_size * n_workers;
if ((binding_array = (char *)malloc(sba_size)) == NULL)
Yap_Error(FATAL_ERROR, TermNil, "malloc error (Yap_init_optyap_memory)");
if ((CELL)binding_array & MBIT) {
Yap_Error(INTERNAL_ERROR, TermNil, "binding_array start address conflicts with tag used in IDB (Yap_init_optyap_memory)");
}
sba_offset = binding_array - Yap_GlobalBase;
sba_end = (int)binding_array + sba_size;
#endif /* YAPOR_SBA */
Yap_TrailBase = Yap_GlobalBase + GlobalLocalArea;
Yap_LocalBase = Yap_TrailBase - CellSize;
if (TrailAuxArea > 262144) /* 262144 = 256 * 1024 */
Yap_TrailTop = Yap_TrailBase + (TrailAuxArea - 131072); /* 131072 = 262144 / 2 */
else
Yap_TrailTop = Yap_TrailBase + (TrailAuxArea / 2);
HeapMax = (CELL)(Yap_TrailBase + (TrailAuxArea - CellSize));
Yap_InitHeap(Yap_HeapBase);
}
void Yap_remap_optyap_memory(void) {
#ifdef YAPOR_SBA
/* setup workers so that they have different areas */
Yap_GlobalBase += worker_id * Yap_worker_area_size;
Yap_TrailBase += worker_id * Yap_worker_area_size;
Yap_LocalBase += worker_id * Yap_worker_area_size;
Yap_TrailTop += worker_id * Yap_worker_area_size;
#endif /* YAPOR_SBA */
#ifdef YAPOR_COPY
int i;
void *remap_addr = Yap_GlobalBase;
#ifdef MMAP_MEMORY_MAPPING_SCHEME
long remap_offset = (ADDR) remap_addr - (ADDR) Yap_WLocal;
if (munmap(remap_addr, (size_t)(Yap_worker_area_size * Yap_number_workers)) == -1)
Yap_Error(FATAL_ERROR, TermNil, "munmap error (Yap_remap_optyap_memory)");
for (i = 0; i < Yap_number_workers; i++)
if (mmap(remap_addr + worker_offset(i), (size_t)Yap_worker_area_size, PROT_READ|PROT_WRITE,
MAP_SHARED|MAP_FIXED, fd_mapfile, remap_offset + i * Yap_worker_area_size) == (void *) -1)
Yap_Error(FATAL_ERROR, TermNil, "mmap error (Yap_remap_optyap_memory)");
#else /* SHM_MEMORY_MAPPING_SCHEME */
for (i = 0; i < Yap_number_workers; i++)
if (shmdt(remap_addr + Yap_worker_area_size * i) == -1)
Yap_Error(FATAL_ERROR, TermNil, "shmdt error (Yap_remap_optyap_memory)");
for (i = 0; i < Yap_number_workers; i++)
if(shmat(shm_mapid[i], remap_addr + worker_offset(i), 0) == (void *) -1)
Yap_Error(FATAL_ERROR, TermNil, "shmat error (Yap_remap_optyap_memory)");
#endif /* MEMORY_MAPPING_SCHEME */
#endif /* YAPOR_COPY */
}
void Yap_unmap_optyap_memory (void) {
#ifdef MMAP_MEMORY_MAPPING_SCHEME
char MapFile[20];
#else /* SHM_MEMORY_MAPPING_SCHEME */
int i;
#endif /* MEMORY_MAPPING_SCHEME */
int proc;
INFORMATION_MESSAGE("Worker %d exiting...", worker_id);
for (proc = 0; proc < Yap_number_workers; proc++) {
if (proc != worker_id && Yap_worker_pid(proc) != 0) {
if (kill(Yap_worker_pid(proc), SIGKILL) != 0)
INFORMATION_MESSAGE("Can't kill process %d", Yap_worker_pid(proc));
else
INFORMATION_MESSAGE("Killing process %d", Yap_worker_pid(proc));
}
}
#ifdef YAPOR_COW
if (Yap_number_workers > 1) {
if (kill(Yap_master_worker, SIGINT) != 0)
INFORMATION_MESSAGE("Can't kill process %d", Yap_master_worker);
else
INFORMATION_MESSAGE("Killing process %d", Yap_master_worker);
}
#endif /* YAPOR_COW */
#ifdef MMAP_MEMORY_MAPPING_SCHEME
strcpy(MapFile,"./mapfile");
#ifdef YAPOR_COW
itos(Yap_master_worker, &MapFile[9]);
#else /* YAPOR_COPY || YAPOR_SBA */
itos(Yap_worker_pid(0), &MapFile[9]);
#endif /* YAPOR_MODEL */
if (remove(MapFile) == 0)
INFORMATION_MESSAGE("Removing mapfile \"%s\"", MapFile);
else
INFORMATION_MESSAGE("Can't remove mapfile \"%s\"", MapFile);
#else /* SHM_MEMORY_MAPPING_SCHEME */
#ifdef YAPOR_COW
i = 0;
#else /* YAPOR_COPY || YAPOR_SBA */
for (i = 0; i < Yap_number_workers + 1; i++)
#endif /* YAPOR_COW */
{
if (shmctl(shm_mapid[i], IPC_RMID, 0) == 0)
INFORMATION_MESSAGE("Removing shared memory segment %d", shm_mapid[i]);
else
INFORMATION_MESSAGE("Can't remove shared memory segment %d", shm_mapid[i]);
}
#endif /* MEMORY_MAPPING_SCHEME */
return;
}
#else /* MMAP_MEMORY_MAPPING_SCHEME */
void
open_mapfile(long TotalArea) {
/* ------------------------- **
** Local functions **
** ------------------------- */
#ifdef MMAP_MEMORY_MAPPING_SCHEME
void open_mapfile(long TotalArea) {
char mapfile[20];
strcpy(mapfile,"./mapfile");
itos(getpid(), &mapfile[9]);
@ -71,217 +260,16 @@ open_mapfile(long TotalArea) {
Yap_Error(FATAL_ERROR, TermNil, "write error (open_mapfile)");
return;
}
void
close_mapfile(void) {
if (close(fd_mapfile) < 0)
Yap_Error(FATAL_ERROR, TermNil, "close error (close_mapfile)");
}
#endif /* MMAP_MEMORY_MAPPING_SCHEME */
void map_memory(long HeapArea, long GlobalLocalArea, long TrailAuxArea, int n_workers) {
void *mmap_addr = (void *)MMAP_ADDR;
#ifdef YAPOR_COW
int private_fd_mapfile;
#if MMAP_MEMORY_MAPPING_SCHEME
long TotalArea;
#endif /* MMAP_MEMORY_MAPPING_SCHEME */
#else /* YAPOR_COPY || YAPOR_SBA */
int i;
long WorkerArea;
long TotalArea;
#endif /* YAPOR_MODEL */
/* initial allocation - model independent */
HeapArea = ADJUST_SIZE_TO_PAGE(HeapArea);
GlobalLocalArea = ADJUST_SIZE(GlobalLocalArea);
TrailAuxArea = ADJUST_SIZE(TrailAuxArea);
/* we'll need this later */
#if defined(YAPOR) && !defined(THREADS)
Yap_global = (struct global_data *)( mmap_addr - sizeof(struct global_data));
Yap_WLocal = (struct worker_local *)( mmap_addr - (sizeof(struct global_data)+MAX_WORKERS*sizeof(struct worker_local)));
extra_area = ADJUST_SIZE_TO_PAGE(sizeof(struct global_data)+MAX_WORKERS*sizeof(struct worker_local));
#endif
Yap_HeapBase = (ADDR)mmap_addr;
Yap_GlobalBase = mmap_addr + HeapArea;
/* shared memory allocation - model dependent */
#ifdef YAPOR_COW
/* acow just needs one stack */
#ifdef MMAP_MEMORY_MAPPING_SCHEME
/* I need this for MMAP to know what it must allocate */
TotalArea = HeapArea;
#endif /* MMAP_MEMORY_MAPPING_SCHEME */
#else /* YAPOR_COPY || YAPOR_SBA */
/* the others need n stacks */
WorkerArea = ADJUST_SIZE_TO_PAGE(GlobalLocalArea + TrailAuxArea);
TotalArea = HeapArea + WorkerArea * n_workers;
#endif /* YAPOR_MODEL */
/* mmap heap area */
#ifdef MMAP_MEMORY_MAPPING_SCHEME
/* map total area in a single go */
open_mapfile(TotalArea+extra_area);
if ((mmap_addr = mmap((void *) MMAP_ADDR-extra_area, (size_t) (TotalArea+extra_area), PROT_READ|PROT_WRITE,
MAP_SHARED|MAP_FIXED, fd_mapfile, 0)) == (void *) -1)
Yap_Error(FATAL_ERROR, TermNil, "mmap error (map_memory)");
#if defined(YAPOR) && !defined(THREADS)
mmap_addr += extra_area;
#endif
#else /* SHM_MEMORY_MAPPING_SCHEME */
/* Most systems are limited regarding what we can allocate */
#ifdef YAPOR_COW
/* single shared segment in ACOW */
shm_map_memory(0, HeapArea, mmap_addr);
#else /* YAPOR_COPY || YAPOR_SBA */
/* place as segment n otherwise (0..n-1 reserved for worker areas */
shm_map_memory(n_workers, HeapArea, mmap_addr);
#endif /* YAPOR_MODEL */
#endif /* MEMORY_MAPPING_SCHEME */
#ifdef YAPOR_COW
/* just allocate local space for stacks */
if ((private_fd_mapfile = open("/dev/zero", O_RDWR)) < 0)
Yap_Error(FATAL_ERROR, TermNil, "open error (map_memory)");
if (mmap(Yap_GlobalBase, GlobalLocalArea + TrailAuxArea, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_FIXED, private_fd_mapfile, 0) == (void *) -1)
Yap_Error(FATAL_ERROR, TermNil, "mmap error (map_memory)");
close(private_fd_mapfile);
#else /* YAPOR_COPY || YAPOR_SBA */
for (i = 0; i < n_workers; i++) {
/* initialize worker vars */
worker_area(i) = Yap_GlobalBase + i * WorkerArea;
worker_offset(i) = worker_area(i) - worker_area(0);
#ifdef SHM_MEMORY_MAPPING_SCHEME
/* mapping worker area */
shm_map_memory(i, WorkerArea, worker_area(i));
#endif /* SHM_MEMORY_MAPPING_SCHEME */
}
#endif /* YAPOR_MODEL */
#ifdef YAPOR_SBA
/* alloc space for the sparse binding array */
sba_size = WorkerArea * n_workers;
if ((binding_array = (char *)malloc(sba_size)) == NULL)
Yap_Error(FATAL_ERROR, TermNil, "malloc error (map_memory)");
if ((CELL)binding_array & MBIT) {
Yap_Error(INTERNAL_ERROR, TermNil, "binding_array start address conflicts with tag used in IDB (map_memory)");
}
sba_offset = binding_array - Yap_GlobalBase;
sba_end = (int)binding_array + sba_size;
#endif /* YAPOR_SBA */
Yap_TrailBase = Yap_GlobalBase + GlobalLocalArea;
Yap_LocalBase = Yap_TrailBase - CellSize;
if (TrailAuxArea > 262144) /* 262144 = 256 * 1024 */
Yap_TrailTop = Yap_TrailBase + (TrailAuxArea - 131072); /* 131072 = 262144 / 2 */
else
Yap_TrailTop = Yap_TrailBase + (TrailAuxArea / 2);
HeapMax = (CELL)(Yap_TrailBase + (TrailAuxArea - CellSize));
Yap_InitHeap(mmap_addr);
}
void unmap_memory (void) {
#ifdef SHM_MEMORY_MAPPING_SCHEME
int i;
#else /* MMAP_MEMORY_MAPPING_SCHEME */
char MapFile[20];
#endif /* MEMORY_MAPPING_SCHEME */
{
int proc;
INFORMATION_MESSAGE("Worker %d exiting...", worker_id);
for (proc = 0; proc < Yap_number_workers; proc++) {
if (proc != worker_id && Yap_worker_pid(proc) != 0) {
if (kill(Yap_worker_pid(proc), SIGKILL) != 0)
INFORMATION_MESSAGE("Can't kill process %d", Yap_worker_pid(proc));
else
INFORMATION_MESSAGE("Killing process %d", Yap_worker_pid(proc));
}
}
#ifdef YAPOR_COW
if (Yap_number_workers > 1) {
if (kill(Yap_master_worker, SIGINT) != 0)
INFORMATION_MESSAGE("Can't kill process %d", Yap_master_worker);
else
INFORMATION_MESSAGE("Killing process %d", Yap_master_worker);
}
#endif /* YAPOR_COW */
}
#ifdef SHM_MEMORY_MAPPING_SCHEME
#ifdef YAPOR_COW
i = 0;
#else
for (i = 0; i < Yap_number_workers + 1; i++)
#endif /* YAPOR_COW */
{
if (shmctl(shm_mapid[i], IPC_RMID, 0) == 0)
INFORMATION_MESSAGE("Removing shared memory segment %d", shm_mapid[i]);
else INFORMATION_MESSAGE("Can't remove shared memory segment %d", shm_mapid[i]);
}
#else /* MMAP_MEMORY_MAPPING_SCHEME */
strcpy(MapFile,"./mapfile");
#ifdef YAPOR_COW
itos(Yap_master_worker, &MapFile[9]);
#else /* YAPOR_COPY || YAPOR_SBA */
itos(Yap_worker_pid(0), &MapFile[9]);
#endif
if (remove(MapFile) == 0)
INFORMATION_MESSAGE("Removing mapfile \"%s\"", MapFile);
else INFORMATION_MESSAGE("Can't remove mapfile \"%s\"", MapFile);
#endif /* MEMORY_MAPPING_SCHEME */
void shm_map_memory(int id, int size, void *shmaddr) {
if (size > SHMMAX)
Yap_Error(FATAL_ERROR, TermNil, "maximum size for a shm segment exceeded (shm_map_memory)");
if ((shm_mapid[id] = shmget(IPC_PRIVATE, size, SHM_R|SHM_W)) == -1)
Yap_Error(FATAL_ERROR, TermNil, "shmget error (shm_map_memory)");
if (shmat(shm_mapid[id], shmaddr, 0) == (void *) -1)
Yap_Error(FATAL_ERROR, TermNil, "shmat error (shm_map_memory)");
return;
}
#endif /* MMAP_MEMORY_MAPPING_SCHEME */
void remap_memory(void) {
#ifdef YAPOR_COW
/* do nothing */
#endif /* YAPOR_COW */
#ifdef YAPOR_SBA
/* setup workers so that they have different areas */
long WorkerArea = worker_offset(1);
Yap_GlobalBase += worker_id * WorkerArea;
Yap_TrailBase += worker_id * WorkerArea;
Yap_LocalBase += worker_id * WorkerArea;
Yap_TrailTop += worker_id * WorkerArea;
#endif /* YAPOR_SBA */
#ifdef YAPOR_COPY
void *remap_addr;
long remap_offset;
long WorkerArea;
int i;
remap_addr = worker_area(0);
remap_offset = (char *)remap_addr - (char *)Yap_HeapBase;
WorkerArea = worker_offset(1);
#ifdef SHM_MEMORY_MAPPING_SCHEME
for (i = 0; i < Yap_number_workers; i++) {
if (shmdt(worker_area(i)) == -1)
Yap_Error(FATAL_ERROR, TermNil, "shmdt error (remap_memory)");
}
for (i = 0; i < Yap_number_workers; i++) {
worker_area(i) = remap_addr + ((Yap_number_workers + i - worker_id) % Yap_number_workers) * WorkerArea;
if(shmat(shm_mapid[i], worker_area(i), 0) == (void *) -1)
Yap_Error(FATAL_ERROR, TermNil, "shmat error (remap_memory)");
}
#else /* MMAP_MEMORY_MAPPING_SCHEME */
if (munmap(remap_addr, (size_t)(WorkerArea * Yap_number_workers)) == -1)
Yap_Error(FATAL_ERROR, TermNil, "munmap error (remap_memory)");
for (i = 0; i < Yap_number_workers; i++) {
worker_area(i) = remap_addr + ((Yap_number_workers + i - worker_id) % Yap_number_workers) * WorkerArea;
if (mmap(worker_area(i), (size_t)WorkerArea, PROT_READ|PROT_WRITE,
MAP_SHARED|MAP_FIXED, fd_mapfile, remap_offset + i * WorkerArea + extra_area) == (void *) -1)
Yap_Error(FATAL_ERROR, TermNil, "mmap error (remap_memory)");
}
#endif /* MEMORY_MAPPING_SCHEME */
for (i = 0; i < Yap_number_workers; i++) {
worker_offset(i) = worker_area(i) - worker_area(worker_id);
}
#endif /* YAPOR_COPY */
}
#endif /* YAPOR && !THREADS */
#endif /* YAPOR && !THREADS */

View File

@ -16,15 +16,9 @@
***************************/
#ifdef YAPOR
#ifdef SHM_MEMORY_MAPPING_SCHEME
void shm_map_memory(int, int, void *);
#else /* MMAP_MEMORY_MAPPING_SCHEME */
void open_mapfile(long);
void close_mapfile(void);
#endif /* MEMORY_MAPPING_SCHEME */
void map_memory(long, long, long, int);
void unmap_memory(void);
void remap_memory(void);
void Yap_init_optyap_memory(long, long, long, int);
void Yap_unmap_optyap_memory(void);
void Yap_remap_optyap_memory(void);
#endif /* YAPOR */

View File

@ -170,6 +170,7 @@ struct global_optyap_data{
int delayed_release_load;
int number_workers;
int worker_pid[MAX_WORKERS];
#ifdef YAPOR_COW
int master_worker;
#endif /* YAPOR_COW */
@ -225,9 +226,9 @@ struct global_optyap_data{
#define Yap_max_pages (Yap_optyap_data.pages.max_pages)
#define Yap_pages_void (Yap_optyap_data.pages.void_pages)
#define Yap_pages_or_fr (Yap_optyap_data.pages.or_frame_pages)
#define Yap_pages_qg_sol_fr (Yap_optyap_data.pages.query_goal_solution_frame_pages)
#define Yap_pages_qg_ans_fr (Yap_optyap_data.pages.query_goal_answer_frame_pages)
#define Yap_pages_or_fr (Yap_optyap_data.pages.or_frame_pages)
#define Yap_pages_qg_sol_fr (Yap_optyap_data.pages.query_goal_solution_frame_pages)
#define Yap_pages_qg_ans_fr (Yap_optyap_data.pages.query_goal_answer_frame_pages)
#define Yap_pages_tg_sol_fr (Yap_optyap_data.pages.table_subgoal_solution_frame_pages)
#define Yap_pages_tg_ans_fr (Yap_optyap_data.pages.table_subgoal_answer_frame_pages)
#define Yap_pages_tab_ent (Yap_optyap_data.pages.table_entry_pages)
@ -240,17 +241,17 @@ struct global_optyap_data{
#define Yap_pages_ans_hash (Yap_optyap_data.pages.answer_trie_hash_pages)
#define Yap_pages_gt_hash (Yap_optyap_data.pages.global_trie_hash_pages)
#define Yap_pages_susp_fr (Yap_optyap_data.pages.suspension_frame_pages)
#define Yap_scheduler_loop (Yap_optyap_data.scheduler_loop)
#define Yap_delayed_release_load (Yap_optyap_data.delayed_release_load)
#define Yap_number_workers (Yap_optyap_data.number_workers)
#define Yap_worker_pid(worker) (Yap_optyap_data.worker_pid[worker])
#define Yap_scheduler_loop (Yap_optyap_data.scheduler_loop)
#define Yap_delayed_release_load (Yap_optyap_data.delayed_release_load)
#define Yap_number_workers (Yap_optyap_data.number_workers)
#define Yap_worker_pid(worker) (Yap_optyap_data.worker_pid[worker])
#define Yap_master_worker (Yap_optyap_data.master_worker)
#define Yap_execution_time (Yap_optyap_data.execution_time)
#define Yap_best_times(time) (Yap_optyap_data.best_execution_times[time])
#define Yap_number_goals (Yap_optyap_data.number_of_executed_goals)
#define Yap_performance_mode (Yap_optyap_data.performance_mode)
#if THREADS
#define Get_Yap_root_cp() offset_to_cptr(Yap_optyap_data.root_choice_point_offset)
#define Get_Yap_root_cp() offset_to_cptr(Yap_optyap_data.root_choice_point_offset)
#define Set_Yap_root_cp(bptr) (Yap_optyap_data.root_choice_point_offset = cptr_to_offset(bptr))
#else
#define Yap_root_cp (Yap_optyap_data.root_choice_point)
@ -277,7 +278,7 @@ struct global_optyap_data{
#define Yap_locks_heap_access (Yap_optyap_data.locks.heap_access)
#define Yap_locks_alloc_block (Yap_optyap_data.locks.alloc_block)
#define Yap_branch(worker, depth) (Yap_optyap_data.branch[worker][depth])
#define Yap_parallel_execution_mode (Yap_optyap_data.parallel_execution_mode)
#define Yap_parallel_execution_mode (Yap_optyap_data.parallel_execution_mode)
#define Yap_answers (Yap_optyap_data.answers)
#define Yap_root_gt (Yap_optyap_data.root_global_trie)
#define Yap_root_tab_ent (Yap_optyap_data.root_table_entry)
@ -314,12 +315,32 @@ struct local_signals{
nodes_shared = 2,
copy_done = 3,
worker_ready = 4
} reply;
} reply_signal;
};
#endif /* YAPOR */
/**********************************************************
** Structs ma_h_inner_struct and ma_hash_entry **
**********************************************************/
#if (defined(TABLING) || !defined(YAPOR_COW)) && defined(MULTI_ASSIGNMENT_VARIABLES)
#define MAVARS_HASH_SIZE 512
typedef struct ma_h_entry {
CELL* addr;
struct ma_h_entry *next;
} ma_h_inner_struct;
typedef struct {
UInt timestmp;
struct ma_h_entry val;
} ma_hash_entry;
#endif /* (TABLING || !YAPOR_COW) && MULTI_ASSIGNMENT_VARIABLES */
/********************************
** Struct local_data **
********************************/
@ -367,6 +388,12 @@ struct local_data{
struct or_frame *top_or_frame_with_suspensions;
#endif /* YAPOR */
#endif /* TABLING */
#if (defined(TABLING) || !defined(YAPOR_COW)) && defined(MULTI_ASSIGNMENT_VARIABLES)
UInt ma_timestamp;
ma_h_inner_struct *ma_h_top;
ma_hash_entry ma_hash_table[MAVARS_HASH_SIZE];
#endif /* (TABLING || !YAPOR_COW) && MULTI_ASSIGNMENT_VARIABLES */
};
#define LOCAL_lock (LOCAL->lock)
@ -389,7 +416,7 @@ struct local_data{
#define Set_LOCAL_prune_request(cpt) (LOCAL->prune_request = cpt)
#endif
#define LOCAL_share_request (LOCAL->share_request)
#define LOCAL_reply_signal (LOCAL->share_signals.reply)
#define LOCAL_reply_signal (LOCAL->share_signals.reply_signal)
#define LOCAL_p_fase_signal (LOCAL->share_signals.P_fase)
#define LOCAL_q_fase_signal (LOCAL->share_signals.Q_fase)
#define LOCAL_lock_signals (LOCAL->share_signals.lock)
@ -412,8 +439,13 @@ struct local_data{
#define Set_LOCAL_top_cp_on_stack(cpt) (LOCAL->top_choice_point_on_stack = cpt)
#endif
#define LOCAL_top_susp_or_fr (LOCAL->top_or_frame_with_suspensions)
#define LOCAL_ma_timestamp (LOCAL->ma_timestamp)
#define LOCAL_ma_h_top (LOCAL->ma_h_top)
#define LOCAL_ma_hash_table (LOCAL->ma_hash_table)
#define REMOTE_lock(worker) (REMOTE[worker].lock)
#define REMOTE_load(worker) (REMOTE[worker].load)
#if THREADS
#define REMOTE_top_cp(worker) offset_to_cptr(REMOTE[worker].top_choice_point_offset)
@ -432,7 +464,7 @@ struct local_data{
#define Set_REMOTE_prune_request(worker,cp) (REMOTE[worker].prune_request = cp)
#endif
#define REMOTE_share_request(worker) (REMOTE[worker].share_request)
#define REMOTE_reply_signal(worker) (REMOTE[worker].share_signals.reply)
#define REMOTE_reply_signal(worker) (REMOTE[worker].share_signals.reply_signal)
#define REMOTE_p_fase_signal(worker) (REMOTE[worker].share_signals.P_fase)
#define REMOTE_q_fase_signal(worker) (REMOTE[worker].share_signals.Q_fase)
#define REMOTE_lock_signals(worker) (REMOTE[worker].share_signals.lock)

View File

@ -238,7 +238,7 @@ int q_share_work(int worker_p) {
OPTYAP_ERROR_CHECKING(q_share_work, LOCAL_top_cp != LOCAL_top_cp_on_stack);
OPTYAP_ERROR_CHECKING(q_share_work, YOUNGER_CP(B_FZ, LOCAL_top_cp));
YAPOR_ERROR_CHECKING(q_share_work, LOCAL_reply_signal != ready);
YAPOR_ERROR_CHECKING(q_share_work, LOCAL_reply_signal != worker_ready);
/* make sharing request */
LOCK_WORKER(worker_p);
@ -292,7 +292,7 @@ int q_share_work(int worker_p) {
sync_with_p:
#ifdef TABLING
REMOTE_reply_signal(worker_p) = ready;
REMOTE_reply_signal(worker_p) = worker_ready;
#else
REMOTE_reply_signal(worker_p) = copy_done;
#endif /* TABLING */

View File

@ -43,9 +43,9 @@ STD_PROTO(static inline void PUT_BUSY, (int));
static inline
void PUT_BUSY(int worker_num) {
LOCK(GLOBAL_LOCKS_bm_idle_workers);
BITMAP_delete(GLOBAL_bm_idle_workers, worker_num);
UNLOCK(GLOBAL_LOCKS_bm_idle_workers);
LOCK(Yap_locks_bm_idle_workers);
BITMAP_delete(Yap_bm_idle_workers, worker_num);
UNLOCK(Yap_locks_bm_idle_workers);
return;
}
@ -57,15 +57,15 @@ void PUT_BUSY(int worker_num) {
void make_root_choice_point(void) {
if (worker_id == 0) {
LOCAL_top_cp = GLOBAL_root_cp = OrFr_node(GLOBAL_root_or_fr) = B;
LOCAL_top_cp = Yap_root_cp = OrFr_node(Yap_root_or_fr) = B;
} else {
B = LOCAL_top_cp = GLOBAL_root_cp;
B = LOCAL_top_cp = Yap_root_cp;
B->cp_tr = TR = ((choiceptr) (worker_offset(0) + (CELL)(B)))->cp_tr;
}
B->cp_h = H0;
B->cp_ap = GETWORK;
B->cp_or_fr = GLOBAL_root_or_fr;
LOCAL_top_or_fr = GLOBAL_root_or_fr;
B->cp_or_fr = Yap_root_or_fr;
LOCAL_top_or_fr = Yap_root_or_fr;
LOCAL_load = 0;
LOCAL_prune_request = NULL;
BRANCH(worker_id, 0) = 0;
@ -86,7 +86,7 @@ int p_share_work(void) {
if (! BITMAP_member(OrFr_members(REMOTE_top_or_fr(worker_q)), worker_id) ||
B == REMOTE_top_cp(worker_q) ||
(LOCAL_load <= DELAYED_RELEASE_LOAD && OrFr_nearest_livenode(LOCAL_top_or_fr) == NULL)) {
(LOCAL_load <= Yap_delayed_release_load && OrFr_nearest_livenode(LOCAL_top_or_fr) == NULL)) {
/* refuse sharing request */
REMOTE_reply_signal(LOCAL_share_request) = no_sharing;
LOCAL_share_request = MAX_WORKERS;
@ -99,13 +99,13 @@ int p_share_work(void) {
if ((son = fork()) == 0) {
worker_id = worker_q; /* child becomes requesting worker */
LOCAL = REMOTE + worker_id;
LOCAL_reply_signal = ready;
LOCAL_reply_signal = worker_ready;
PUT_IN_REQUESTABLE(worker_id);
PUT_BUSY(worker_id);
return FALSE;
} else {
worker_pid(worker_q) = son;
Yap_worker_pid(worker_q) = son;
LOCAL_share_request = MAX_WORKERS;
PUT_IN_REQUESTABLE(worker_id);
@ -129,7 +129,7 @@ int q_share_work(int worker_p) {
/* make sharing request */
LOCK_WORKER(worker_p);
if (BITMAP_member(GLOBAL_bm_idle_workers, worker_p) ||
if (BITMAP_member(Yap_bm_idle_workers, worker_p) ||
REMOTE_share_request(worker_p) != MAX_WORKERS) {
/* worker p is idle or has another request */
UNLOCK_WORKER(worker_p);
@ -139,10 +139,10 @@ int q_share_work(int worker_p) {
UNLOCK_WORKER(worker_p);
/* wait for an answer */
while (LOCAL_reply_signal == ready);
while (LOCAL_reply_signal == worker_ready);
if (LOCAL_reply_signal == no_sharing) {
/* sharing request refused */
LOCAL_reply_signal = ready;
LOCAL_reply_signal = worker_ready;
return FALSE;
}
/* exit this process */

View File

@ -108,6 +108,8 @@ STD_PROTO(static inline qg_sol_fr_ptr CUT_prune_solution_frames, (qg_sol_fr_ptr,
** Engine Macros **
** ----------------------- */
#define worker_offset(X) ((Yap_number_workers + X - worker_id) % Yap_number_workers * Yap_worker_area_size)
#define LOCK_OR_FRAME(fr) LOCK(OrFr_lock(fr))
#define UNLOCK_OR_FRAME(fr) UNLOCK(OrFr_lock(fr))

View File

@ -87,15 +87,15 @@ reset_trail(tr_fr_ptr tr_top, tr_fr_ptr trp)
void make_root_choice_point(void) {
if (worker_id == 0) {
LOCAL_top_cp = GLOBAL_root_cp = OrFr_node(GLOBAL_root_or_fr) = B;
LOCAL_top_cp = Yap_root_cp = OrFr_node(Yap_root_or_fr) = B;
B->cp_h = H0;
B->cp_ap = GETWORK;
B->cp_or_fr = GLOBAL_root_or_fr;
B->cp_or_fr = Yap_root_or_fr;
} else {
B = LOCAL_top_cp = GLOBAL_root_cp;
B = LOCAL_top_cp = Yap_root_cp;
TR = B->cp_tr;
}
LOCAL_top_or_fr = GLOBAL_root_or_fr;
LOCAL_top_or_fr = Yap_root_or_fr;
LOCAL_load = 0;
LOCAL_prune_request = NULL;
BRANCH(worker_id, 0) = 0;
@ -121,7 +121,7 @@ void p_share_work(void) {
if (! BITMAP_member(OrFr_members(REMOTE_top_or_fr(worker_q)), worker_id) ||
B == REMOTE_top_cp(worker_q) ||
(LOCAL_load <= DELAYED_RELEASE_LOAD && OrFr_nearest_livenode(LOCAL_top_or_fr) == NULL)) {
(LOCAL_load <= Yap_delayed_release_load && OrFr_nearest_livenode(LOCAL_top_or_fr) == NULL)) {
/* refuse sharing request */
REMOTE_reply_signal(LOCAL_share_request) = no_sharing;
LOCAL_share_request = MAX_WORKERS;
@ -163,7 +163,7 @@ int q_share_work(int worker_p) {
/* make sharing request */
LOCK_WORKER(worker_p);
if (BITMAP_member(GLOBAL_bm_idle_workers, worker_p) ||
if (BITMAP_member(Yap_bm_idle_workers, worker_p) ||
REMOTE_share_request(worker_p) != MAX_WORKERS) {
/* worker p is idle or has another request */
UNLOCK_WORKER(worker_p);
@ -173,10 +173,10 @@ int q_share_work(int worker_p) {
UNLOCK_WORKER(worker_p);
/* wait for an answer */
while (LOCAL_reply_signal == ready);
while (LOCAL_reply_signal == worker_ready);
if (LOCAL_reply_signal == no_sharing) {
/* sharing request refused */
LOCAL_reply_signal = ready;
LOCAL_reply_signal = worker_ready;
return FALSE;
}
@ -207,8 +207,8 @@ int q_share_work(int worker_p) {
}
/* update registers and return */
/* REMOTE_reply_signal(worker_p) = ready; */
LOCAL_reply_signal = ready;
/* REMOTE_reply_signal(worker_p) = worker_ready; */
LOCAL_reply_signal = worker_ready;
PUT_IN_REQUESTABLE(worker_id);
TR = LOCAL_top_cp->cp_tr;
return TRUE;

View File

@ -11,20 +11,6 @@
** **
************************************************************************/
/* ----------------------- **
** Struct worker **
** ----------------------- */
extern struct worker{
void *worker_area[MAX_WORKERS];
long worker_offset[MAX_WORKERS];
} WORKER;
#define worker_area(W) (WORKER.worker_area[W])
#define worker_offset(W) (WORKER.worker_offset[W])
/* ------------------------- **
** Struct or_frame **
** ------------------------- */

View File

@ -53,21 +53,21 @@ static void share_private_nodes(int worker_q);
void make_root_choice_point(void) {
CACHE_REGS
if (worker_id == 0) {
SetOrFr_node(GLOBAL_root_or_fr, B);
SetOrFr_node(Yap_root_or_fr, B);
Set_LOCAL_top_cp(B);
Set_GLOBAL_root_cp(B);
Set_Yap_root_cp(B);
} else {
choiceptr imageB;
Set_LOCAL_top_cp(Get_GLOBAL_root_cp());
B = Get_GLOBAL_root_cp();
Set_LOCAL_top_cp(Get_Yap_root_cp());
B = Get_Yap_root_cp();
/*
this is tricky, we need to get the B from some other stack
and convert back to our own stack;
*/
OldLCL0 = LCL0;
LCL0 = FOREIGN_ThreadHandle(0).current_yaam_regs->LCL0_;
imageB = Get_GLOBAL_root_cp();
imageB = Get_Yap_root_cp();
/* we know B */
B->cp_tr = TR =
(tr_fr_ptr)((CELL)(imageB->cp_tr)+((CELL)OldLCL0-(CELL)LCL0));
@ -75,8 +75,8 @@ void make_root_choice_point(void) {
}
B->cp_h = H0;
B->cp_ap = GETWORK;
B->cp_or_fr = GLOBAL_root_or_fr;
LOCAL_top_or_fr = GLOBAL_root_or_fr;
B->cp_or_fr = Yap_root_or_fr;
LOCAL_top_or_fr = Yap_root_or_fr;
LOCAL_load = 0;
Set_LOCAL_prune_request(NULL);
BRANCH(worker_id, 0) = 0;
@ -97,9 +97,9 @@ void free_root_choice_point(void) {
#ifdef TABLING
Set_LOCAL_top_cp_on_stack((choiceptr) Yap_LocalBase);
#endif /* TABLING */
Set_GLOBAL_root_cp((choiceptr) Yap_LocalBase);
Set_Yap_root_cp((choiceptr) Yap_LocalBase);
Set_LOCAL_top_cp((choiceptr) Yap_LocalBase);
SetOrFr_node(GLOBAL_root_or_fr, (choiceptr) Yap_LocalBase);
SetOrFr_node(Yap_root_or_fr, (choiceptr) Yap_LocalBase);
return;
}
@ -110,7 +110,7 @@ int p_share_work() {
if (! BITMAP_member(OrFr_members(REMOTE_top_or_fr(worker_q)), worker_id) ||
B == REMOTE_top_cp(worker_q) ||
(LOCAL_load <= DELAYED_RELEASE_LOAD && OrFr_nearest_livenode(LOCAL_top_or_fr) == NULL)) {
(LOCAL_load <= Yap_delayed_release_load && OrFr_nearest_livenode(LOCAL_top_or_fr) == NULL)) {
/* refuse sharing request */
REMOTE_reply_signal(LOCAL_share_request) = no_sharing;
LOCAL_share_request = MAX_WORKERS;
@ -157,7 +157,7 @@ int q_share_work(int worker_p) {
/* make sharing request */
LOCK_WORKER(worker_p);
if (BITMAP_member(GLOBAL_bm_idle_workers, worker_p) ||
if (BITMAP_member(Yap_bm_idle_workers, worker_p) ||
REMOTE_share_request(worker_p) != MAX_WORKERS) {
/* worker p is idle or has another request */
UNLOCK_WORKER(worker_p);
@ -497,7 +497,7 @@ void share_private_nodes(int worker_q) {
#ifdef DEBUG_OPTYAP
{ dep_fr_ptr aux_dep_fr = LOCAL_top_dep_fr;
while(aux_dep_fr != GLOBAL_root_dep_fr) {
while(aux_dep_fr != Yap_root_dep_fr) {
choiceptr top_cp_on_branch;
top_cp_on_branch = DepFr_cons_cp(aux_dep_fr);
while (YOUNGER_CP(top_cp_on_branch, B)) {

View File

@ -414,7 +414,7 @@ static inline tg_sol_fr_ptr CUT_prune_tg_solution_frames(tg_sol_fr_ptr, int);
Yap_last_sg_fr = NULL; \
} \
if (Yap_check_sg_fr == SG_FR) \
GLOBAL_check_sg_fr = SgFr_previous(SG_FR)
Yap_check_sg_fr = SgFr_previous(SG_FR)
#else
#define insert_into_global_sg_fr_list(SG_FR)
#define remove_from_global_sg_fr_list(SG_FR)