Compare commits

..

No commits in common. "0e2be6c11b9e792d68e8a9fa6723cbad9f1d120c" and "8e908f867cd174163b0830f9b925831b9f524b21" have entirely different histories.

10 changed files with 417 additions and 1487 deletions

View File

@ -1,7 +1,7 @@
# $RCSfile: Makefile,v $ # $RCSfile: Makefile,v $
# $Revision: 1.2 $ # $Revision: 1.1 $
# $Name: $ # $Name: $
# $Date: 2005/06/26 23:04:11 $ # $Date: 2005/01/24 23:24:30 $
# $Author: agibert $ # $Author: agibert $
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
@ -10,7 +10,7 @@
SUBDIRS := include lib util demo doc SUBDIRS := include lib util doc
FILE_DOC := *.txt FILE_DOC := *.txt

View File

@ -1,7 +1,7 @@
# $RCSfile: ReleaseNotes.txt,v $ # $RCSfile: ReleaseNotes.txt,v $
# $Revision: 2.1 $ # $Revision: 2.0 $
# $Name: $ # $Name: $
# $Date: 2005/06/27 00:17:36 $ # $Date: 2005/01/24 23:58:23 $
# $Author: agibert $ # $Author: agibert $
@ -9,13 +9,11 @@
------------------------------------------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------------------------------------------------
LibShMem V 2.0.0 - A. Gibert - xx/06/05 LibShMem V 2.0.0 - A. Gibert - xx/02/05
------------------------------------------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------------------------------------------------
All: This new LibShMem branch (2.0.x) support the new LibNode branch (2.1.x), All: This new LibShMem branch (2.0.x) support the new LibShMem branch (2.1.x),
LibShMem: Add HP-UX 11 support, LibShMem: ...
Improve Manager structure in a more LibNode 2 way,
SMDemo0: Add a new demo !

View File

@ -1,10 +1,6 @@
SRC := smdemo0.c smdemo0_snd.c smdemo0_rcv.c SRC := smdemo0.c
TARGETS := smdemo0 smdemo0-c smdemo0-static smdemo0-static-c \ TARGETS := smdemo0 smdemo0-c smdemo0-static smdemo0-static-c
smdemo0_snd smdemo0_snd-c smdemo0_snd-static smdemo0_snd-static-c \ FILE_BIN := smdemo0 smdemo0-c smdemo0-static smdemo0-static-c
smdemo0_rcv smdemo0_rcv-c smdemo0_rcv-static smdemo0_rcv-static-c
FILE_BIN := smdemo0 smdemo0-c smdemo0-static smdemo0-static-c \
smdemo0_snd smdemo0_snd-c smdemo0_snd-static smdemo0_snd-static-c \
smdemo0_rcv smdemo0_rcv-c smdemo0_rcv-static smdemo0_rcv-static-c
FILE_LIB := smdemo0.dat FILE_LIB := smdemo0.dat
@ -14,12 +10,12 @@ include ../Makefile.rule
DEP_STATIC += ../lib/libshmem.a ../../libnode/lib/libnode.a DEP_STATIC += ../lib/libnode.a
DEP_DYNAMIC += ../lib/libshmem.so ../../libnode/lib/libnode.so DEP_DYNAMIC += ../lib/libnode.so
INCLUDE += -I . -I ../include -I ../../libnode/include INCLUDE += -I . -I ../include
LIBDIR += -L . -L ../lib -L ../../libnode/lib LIBDIR += -L . -L ../lib
LIB_STATIC += ../lib/libshmem.a ../../libnode/lib/libnode.a -ldl LIB_STATIC += ../lib/libnode.a -ldl
LIB_DYNAMIC += -lshmem -lnode -ldl LIB_DYNAMIC += -lnode -ldl
CFLAGS += -rdynamic CFLAGS += -rdynamic
ifdef _LIBVER_SUPPORT ifdef _LIBVER_SUPPORT
@ -56,26 +52,3 @@ smdemo0-static: smdemo0.c $(DEP_STATIC)
smdemo0-static-c: smdemo0.c $(DEP_STATIC) smdemo0-static-c: smdemo0.c $(DEP_STATIC)
$(CC) -o $@ $(CFLAGS) $(ND_CHECK_FLAGS) $(INCLUDE) $< $(LIB_STATIC) $(CC) -o $@ $(CFLAGS) $(ND_CHECK_FLAGS) $(INCLUDE) $< $(LIB_STATIC)
smdemo0_snd: smdemo0_snd.c $(DEP_DYNAMIC)
$(CC) -o $@ $(CFLAGS) $(ND_NOCHECK_FLAGS) $(INCLUDE) $(LIBDIR) $(LIB_DYNAMIC) $<
smdemo0_snd-c: smdemo0_snd.c $(DEP_DYNAMIC)
$(CC) -o $@ $(CFLAGS) $(ND_CHECK_FLAGS) $(INCLUDE) $(LIBDIR) $(LIB_DYNAMIC) $<
smdemo0_snd-static: smdemo0_snd.c $(DEP_STATIC)
$(CC) -o $@ $(CFLAGS) $(ND_NOCHECK_FLAGS) $(INCLUDE) $< $(LIB_STATIC)
smdemo0_snd-static-c: smdemo0_snd.c $(DEP_STATIC)
$(CC) -o $@ $(CFLAGS) $(ND_CHECK_FLAGS) $(INCLUDE) $< $(LIB_STATIC)
smdemo0_rcv: smdemo0_rcv.c $(DEP_DYNAMIC)
$(CC) -o $@ $(CFLAGS) $(ND_NOCHECK_FLAGS) $(INCLUDE) $(LIBDIR) $(LIB_DYNAMIC) $<
smdemo0_rcv-c: smdemo0_rcv.c $(DEP_DYNAMIC)
$(CC) -o $@ $(CFLAGS) $(ND_CHECK_FLAGS) $(INCLUDE) $(LIBDIR) $(LIB_DYNAMIC) $<
smdemo0_rcv-static: smdemo0_rcv.c $(DEP_STATIC)
$(CC) -o $@ $(CFLAGS) $(ND_NOCHECK_FLAGS) $(INCLUDE) $< $(LIB_STATIC)
smdemo0_rcv-static-c: smdemo0_rcv.c $(DEP_STATIC)
$(CC) -o $@ $(CFLAGS) $(ND_CHECK_FLAGS) $(INCLUDE) $< $(LIB_STATIC)

View File

@ -1,380 +0,0 @@
/*---------------------------------------------------------------------------------*/
/* $RCSfile: smdemo0.c,v $ */
/*---------------------------------------------------------------------------------*/
/* $Revision: 1.1 $ */
/* $Name: $ */
/* $Date: 2005/06/26 23:16:38 $ */
/* $Author: agibert $ */
/*---------------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------------*/
/* This file is a program test of libshmem */
/* */
/* LibShMem is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU Lesser General Public Licence as published by */
/* the Free Software Foundation; either version 2.1 of the License, or */
/* (at your option) any later version. */
/* */
/* LibShMem is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU Lesser General Public License for more details. */
/* */
/* You should have received a copy of the GNU Lesser General Public License */
/* along with LibShMem; if not, write to the Free Software */
/* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
/*---------------------------------------------------------------------------------*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <unistd.h>
#include <errno.h>
#include <node.h>
#ifndef SM_MODE
# define SM_MODE 0 /* Utilisation des API sécurisés */
#endif
#include <shmem.h>
#define LOG_ERROR 10
#define LOG_WARNING 20
#define LOG_INFO 30
#define LOG_TRACE 40
#define FATHER_ID 0
#define SON_SND_ID 1
#define SON_SND_NAME "snd"
#define SON_RCV_ID 2
#define SON_RCV_NAME "rcv"
#define INST_MAX 256
void Log_Print( int, int, int, int, char *, ...);
int Do_Fork_Exec( char **, int, int, int, int *, int);
void Make_Son_Cmd_Name( char *, char *, char *);
int main( int , char **);
void Log_Print( int Log_Level, int Verbose_Level, int Proc_Id, int Inst_Id, char *Format_Str, ...)
{
va_list args;
char *prompt[] = { "father", "snd", "rcv"};
int fmt_size = 255;
char fmt[ fmt_size + 1];
if( Log_Level <= Verbose_Level)
{
va_start( args, Format_Str);
if( Proc_Id == FATHER_ID)
{
snprintf( fmt, fmt_size, "%s: %s", prompt[Proc_Id], Format_Str);
}
else
{
snprintf( fmt, fmt_size, "%s%02d : %s", prompt[Proc_Id], Inst_Id, Format_Str);
}
vfprintf( stderr, fmt, args);
fflush( stderr);
va_end( args);
}
}
int Do_Fork_Exec( char **ArgV_Tab, int Proc_Id, int Inst_Id, int Dir, int Pipe_Desc[2], int Verbose_Level)
{
pid_t pid;
int rc;
char cmd[1024] = "";
int i;
for( i = 0; ArgV_Tab[i] != NULL; i++)
{
if( i > 0)
{
strcat( cmd, " ");
}
strcat( cmd, ArgV_Tab[i]);
}
Log_Print( LOG_TRACE, Verbose_Level, FATHER_ID, 0, "Forking Inst_Id: (%d) Dir: (%d) Cmd: [%s]...\n", Inst_Id, Dir, cmd);
switch( pid = fork())
{
case 0:
{
Log_Print( LOG_INFO, Verbose_Level, Proc_Id, Inst_Id, "PId: (%d) PPId: (%d) Exec_File: [%s]\n", getpid(), getppid(), ArgV_Tab[0]);
if( ( rc = close( Pipe_Desc[ 1 - Dir])) == -1)
{
Log_Print( LOG_ERROR, Verbose_Level, Proc_Id, Inst_Id, "close() failed: (%d) !\n", errno);
exit( -1);
}
if( ( rc = dup2( Pipe_Desc[ Dir], Dir)) == -1)
{
Log_Print( LOG_ERROR, Verbose_Level, Proc_Id, Inst_Id, "dup2() failed: (%d) !\n", errno);
exit( -1);
}
if( ( rc = execv( ArgV_Tab[0], ArgV_Tab)) == -1)
{
Log_Print( LOG_ERROR, Verbose_Level, Proc_Id, Inst_Id, "execv() failed: (%d) !\n", errno);
exit( -1);
}
exit(-1);
}
case -1:
{
Log_Print( LOG_ERROR, Verbose_Level, FATHER_ID, Inst_Id, "fork() failed: (%d) !\n", errno);
return( -1);
}
default:
{
Log_Print( LOG_INFO, Verbose_Level, FATHER_ID, Inst_Id, "PId: (%d) Son_PId: (%d)\n", getpid(), pid);
return( 0);
}
}
}
void Make_Son_Cmd_Name( char *Son_Cmd_Name, char *Father_Cmd_Name, char *Son_Name)
{
char *ptr;
if( ( ptr = strstr( Father_Cmd_Name, "-")) == NULL)
{
ptr = Father_Cmd_Name + strlen( Father_Cmd_Name);
}
strncpy( Son_Cmd_Name, Father_Cmd_Name, ( ptr - Father_Cmd_Name));
Son_Cmd_Name[ ( ptr - Father_Cmd_Name)] = '\0';
strcat( Son_Cmd_Name, "_");
strcat( Son_Cmd_Name, Son_Name);
strcat( Son_Cmd_Name, ptr);
}
int main( int ArgC, char **ArgV)
{
char *Heap_Name;
int Inst_Nb;
int Chunk_Nb;
size_t Chunk_Size;
int Verbose_Level = 30;
SMT_Heap *heap_ptr;
size_t heap_size = 1024;
int locked;
SMT_Status status;
int rc;
int pipe_desc[2];
pid_t pid;
char *ptr;
char *argv_tab[10];
char son_cmd[256];
char inst_id_str[32];
char chunk_nb_str[32];
char chunk_size_str[32];
char verbose_level_str[32];
int inst_id;
short error = 0;
if( ArgC != 6)
{
Log_Print( LOG_ERROR, Verbose_Level, FATHER_ID, 0, "Usage: %s Inst_Nb Heap_Name Chunck_Nb Chunk_Size Verbose_Level\n", ArgV[0]);
exit( -1);
}
else
{
Inst_Nb = atoi( ArgV[1]);
Heap_Name = ArgV[2];
Chunk_Nb = atoi( ArgV[3]);
Chunk_Size = atoi( ArgV[4]);
Verbose_Level = atoi( ArgV[5]);
if( Inst_Nb > INST_MAX)
{
Log_Print( LOG_ERROR, Verbose_Level, FATHER_ID, 0, "Inst_Nb: (%d) > (%d) !\n", Inst_Nb, INST_MAX);
exit( -1);
}
Log_Print( LOG_INFO, Verbose_Level, FATHER_ID, 0, "Inst_Nb: (%d) Heap_Name: [%s] Chunck_Nb: (%d) Chunck_Size: (%d) Verbose_Level: (%d)...\n",
Inst_Nb, Heap_Name, Chunk_Nb, Chunk_Size, Verbose_Level);
}
if( ( status = SM_Library_Open( 0, NULL, ( SMD_OPEN | SMD_DEBUG_ALL))) != SMS_OK)
{
Log_Print( LOG_ERROR, Verbose_Level, FATHER_ID, 0, "Can't open LibShMem (%d) !\n", status);
exit( -1);
}
Log_Print( LOG_TRACE, Verbose_Level, FATHER_ID, 0, "LibShMem opened !\n");
if( ( status = SM_Heap_Open( Heap_Name, &heap_ptr, heap_size, ( SMD_OPEN | SMD_CREATE | SMD_NO_LOCK), &locked)) != SMS_OK)
{
Log_Print( LOG_ERROR, Verbose_Level, FATHER_ID, 0, "Can't create heap (%d) !\n", status);
}
else
{
Log_Print( LOG_TRACE, Verbose_Level, FATHER_ID, 0, "Heap opened !\n");
for( inst_id = 0, error = 0; ( inst_id < Inst_Nb) && ( error == 0); inst_id++)
{
if( pipe( pipe_desc) == -1)
{
Log_Print( LOG_ERROR, Verbose_Level, FATHER_ID, 0, "Con't open pipe (%d) !\n", errno);
error = 1;
}
else
{
argv_tab[0] = son_cmd;
Make_Son_Cmd_Name( argv_tab[0], ArgV[0], SON_SND_NAME);
argv_tab[1] = inst_id_str;
sprintf( argv_tab[1], "%d", inst_id);
argv_tab[2] = Heap_Name;
argv_tab[3] = chunk_nb_str;
sprintf( argv_tab[3], "%d", Chunk_Nb);
argv_tab[4] = chunk_size_str;
sprintf( argv_tab[4], "%d", Chunk_Size);
argv_tab[5] = verbose_level_str;
sprintf( argv_tab[5], "%d", Verbose_Level);
argv_tab[6] = NULL;
if( Do_Fork_Exec( argv_tab, SON_SND_ID, inst_id, 1, pipe_desc, Verbose_Level) == -1)
{
error = 1;
}
else
{
argv_tab[0] = son_cmd;
Make_Son_Cmd_Name( argv_tab[0], ArgV[0], SON_RCV_NAME);
argv_tab[1] = inst_id_str;
sprintf( argv_tab[1], "%d", inst_id);
argv_tab[2] = Heap_Name;
argv_tab[3] = verbose_level_str;
sprintf( argv_tab[3], "%d", Verbose_Level);
argv_tab[4] = NULL;
if( Do_Fork_Exec( argv_tab, SON_RCV_ID, inst_id, 0, pipe_desc, Verbose_Level) == -1)
{
error = 1;
}
else
{
if( ( rc = close( pipe_desc[ 0])) == -1)
{
Log_Print( LOG_ERROR, Verbose_Level, FATHER_ID, 0, "close() pipe[0] failed: (%d)\n", errno);
}
if( ( rc = close( pipe_desc[ 1])) == -1)
{
Log_Print( LOG_ERROR, Verbose_Level, FATHER_ID, 0, "close() pipe[1] failed: (%d)\n", errno);
}
}
}
}
}
if( error == 0)
{
Log_Print( LOG_TRACE, Verbose_Level, FATHER_ID, 0, "Waiting sons to complet...\n");
for( inst_id = 0; inst_id < ( Inst_Nb * 2); inst_id++)
{
pid = wait( NULL);
Log_Print( LOG_TRACE, Verbose_Level, FATHER_ID, 0, "Son PId: (%d) exited !\n", pid);
}
}
if( ( ( status = SM_Heap_Lock( heap_ptr, SMD_WRITE, &locked)) != SMS_OK) && ( locked == TRUE))
{
Log_Print( LOG_ERROR, Verbose_Level, FATHER_ID, 0, "Can't lock heap (%d) !\n", status);
}
else
{
if( ( status = SM_Heap_Close( heap_ptr)) != SMS_OK)
{
Log_Print( LOG_ERROR, Verbose_Level, FATHER_ID, 0, "Can't close heap (%d) !\n", status);
}
else
{
Log_Print( LOG_TRACE, Verbose_Level, FATHER_ID, 0, "Heap closed !\n");
}
}
}
if( ( status = SM_Library_Close( SMD_CLOSE)) != SMS_OK)
{
Log_Print( LOG_ERROR, Verbose_Level, FATHER_ID, 0, "Can't close LibShMem (%d) !\n", status);
exit( -1);
}
else
{
Log_Print( LOG_TRACE, Verbose_Level, FATHER_ID, 0, "LibShMem closed !\n");
}
exit( 0);
}

View File

@ -1,204 +0,0 @@
/*---------------------------------------------------------------------------------*/
/* $RCSfile: smdemo0_rcv.c,v $ */
/*---------------------------------------------------------------------------------*/
/* $Revision: 1.1 $ */
/* $Name: $ */
/* $Date: 2005/06/26 23:16:38 $ */
/* $Author: agibert $ */
/*---------------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------------*/
/* This file is a program test of libshmem */
/* */
/* LibShMem is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU Lesser General Public Licence as published by */
/* the Free Software Foundation; either version 2.1 of the License, or */
/* (at your option) any later version. */
/* */
/* LibShMem is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU Lesser General Public License for more details. */
/* */
/* You should have received a copy of the GNU Lesser General Public License */
/* along with LibShMem; if not, write to the Free Software */
/* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
/*---------------------------------------------------------------------------------*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <unistd.h>
#include <errno.h>
#include <node.h>
#ifndef SM_MODE
# define SM_MODE 0 /* Utilisation des API sécurisés */
#endif
#include <shmem.h>
#define LOG_ERROR 10
#define LOG_WARNING 20
#define LOG_INFO 30
#define LOG_TRACE 40
void Log_Print( int, int, int, char *, ...);
int main( int, char **);
void Log_Print( int Log_Level, int Verbose_Level, int Inst_Id, char *Format_Str, ...)
{
va_list args;
char *prompt = "rcv";
int fmt_size = 255;
char fmt[fmt_size + 1];
if( Log_Level <= Verbose_Level)
{
va_start( args, Format_Str);
snprintf( fmt, fmt_size, "%s%02d : %s", prompt, Inst_Id, Format_Str);
vfprintf( stderr, fmt, args);
fflush( stderr);
va_end( args);
}
}
int main( int ArgC, char **ArgV)
{
int Inst_Id;
char *Heap_Name;
int Verbose_Level = 30;
SMT_Heap *heap_ptr;
int locked;
SMT_Status status = SMS_OK;
char *chunk_ptr;
int chunk_id = 0;
char input_str[100];
size_t input_size = 99;
if( ArgC != 4)
{
Log_Print( LOG_ERROR, Verbose_Level, 0, "Usage: %s Inst_Id Heap_Name Verbose_Level\n", ArgV[0]);
exit( -1);
}
else
{
Inst_Id = atoi( ArgV[1]);
Heap_Name = ArgV[2];
Verbose_Level = atoi( ArgV[3]);
Log_Print( LOG_INFO, Verbose_Level, Inst_Id, "Inst_Id: (%d) Heap_Name: [%s] Verbose_Level: (%d)...\n",
Inst_Id, Heap_Name, Verbose_Level);
fflush( stderr);
}
if( ( status = SM_Library_Open( 0, NULL, ( SMD_OPEN | SMD_DEBUG_ALL))) != SMS_OK)
{
Log_Print( LOG_ERROR, Verbose_Level, Inst_Id, "Can't open LibShMem (%d) !\n", status);
exit( -1);
}
Log_Print( LOG_TRACE, Verbose_Level, Inst_Id, "LibShMem opened !\n");
if( ( status = SM_Heap_Open( Heap_Name, &heap_ptr, 0, ( SMD_OPEN | SMD_NO_LOCK), &locked)) != SMS_OK)
{
Log_Print( LOG_ERROR, Verbose_Level, Inst_Id, "Can't open heap (%d) !\n", status);
}
else
{
Log_Print( LOG_TRACE, Verbose_Level, Inst_Id, "Heap opened !\n");
while( ( fgets( input_str, input_size, stdin) != NULL) && ( status == SMS_OK))
{
if( ( chunk_ptr = (char *)atol( input_str)) == NULL)
{
Log_Print( LOG_ERROR, Verbose_Level, Inst_Id, "Garbage on stdin [%s], skiping !\n", input_str);
}
else
{
Log_Print( LOG_TRACE, Verbose_Level, Inst_Id, "Received message: [%s] Id: (%d) Address: (%lu)\n", chunk_ptr, chunk_id, chunk_ptr);
chunk_id++;
if( ( ( status = SM_Heap_Lock( heap_ptr, SMD_WRITE, &locked)) != SMS_OK) && ( locked == TRUE))
{
Log_Print( LOG_ERROR, Verbose_Level, Inst_Id, "Can't lock heap (%d) !\n", status);
}
else
{
if( ( status = SM_Chunk_Free( heap_ptr, chunk_ptr)) != SMS_OK)
{
Log_Print( LOG_ERROR, Verbose_Level, Inst_Id, "Can't free chunk (%d) !\n", status);
}
else
{
Log_Print( LOG_TRACE, Verbose_Level, Inst_Id, "Chunk: (%lu) freed !\n", chunk_ptr);
if( ( status = SM_Heap_Unlock( heap_ptr)) != SMS_OK)
{
Log_Print( LOG_ERROR, Verbose_Level, Inst_Id, "Can't unlock heap (%d) !\n", status);
}
}
}
}
}
Log_Print( LOG_INFO, Verbose_Level, Inst_Id, "Number of message received: (%d) !\n", chunk_id);
if( ( ( status = SM_Heap_Lock( heap_ptr, SMD_WRITE, &locked)) != SMS_OK) && ( locked == TRUE))
{
Log_Print( LOG_ERROR, Verbose_Level, Inst_Id, "Can't lock heap (%d) !\n", status);
}
else
{
if( ( status = SM_Heap_Close( heap_ptr)) != SMS_OK)
{
Log_Print( LOG_ERROR, Verbose_Level, Inst_Id, "Can't close heap (%d) !\n", status);
}
else
{
Log_Print( LOG_TRACE, Verbose_Level, Inst_Id, "Heap closed !\n");
}
}
}
if( ( status = SM_Library_Close( SMD_CLOSE)) != SMS_OK)
{
Log_Print( LOG_ERROR, Verbose_Level, Inst_Id, "Can't close LibShMem (%d) !\n", status);
exit( -1);
}
else
{
Log_Print( LOG_TRACE, Verbose_Level, Inst_Id, "LibShMem closed !\n");
}
exit( 0);
}

View File

@ -1,204 +0,0 @@
/*---------------------------------------------------------------------------------*/
/* $RCSfile: smdemo0_snd.c,v $ */
/*---------------------------------------------------------------------------------*/
/* $Revision: 1.1 $ */
/* $Name: $ */
/* $Date: 2005/06/26 23:16:38 $ */
/* $Author: agibert $ */
/*---------------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------------*/
/* This file is a program test of libshmem */
/* */
/* LibShMem is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU Lesser General Public Licence as published by */
/* the Free Software Foundation; either version 2.1 of the License, or */
/* (at your option) any later version. */
/* */
/* LibShMem is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU Lesser General Public License for more details. */
/* */
/* You should have received a copy of the GNU Lesser General Public License */
/* along with LibShMem; if not, write to the Free Software */
/* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
/*---------------------------------------------------------------------------------*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <unistd.h>
#include <errno.h>
#include <node.h>
#ifndef SM_MODE
# define SM_MODE 0 /* Utilisation des API sécurisés */
#endif
#include <shmem.h>
#define LOG_ERROR 10
#define LOG_WARNING 20
#define LOG_INFO 30
#define LOG_TRACE 40
void Log_Print( int, int, int, char *, ...);
int main( int ArgC, char **ArgV);
void Log_Print( int Log_Level, int Verbose_Level, int Inst_Id, char *Format_Str, ...)
{
va_list args;
char *prompt = "snd";
int fmt_size = 255;
char fmt[ fmt_size + 1];
if( Log_Level <= Verbose_Level)
{
va_start( args, Format_Str);
snprintf( fmt, fmt_size, "%s%02d : %s", prompt, Inst_Id, Format_Str);
vfprintf( stderr, fmt, args);
fflush( stderr);
va_end( args);
}
}
int main( int ArgC, char **ArgV)
{
int Inst_Id;
char *Heap_Name;
int Chunk_Nb;
size_t Chunk_Size;
int Verbose_Level = 30;
SMT_Heap *heap_ptr;
size_t heap_size = 1024;
int locked;
SMT_Status status;
char *chunk_ptr;
int chunk_id;
if( ArgC != 6)
{
Log_Print( LOG_ERROR, Verbose_Level, 0, "Usage: %s Inst_Id Heap_Name Chunck_Nb Chunk_Size Verbose_Level\n", ArgV[0]);
exit( -1);
}
else
{
Inst_Id = atoi( ArgV[1]);
Heap_Name = ArgV[2];
Chunk_Nb = atoi( ArgV[3]);
Chunk_Size = atoi( ArgV[4]);
Verbose_Level = atoi( ArgV[5]);
Log_Print( LOG_INFO, Verbose_Level, Inst_Id, "Inst_Id: (%d) Heap_Name: [%s] Chunck_Nb: (%d) Chunck_Size: (%d) Verbose_Level: (%d)...\n",
Inst_Id, Heap_Name, Chunk_Nb, Chunk_Size, Verbose_Level);
}
if( ( status = SM_Library_Open( 0, NULL, ( SMD_OPEN | SMD_DEBUG_ALL))) != SMS_OK)
{
Log_Print( LOG_ERROR, Verbose_Level, Inst_Id, "Can't open LibShMem (%d) !\n", status);
exit( -1);
}
Log_Print( LOG_TRACE, Verbose_Level, Inst_Id, "LibShMem opened !\n");
if( ( status = SM_Heap_Open( Heap_Name, &heap_ptr, heap_size, ( SMD_OPEN | SMD_NO_LOCK), &locked)) != SMS_OK)
{
Log_Print( LOG_ERROR, Verbose_Level, Inst_Id, "Can't open heap (%d) !\n", status);
}
else
{
Log_Print( LOG_TRACE, Verbose_Level, Inst_Id, "Heap opened !\n");
for( chunk_id = 0; ( chunk_id < Chunk_Nb) && ( status == SMS_OK); chunk_id++)
{
if( ( ( status = SM_Heap_Lock( heap_ptr, SMD_WRITE, &locked)) != SMS_OK) && ( locked == TRUE))
{
Log_Print( LOG_ERROR, Verbose_Level, Inst_Id, "Can't lock heap (%d) !\n", status);
}
else
{
if( ( status = SM_Chunk_Alloc( heap_ptr, Chunk_Size, (void **)&chunk_ptr)) != SMS_OK)
{
Log_Print( LOG_ERROR, Verbose_Level, Inst_Id, "Can't alloc chunk (%d) !\n", status);
}
else
{
if( ( status = SM_Heap_Unlock( heap_ptr)) != SMS_OK)
{
Log_Print( LOG_ERROR, Verbose_Level, Inst_Id, "Can't unlock heap (%d) !\n", status);
}
else
{
Log_Print( LOG_TRACE, Verbose_Level, Inst_Id, "Chunk allocated !\n");
snprintf( chunk_ptr, Chunk_Size, "Hello brother: (%d) !", chunk_id);
Log_Print( LOG_TRACE, Verbose_Level, Inst_Id, "Message: [%s] writen into the chunk: (%lu)\n", chunk_ptr, chunk_ptr);
fprintf( stdout, "%lu\n", chunk_ptr);
fflush( stdout);
}
}
}
}
Log_Print( LOG_INFO, Verbose_Level, Inst_Id, "Number of message sendeded: (%d) !\n", chunk_id);
if( ( ( status = SM_Heap_Lock( heap_ptr, SMD_WRITE, &locked)) != SMS_OK) && ( locked == TRUE))
{
Log_Print( LOG_ERROR, Verbose_Level, Inst_Id, "Can't lock heap (%d) !\n", status);
}
else
{
if( ( status = SM_Heap_Close( heap_ptr)) != SMS_OK)
{
Log_Print( LOG_ERROR, Verbose_Level, Inst_Id, "Can't close heap (%d) !\n", status);
}
else
{
Log_Print( LOG_TRACE, Verbose_Level, Inst_Id, "Heap closed !\n");
}
}
}
if( ( status = SM_Library_Close( SMD_CLOSE)) != SMS_OK)
{
Log_Print( LOG_ERROR, Verbose_Level, Inst_Id, "Can't close LibShMem (%d) !\n", status);
exit( -1);
}
else
{
Log_Print( LOG_TRACE, Verbose_Level, Inst_Id, "LibShMem closed !\n");
}
exit( 0);
}

View File

@ -1,9 +1,9 @@
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
/* $RCSfile: shmem.h,v $ */ /* $RCSfile: shmem.h,v $ */
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
/* $Revision: 2.3 $ */ /* $Revision: 2.2 $ */
/* $Name: $ */ /* $Name: $ */
/* $Date: 2005/06/26 23:07:40 $ */ /* $Date: 2005/02/23 23:31:06 $ */
/* $Author: agibert $ */ /* $Author: agibert $ */
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
@ -207,7 +207,6 @@ extern "C" {
size_t Segment_Size; /* Taille des segments de mémoire composant le heap */ size_t Segment_Size; /* Taille des segments de mémoire composant le heap */
size_t Limit_Size; /* Taille limite du heap (par défaut : pas de limite) */ size_t Limit_Size; /* Taille limite du heap (par défaut : pas de limite) */
int Auto_Compress; /* Nombre de chunks libres à partir duquel le heap est automatiquement compressé */ int Auto_Compress; /* Nombre de chunks libres à partir duquel le heap est automatiquement compressé */
long Compress_Nb; /* Nomber of time the heap has been compressed */
} SMT_MHH; } SMT_MHH;
/* Heap ouvert */ /* Heap ouvert */

File diff suppressed because it is too large Load Diff

View File

@ -1,9 +1,9 @@
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
/* $RCSfile: libshmem.h,v $ */ /* $RCSfile: libshmem.h,v $ */
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
/* $Revision: 2.3 $ */ /* $Revision: 2.2 $ */
/* $Name: $ */ /* $Name: $ */
/* $Date: 2005/06/26 23:02:35 $ */ /* $Date: 2005/02/23 23:31:06 $ */
/* $Author: agibert $ */ /* $Author: agibert $ */
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
@ -234,6 +234,16 @@ SMT_Status SM_MHH_End (SMT_MHH *);
/*------------------------------------------------------------------------------*/ /*------------------------------------------------------------------------------*/
NDT_Status SM_DSR_Manager( NDT_Root *, NDT_Index_Id, NDT_Node *, NDT_Command, va_list); NDT_Status SM_DSR_Manager( NDT_Root *, NDT_Index_Id, NDT_Node *, NDT_Command, va_list);
/*------------------------------------------------------------------------------*/
/* Initialisation d'un nouveau segment de données (noeud du DSR) */
/*------------------------------------------------------------------------------*/
SMT_DSH *SM_DataSegment_Init (SMT_MHH *, size_t);
/*------------------------------------------------------------------------------*/
/* Terminaison d'un segment de données */
/*------------------------------------------------------------------------------*/
SMT_Status SM_DataSegment_End (NDT_Root *, SMT_DSH *);
/*------------------------------------------------------------------------------*/ /*------------------------------------------------------------------------------*/
/* Ouverture d'un segment de données */ /* Ouverture d'un segment de données */
/*------------------------------------------------------------------------------*/ /*------------------------------------------------------------------------------*/

View File

@ -3,14 +3,10 @@
#include <string.h> #include <string.h>
#include <stdarg.h> #include <stdarg.h>
#include <node.h> #include <node.h>
#define SM_MODE 0 /* Utilisation des API sécurisés */
#ifndef SM_MODE
# define SM_MODE 0 /* Utilisation des API sécurisés */
#endif
#include <shmem.h> #include <shmem.h>
//VER_INFO_EXPORT (smadmin, "$Revision: 2.3 $", "$Name: $", __FILE__, "$Author: agibert $") //VER_INFO_EXPORT (smadmin, "$Revision: 2.1 $", "$Name: $", __FILE__, "$Author: agibert $")
#define USAGE "Usage : %s [ --help | --version [-v] | --create | --destroy ]\n" #define USAGE "Usage : %s [ --help | --version [-v] | --create | --destroy ]\n"
@ -34,15 +30,8 @@
#define ACR_DUMP 17 #define ACR_DUMP 17
#define FCR_DUMP 18 #define FCR_DUMP 18
#define NAME_LEN 100
#define NAME_SIZE ( NAME_LEN + 1)
#define TMP_LEN 100
#define TMP_SIZE ( TMP_LEN + 1)
char menu [1000]; char menu [1000];
char tmp [100];
char tmp [TMP_SIZE];
void init_menu (void); void init_menu (void);
int print_menu (void); int print_menu (void);
@ -50,7 +39,7 @@ int print_menu (void);
int main (int argc, char ** argv) int main (int argc, char ** argv)
{ {
int choice; int choice;
char name [NAME_SIZE]; char name [100];
int Mode, Locked; int Mode, Locked;
void * ptr; void * ptr;
char answer [10]; char answer [10];
@ -138,14 +127,10 @@ int main (int argc, char ** argv)
case MHH_INIT: case MHH_INIT:
fprintf (stdout, "\nNew heap name ? "); fprintf (stdout, "\nNew heap name ? ");
fgets( name, NAME_SIZE, stdin); gets (name);
name[ strlen( name) - 1] = '\0';
fprintf (stdout, "\nHeap segment size ? "); fprintf (stdout, "\nHeap segment size ? ");
fgets( tmp, NAME_SIZE, stdin); gets (tmp);
tmp[ strlen( tmp) - 1] = '\0'; size = atoi (tmp);
size = atol (tmp);
fprintf (stdout, "\nReturn code = %s\n", \ fprintf (stdout, "\nReturn code = %s\n", \
SM_Heap_Open (name, &Heap, size, \ SM_Heap_Open (name, &Heap, size, \
SMD_CREATE, &Locked) == SMS_OK ? "OK" : "NOK" ); SMD_CREATE, &Locked) == SMS_OK ? "OK" : "NOK" );
@ -153,13 +138,9 @@ int main (int argc, char ** argv)
case MHH_OPEN: case MHH_OPEN:
fprintf (stdout, "\nHeap name to open ? "); fprintf (stdout, "\nHeap name to open ? ");
fgets( name, NAME_SIZE, stdin); gets (name);
name[ strlen( name) - 1] = '\0';
fprintf (stdout, "\nOpening mode (read=1 write=2) ? "); fprintf (stdout, "\nOpening mode (read=1 write=2) ? ");
fgets( tmp, TMP_SIZE, stdin); gets (tmp);
tmp[ strlen( tmp) - 1] = '\0';
if (tmp[0] == '1') Mode = SMD_READ; if (tmp[0] == '1') Mode = SMD_READ;
else Mode = SMD_WRITE; else Mode = SMD_WRITE;
if (!strcmp (name, HEAP_SYSTEM)) if (!strcmp (name, HEAP_SYSTEM))
@ -176,9 +157,7 @@ int main (int argc, char ** argv)
case MHH_COMPRESS: case MHH_COMPRESS:
fprintf (stdout, "\nHeap name à compresser ? "); fprintf (stdout, "\nHeap name à compresser ? ");
fgets( name, NAME_SIZE, stdin); gets (name);
name[ strlen( name) - 1] = '\0';
if (SM_Heap_Open (name, &Heap, 0, SMD_OPEN | SMD_WRITE, &Locked) == SMS_OK) if (SM_Heap_Open (name, &Heap, 0, SMD_OPEN | SMD_WRITE, &Locked) == SMS_OK)
{ {
size_t Compress; size_t Compress;
@ -190,9 +169,7 @@ int main (int argc, char ** argv)
case MHH_END: case MHH_END:
fprintf (stdout, "\nHeap name to remove ? "); fprintf (stdout, "\nHeap name to remove ? ");
fgets( name, NAME_SIZE, stdin); gets (name);
name[ strlen( name) - 1] = '\0';
if (!strcmp (name, HEAP_SYSTEM)) if (!strcmp (name, HEAP_SYSTEM))
{ {
fprintf (stdout, \ fprintf (stdout, \
@ -207,9 +184,7 @@ int main (int argc, char ** argv)
case MHH_CLOSE: case MHH_CLOSE:
fprintf (stdout, "\nHeap name to close ? "); fprintf (stdout, "\nHeap name to close ? ");
fgets( name, NAME_SIZE, stdin); gets (name);
name[ strlen( name) - 1] = '\0';
if (!strcmp (name, HEAP_SYSTEM)) if (!strcmp (name, HEAP_SYSTEM))
{ {
fprintf (stdout, \ fprintf (stdout, \
@ -226,9 +201,7 @@ int main (int argc, char ** argv)
case MHH_CHECK: case MHH_CHECK:
fprintf (stdout, "\nHeap name to check/recover ? "); fprintf (stdout, "\nHeap name to check/recover ? ");
fgets( name, NAME_SIZE, stdin); gets (name);
name[ strlen( name) - 1] = '\0';
if (SM_Heap_Open (name, &Heap, 0, SMD_OPEN | SMD_WRITE, &Locked) == SMS_OK) if (SM_Heap_Open (name, &Heap, 0, SMD_OPEN | SMD_WRITE, &Locked) == SMS_OK)
{ {
Nb_Detected = Nb_Corrected = 0; Nb_Detected = Nb_Corrected = 0;
@ -239,55 +212,41 @@ int main (int argc, char ** argv)
case ALLOC_CHUNK: case ALLOC_CHUNK:
fprintf (stdout, "\nHeap name ? "); fprintf (stdout, "\nHeap name ? ");
fgets( name, NAME_SIZE, stdin); gets (name);
name[ strlen( name) - 1] = '\0';
fprintf (stdout, "\nAllocation size ? "); fprintf (stdout, "\nAllocation size ? ");
fgets( tmp, TMP_SIZE, stdin); gets (tmp);
tmp[ strlen( tmp) - 1] = '\0'; size = atoi (tmp);
size = atol (tmp);
if (SM_Heap_Open (name, &Heap, 0, SMD_OPEN | SMD_WRITE, &Locked) == SMS_OK) if (SM_Heap_Open (name, &Heap, 0, SMD_OPEN | SMD_WRITE, &Locked) == SMS_OK)
{ {
SM_Chunk_Alloc (Heap, size, &ptr); SM_Chunk_Alloc (Heap, size, &ptr);
if (Locked == TRUE) SM_Heap_Unlock (Heap); if (Locked == TRUE) SM_Heap_Unlock (Heap);
} }
fprintf (stdout, "\nAddress = 0x%p (%lu)\n", ptr, ptr); fprintf (stdout, "\nAddress = 0x%p (%d)\n", ptr, (unsigned int)ptr);
break; break;
case WRITE_CHUNK: case WRITE_CHUNK:
fprintf (stdout, "\nAddress ? "); fprintf (stdout, "\nAddress ? ");
fgets( tmp, TMP_SIZE, stdin); gets (tmp);
tmp[ strlen( tmp) - 1] = '\0'; ptr = (void *)atoi (tmp);
ptr = (void *)atol (tmp);
fprintf (stdout, "\nString to put in ? "); fprintf (stdout, "\nString to put in ? ");
fgets( tmp, TMP_SIZE, stdin); gets (tmp);
tmp[ strlen( tmp) - 1] = '\0';
strcpy ( (char *)ptr, tmp); strcpy ( (char *)ptr, tmp);
fprintf (stdout, "\nOK\n"); fprintf (stdout, "\nOK\n");
break; break;
case READ_CHUNK: case READ_CHUNK:
fprintf (stdout, "\nAddress ? "); fprintf (stdout, "\nAddress ? ");
fgets( tmp, TMP_SIZE, stdin); gets (tmp);
tmp[ strlen( tmp) - 1] = '\0'; ptr = (void *)atoi (tmp);
ptr = (void *)atol (tmp);
fprintf (stdout, "\nValeur du pointeur = %s\n", (char *)ptr); fprintf (stdout, "\nValeur du pointeur = %s\n", (char *)ptr);
break; break;
case FREE_CHUNK: case FREE_CHUNK:
fprintf (stdout, "\nHeap name ? "); fprintf (stdout, "\nHeap name ? ");
fgets( name, NAME_SIZE, stdin); gets (name);
name[ strlen( name) - 1] = '\0';
fprintf (stdout, "\nAddress ? "); fprintf (stdout, "\nAddress ? ");
fgets( tmp, TMP_SIZE, stdin); gets (tmp);
tmp[ strlen( tmp) - 1] = '\0'; ptr = (void *)atoi (tmp);
ptr = (void *)atol (tmp);
if (SM_Heap_Open (name, &Heap, 0, SMD_OPEN | SMD_WRITE, &Locked) == SMS_OK) if (SM_Heap_Open (name, &Heap, 0, SMD_OPEN | SMD_WRITE, &Locked) == SMS_OK)
{ {
fprintf (stdout, "\nReturn code = %s\n", \ fprintf (stdout, "\nReturn code = %s\n", \
@ -299,9 +258,7 @@ int main (int argc, char ** argv)
case DSR_DUMP: case DSR_DUMP:
fprintf (stdout, "\nHeap name ? "); fprintf (stdout, "\nHeap name ? ");
fgets( name, NAME_SIZE, stdin); gets (name);
name[ strlen( name) - 1] = '\0';
if (SM_Heap_Open (name, &Heap, 0, SMD_OPEN | SMD_READ, &Locked) == SMS_OK) if (SM_Heap_Open (name, &Heap, 0, SMD_OPEN | SMD_READ, &Locked) == SMS_OK)
{ {
ND_DataStruct_Info_Print( stdout, Heap->MHH->DSR, NDD_RECURSIVE_MODE_PARENT_CHILD, 0, 0); ND_DataStruct_Info_Print( stdout, Heap->MHH->DSR, NDD_RECURSIVE_MODE_PARENT_CHILD, 0, 0);
@ -312,9 +269,7 @@ int main (int argc, char ** argv)
case ACR_DUMP: case ACR_DUMP:
fprintf (stdout, "\nHeap name ? "); fprintf (stdout, "\nHeap name ? ");
fgets( name, NAME_SIZE, stdin); gets (name);
name[ strlen( name) - 1] = '\0';
if (SM_Heap_Open (name, &Heap, 0, SMD_OPEN | SMD_READ, &Locked) == SMS_OK) if (SM_Heap_Open (name, &Heap, 0, SMD_OPEN | SMD_READ, &Locked) == SMS_OK)
{ {
ND_DataStruct_Info_Print( stdout, Heap->MHH->ACR, NDD_RECURSIVE_MODE_PARENT_CHILD, 0, 0); ND_DataStruct_Info_Print( stdout, Heap->MHH->ACR, NDD_RECURSIVE_MODE_PARENT_CHILD, 0, 0);
@ -325,9 +280,7 @@ int main (int argc, char ** argv)
case FCR_DUMP: case FCR_DUMP:
fprintf (stdout, "\nHeap name ? "); fprintf (stdout, "\nHeap name ? ");
fgets( name, NAME_SIZE, stdin); gets (name);
name[ strlen( name) - 1] = '\0';
if (SM_Heap_Open (name, &Heap, 0, SMD_OPEN | SMD_READ, &Locked) == SMS_OK) if (SM_Heap_Open (name, &Heap, 0, SMD_OPEN | SMD_READ, &Locked) == SMS_OK)
{ {
ND_DataStruct_Info_Print( stdout, Heap->MHH->FCR, NDD_RECURSIVE_MODE_PARENT_CHILD, 0, 0); ND_DataStruct_Info_Print( stdout, Heap->MHH->FCR, NDD_RECURSIVE_MODE_PARENT_CHILD, 0, 0);
@ -380,9 +333,7 @@ int print_menu (void)
while (tmp[0] == '\0') while (tmp[0] == '\0')
{ {
printf ("\nChoice ? "); printf ("\nChoice ? ");
fgets( tmp, TMP_SIZE, stdin); gets (tmp);
tmp[ strlen( tmp) - 1] = '\0';
} }
return atoi (tmp); return atoi (tmp);