#include <ctype.h>
+#include <assert.h>
#include "copyrite.h"
#include "sysstuff.h"
#include "macros.h"
#include "mtop_util.h"
#include "gmxfio.h"
-#ifdef GMX_THREADS
+#ifdef GMX_THREAD_MPI
#include "thread_mpi.h"
#endif
static const char *program_name=NULL;
static char *cmd_line=NULL;
-#ifdef GMX_THREADS
+#ifdef GMX_THREAD_MPI
/* For now, some things here are simply not re-entrant, so
we have to actively lock them. */
static tMPI_Thread_mutex_t init_mutex=TMPI_THREAD_MUTEX_INITIALIZER;
const char *ShortProgram(void)
{
const char *pr,*ret;
-#ifdef GMX_THREADS
+#ifdef GMX_THREAD_MPI
tMPI_Thread_mutex_lock(&init_mutex);
#endif
pr=ret=program_name;
-#ifdef GMX_THREADS
+#ifdef GMX_THREAD_MPI
tMPI_Thread_mutex_unlock(&init_mutex);
#endif
if ((pr=strrchr(ret,DIR_SEPARATOR)) != NULL)
ret=pr+1;
- /* Strip away the libtool prefix if it's still there. */
- if(strlen(ret) > 3 && !strncmp(ret, "lt-", 3))
- ret = ret + 3;
return ret;
}
const char *Program(void)
{
const char *ret;
-#ifdef GMX_THREADS
+#ifdef GMX_THREAD_MPI
tMPI_Thread_mutex_lock(&init_mutex);
#endif
ret=program_name;
-#ifdef GMX_THREADS
+#ifdef GMX_THREAD_MPI
tMPI_Thread_mutex_unlock(&init_mutex);
#endif
return ret;
const char *command_line(void)
{
const char *ret;
-#ifdef GMX_THREADS
+#ifdef GMX_THREAD_MPI
tMPI_Thread_mutex_lock(&init_mutex);
#endif
ret=cmd_line;
-#ifdef GMX_THREADS
+#ifdef GMX_THREAD_MPI
tMPI_Thread_mutex_unlock(&init_mutex);
#endif
return ret;
void set_program_name(const char *argvzero)
{
-#ifdef GMX_THREADS
+#ifdef GMX_THREAD_MPI
tMPI_Thread_mutex_lock(&init_mutex);
#endif
- /* When you run a dynamically linked program before installing
- * it, libtool uses wrapper scripts and prefixes the name with "lt-".
- * Until libtool is fixed to set argv[0] right, rip away the prefix:
- */
if (program_name == NULL)
{
- if(strlen(argvzero)>3 && !strncmp(argvzero,"lt-",3))
- program_name=strdup(argvzero+3);
- else
- program_name=strdup(argvzero);
+ /* if filename has file ending (e.g. .exe) then strip away */
+ char* extpos=strrchr(argvzero,'.');
+ if(extpos > strrchr(argvzero,DIR_SEPARATOR))
+ {
+ program_name=gmx_strndup(argvzero,extpos-argvzero);
+ }
+ else
+ {
+ program_name=gmx_strdup(argvzero);
+ }
}
if (program_name == NULL)
program_name="GROMACS";
-#ifdef GMX_THREADS
+#ifdef GMX_THREAD_MPI
tMPI_Thread_mutex_unlock(&init_mutex);
#endif
}
int i;
size_t cmdlength;
-#ifdef GMX_THREADS
+#ifdef GMX_THREAD_MPI
tMPI_Thread_mutex_lock(&init_mutex);
#endif
if (cmd_line==NULL)
strcat(cmd_line," ");
}
}
-#ifdef GMX_THREADS
+#ifdef GMX_THREAD_MPI
tMPI_Thread_mutex_unlock(&init_mutex);
#endif
static void set_default_time_unit(const char *time_list[], gmx_bool bCanTime)
{
- int i,j;
+ int i=0,j;
const char *select = NULL;
if (bCanTime)
}
}
}
- if (!bCanTime || select == NULL || strcmp(time_list[i], select) != 0)
+ if (!bCanTime || select == NULL ||
+ time_list[i]==NULL || strcmp(time_list[i], select) != 0)
{
/* Set it to the default: ps */
i = 1;
static void usage(const char *type,const char *arg)
{
- if (arg != NULL)
- gmx_fatal(FARGS,"Expected %s argument for option %s\n",type,arg);
+ assert(arg);
+ gmx_fatal(FARGS,"Expected %s argument for option %s\n",type,arg);
}
int iscan(int argc,char *argv[],int *i)
/* The some system, e.g. the catamount kernel on cray xt3 do not have nice(2). */
if (nicelevel != 0 && !bExit)
{
-#ifdef GMX_THREADS
+#ifdef GMX_THREAD_MPI
static gmx_bool nice_set=FALSE; /* only set it once */
tMPI_Thread_mutex_lock(&init_mutex);
if (!nice_set)
{
#endif
i=nice(nicelevel); /* assign ret value to avoid warnings */
-#ifdef GMX_THREADS
+#ifdef GMX_THREAD_MPI
nice_set=TRUE;
}
tMPI_Thread_mutex_unlock(&init_mutex);
gmx_cmd(argv[1]);
}
}
- if (bExit) {
- if (gmx_parallel_env_initialized())
- /*gmx_abort(gmx_node_rank(),gmx_node_num(),0);*/
- gmx_finalize();
+ if (bExit)
+ {
+ gmx_finalize_par();
+
exit(0);
}
#undef FF