userfunctions.c: In function ‘UserFunctions’:
userfunctions.c:69:33: error: ‘EulersNumber’ undeclared (first use in this function)
69 | AddUDF(env,"e","d",0,0,NULL,EulersNumber,"EulersNumber",NULL);
| ^~~~~~~~~~~~
userfunctions.c:69:33: note: each undeclared identifier is reported only once for each function it appears in
make: *** [makefile:91: userfunctions.o] Error 1
void UserFunctions(
Environment *env)
{
{
AddUDF(env,"e","d",0,0,NULL,EulersNumber,"EulersNumber",NULL);
}
#if MAC_XCD
#pragma unused(env)
#endif
}
#include <math.h>
void EulersNumber(
Environment *env,
UDFContext *udfc,
UDFValue *out)
{
out->floatValue = CreateFloat(env,exp(1.0));
}
void EulersNumber(Environment *,UDFContext *,UDFValue *);
The common practice is to create a file named EulersNumber.h, place the prototype in that file, and then place a #include "EulersNumber.h" within userfunctions.c.
gcc -o clips main.o -L. -lclips -lm
/usr/bin/ld: ./libclips.a(userfunctions.o): in function `UserFunctions':
userfunctions.c:(.text+0x2a): undefined reference to `EulersNumber'
collect2: error: ld returned 1 exit status
make: *** [makefile:94: clips] Error 1
#include <math.h>
void EulersNumber(
Environment *env,
UDFContext *udfc,
UDFValue *out)
{
out->floatValue = CreateFloat(env,exp(1.0));
}
void EulersNumber(Environment *,UDFContext *,UDFValue *);
#include "clips.h"
#include "EulersNumber.h"
void UserFunctions(Environment *);
/*********************************************************/
/* UserFunctions: Informs the expert system environment */
/* of any user defined functions. In the default case, */
/* there are no user defined functions. To define */
/* functions, either this function must be replaced by */
/* a function with the same name within this file, or */
/* this function can be deleted from this file and */
/* included in another file. */
/*********************************************************/
void UserFunctions(
Environment *env)
{
{
AddUDF(env,"e","d",0,0,NULL,EulersNumber,"EulersNumber",NULL);
}
#if MAC_XCD
#pragma unused(env)
#endif
--
You received this message because you are subscribed to the Google Groups "CLIPSESG" group.
To post to this group, send email to CLIP...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/CLIPSESG?hl=en
--> IF YOU NO LONGER WANT TO RECEIVE EMAIL <--
Visit this group at http://groups.google.com/group/CLIPSESG?hl=en
Click on "Edit my membership" link.
Select the "No Email" radio button.
Click the "Save these settings" button.
--> IF YOU WANT TO UNSUBSCRIBE <--
Visit this group at http://groups.google.com/group/CLIPSESG?hl=en
Sign in
Click on "Edit my membership" link.
Click the "Unsubscribe" button.
Note: This appears to be the most reliable way to unsubscribe
Alternately, send email to CLIPSESG-u...@googlegroups.com. You will receive an email which you must respond to as well to unsubscribe. Clicking the link mentioned in the unsubscribe reply does not appear to work reliably.
---
You received this message because you are subscribed to the Google Groups "CLIPSESG" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clipsesg+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/clipsesg/3475357e-3f7b-49b3-adec-5fcf2f41e7fen%40googlegroups.com.
gcc -o clips main.o -L. -lclips -lm
/usr/bin/ld: ./libclips.a(geographic_region.o): in function `geographic_region':
geographic_region.c:(.text+0x79): undefined reference to `shm_open'
collect2: error: ld returned 1 exit status
make: *** [makefile:94: clips] Error 1
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <unistd.h>
#include <string.h>
#include "clips.h"
#include "geographic_region.h"
void UserFunctions(Environment *);
void UserFunctions(
Environment *env)
{
{
AddUDF(env,"geographic_region","sy",0,0,NULL,geographic_region,"geographic_region",NULL);
}
#if MAC_XCD
#pragma unused(env)
#endif
}
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <unistd.h>
#include <string.h>
#include "geographic_region.h"
#define SHARED_MEM_NAME "/jims"
#define EXIT_SUCCESS 0
struct shared_memory {
char region[14];
int n;
float tt[2000][2000];
int pa_bt[2000];
};
//int main(int argc, char **argv) {
void geographic_region(
Environment *env,
UDFContext *udfc,
UDFValue *out)
{
printf("Entering geographic_region.c\n");
struct shared_memory *shared_mem_ptr;
int fd_shm;
FILE *fromR;
char region[14];
int n;
float times[2000];
int pa_bt[2000];
/* // Establish the shared memory. */
if ((fd_shm = shm_open (SHARED_MEM_NAME, O_RDWR | O_CREAT | O_EXCL, 0666)) == -1)
perror ("shm_open");
if (ftruncate (fd_shm, sizeof (struct shared_memory)) == -1)
perror("ftruncate");
if ((shared_mem_ptr = mmap (NULL, sizeof (struct shared_memory), PROT_READ | PROT_WRITE, MAP_SHARED,
fd_shm, 0)) == MAP_FAILED)
perror("mmap");
/* // Write the R-generated OSRM matrix into shared memory. */
fromR = fopen("time_matrix", "r");
fscanf(fromR, "%s", region);
sprintf(shared_mem_ptr -> region, "%s", region);
printf("%s\n", region);
fscanf(fromR, "%d", &n);
shared_mem_ptr -> n = n;
for(int i = 0; i < n; i++) {
for (int j = 0 ; j < n; j++) {
fscanf(fromR, "%f", ×[j]);
shared_mem_ptr -> tt[i][j] = times[j];
}
}
for(int i = 0; i < n; i++) {
fscanf(fromR, "%d", &pa_bt[i]);
shared_mem_ptr -> pa_bt[i] = pa_bt[i];
printf("%d\n", pa_bt[i]);
}
// return EXIT_SUCCESS;
out->lexemeValue = CreateString(env, region);
}
#include "clips.h"
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <unistd.h>
#include <string.h>
void geographic_region(Environment *,UDFContext *,UDFValue *)
To view this discussion on the web visit https://groups.google.com/d/msgid/clipsesg/321b02e3-3567-4046-a632-681775d6bdf7n%40googlegroups.com.
shm_open: Too many open files
mmap: Bad file descriptor
Segmentation fault (core dumped)
(travel_time 888653 1287831)
(travel_time 1287831 888653)
(defrule R1
(SP_bt_avail ?bt ?bt_dow ?bt_setting ?bt_start ?bt_end)
(test (eq ?bt 2243859))
(SP_pa_avail ?pa ?pa_dow ?pa_setting ?pa_start ?pa_end)
(test (eq ?pa_dow ?bt_dow))
=>
(printout t "Travel Time = " (travel_time ?bt ?pa) crlf)
(printout t "Found pa " ?pa " " ?pa_dow " " ?pa_setting " " ?pa_start " " ?pa_end crlf)
(printout t "Found bt " ?bt " " ?bt_dow " " ?bt_setting " " ?bt_start " " ?bt_end crlf))
In the C code I do ummap the Posix shared memory segment.
Does CLIPS internally start a great number of executions of a rule such as R1 and then not conclude them for some time, leaving too many open files?
Is there a means to control such a situation if indeed that is what is happening?
Thank you
To view this discussion on the web visit https://groups.google.com/d/msgid/clipsesg/39e27e67-03e3-4e83-8f2c-4bce668a4c07n%40googlegroups.com.
/home/ubuntu/clips/clips_core_source_640/core/clips
(load-facts "/home/ubuntu/Graphics/ABS_Scheduling_Optimization/intermediate_files/facts_in")
(defrule R1
(SP_bt_avail ?bt ?bt_dow ?bt_setting ?bt_start ?bt_end)
(SP_pa_avail ?pa ?pa_dow ?pa_setting ?pa_start ?pa_end)
(test (eq ?bt 2243859))
(test (eq ?pa_dow ?bt_dow))
=>
(bind ?tt (travel_time ?bt ?pa))
(printout t "Travel Time = " ?tt crlf)
(printout t ?bt " " ?pa crlf))
(run)
2243859 1863309
Unmapping result is 0
Travel Time = 59.0
2243859 1863185
Unmapping result is 0
Travel Time = 137.0
2243859 1862346
Unmapping result is 0
Travel Time = 96.0
2243859 1861660
Segmentation fault (core dumped)
(base) ubuntu@ip-172-31-11-209:~/clips/clips_core_source_640/core$
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <unistd.h>
#include <sys/types.h>
#include "travel_time.h"
#define SHARED_MEM_NAME "/jims"
struct shared_memory {
char region[14];
int n;
float tt[2000][2000];
int pa_bt[2000];
};
/* char* check() { */
/* printf("Entering check.\n"); */
/* return "Zone 27"; */
/* } */
/* float main(int argc, char *argv[]) { */
void travel_time(
Environment *env,
UDFContext *udfc,
UDFValue *out)
{
UDFValue from, to;
struct shared_memory *shared_mem_ptr;
int fd_shm;
FILE *fromR;
int n;
// int from, to;
/* char* check_return; */
/* check_return = check(); */
/* printf("Check Return %s\n", check_return); */
UDFFirstArgument(udfc,INTEGER_BIT,&from);
UDFNextArgument(udfc,INTEGER_BIT,&to);
long long From = from.integerValue->contents;
long long To = to.integerValue->contents;
long long F, T;
// Connect to the shared memory.
if ((fd_shm = shm_open (SHARED_MEM_NAME, O_RDONLY, 0666)) == -1)
perror("shm_open");
if ((shared_mem_ptr = mmap ( NULL, sizeof (struct shared_memory), PROT_READ, MAP_SHARED,
fd_shm, 0)) == MAP_FAILED)
perror("mmap");
// Determine the travel time.
n = shared_mem_ptr -> n;
// printf("The count n is %d\n", n);
for(int i = 0; i < n; i++) {
if(From == shared_mem_ptr -> pa_bt[i])
F = i;
if(To == shared_mem_ptr -> pa_bt[i])
T = i;
}
// printf("Indicies are from = %lld and to = %lld\n", F, T);
/* printf("Travel time is %f\n", shared_mem_ptr -> tt[from - 1][to - 1]); */
/* return shared_mem_ptr -> shared_mem_pr->tt[from - 1][to - 1]; */
out->floatValue = CreateFloat(env,shared_mem_ptr->tt[F - 1][T - 1]);
// munmap(void addr[.length], size_t length);
int result = munmap(NULL, sizeof (struct shared_memory));
printf("Unmapping result is %d\n", result);
}
To view this discussion on the web visit https://groups.google.com/d/msgid/clipsesg/28d5b302-b1cc-49fe-966e-fea0c758011en%40googlegroups.com.