From 168b1818c6339ac699bab099ebd413ab1cae4388 Mon Sep 17 00:00:00 2001 From: agibert Date: Sun, 26 Jun 2005 23:16:38 +0000 Subject: [PATCH] Initial release. --- demo/smdemo0.c | 380 +++++++++++++++++++++++++++++++++++++++++++++ demo/smdemo0_rcv.c | 204 ++++++++++++++++++++++++ demo/smdemo0_snd.c | 204 ++++++++++++++++++++++++ 3 files changed, 788 insertions(+) create mode 100644 demo/smdemo0.c create mode 100644 demo/smdemo0_rcv.c create mode 100644 demo/smdemo0_snd.c diff --git a/demo/smdemo0.c b/demo/smdemo0.c new file mode 100644 index 0000000..a819812 --- /dev/null +++ b/demo/smdemo0.c @@ -0,0 +1,380 @@ +/*---------------------------------------------------------------------------------*/ +/* $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 +#include +#include +#include +#include +#include + + + +#include + + +#ifndef SM_MODE +# define SM_MODE 0 /* Utilisation des API sécurisés */ +#endif + +#include + + + +#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); +} diff --git a/demo/smdemo0_rcv.c b/demo/smdemo0_rcv.c new file mode 100644 index 0000000..3a6bad3 --- /dev/null +++ b/demo/smdemo0_rcv.c @@ -0,0 +1,204 @@ +/*---------------------------------------------------------------------------------*/ +/* $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 +#include +#include +#include +#include +#include + +#include + +#ifndef SM_MODE +# define SM_MODE 0 /* Utilisation des API sécurisés */ +#endif + +#include + + + + + +#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); +} diff --git a/demo/smdemo0_snd.c b/demo/smdemo0_snd.c new file mode 100644 index 0000000..08a0d06 --- /dev/null +++ b/demo/smdemo0_snd.c @@ -0,0 +1,204 @@ +/*---------------------------------------------------------------------------------*/ +/* $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 +#include +#include +#include +#include +#include + +#include + +#ifndef SM_MODE +# define SM_MODE 0 /* Utilisation des API sécurisés */ +#endif + +#include + + + + + +#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); +}