Skip to content

Commit

Permalink
Cleanup: Refactor CMK_CMIPRINTF_IS_A_BUILTIN into CMK_USE_LRTS_STDIO
Browse files Browse the repository at this point in the history
  • Loading branch information
evan-charmworks committed Jun 26, 2023
1 parent fd69b9a commit 5798eba
Show file tree
Hide file tree
Showing 19 changed files with 167 additions and 247 deletions.
6 changes: 3 additions & 3 deletions doc/converse/manual.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1422,15 +1422,15 @@ Input/Output

.. code-block:: c++

void CmiPrintf(char *format, arg1, arg2, ...)
int CmiPrintf(const char *format, ...)
This function does an atomic ``printf()`` on ``stdout``. On machine with
host, this is implemented on top of the messaging layer using
asynchronous sends.

.. code-block:: c++

int CmiScanf(char *format, void *arg1, void *arg2, ...)
int CmiScanf(const char *format, ...)
This function performs an atomic ``scanf`` from ``stdin``. The
processor, on which the caller resides, blocks for input. On machines
Expand All @@ -1439,7 +1439,7 @@ asynchronous send and blocking receive.

.. code-block:: c++

void CmiError(char *format, arg1, arg2, ...)
int CmiError(const char *format, ...)
This function does an atomic ``printf()`` on ``stderr``. On machines
with host, this is implemented on top of the messaging layer using
Expand Down
2 changes: 1 addition & 1 deletion src/arch/gni/conv-common.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#define CMK_CMIDELIVERS_USE_COMMON_CODE 1

#define CMK_CMIPRINTF_IS_A_BUILTIN 0
#define CMK_USE_LRTS_STDIO 0

#define CMI_MACH_TRACE_USEREVENTS 0

Expand Down
2 changes: 1 addition & 1 deletion src/arch/mpi/conv-common.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#define CMK_CMIDELIVERS_USE_COMMON_CODE 1

#define CMK_CMIPRINTF_IS_A_BUILTIN 0
#define CMK_USE_LRTS_STDIO 0

#define CMI_MACH_TRACE_USEREVENTS 0

Expand Down
2 changes: 1 addition & 1 deletion src/arch/netlrts/conv-common.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#define CMK_NET_VERSION 1

#define CMK_CMIPRINTF_IS_A_BUILTIN 1
#define CMK_USE_LRTS_STDIO 1

#define CMK_CMIDELIVERS_USE_COMMON_CODE 1

Expand Down
109 changes: 28 additions & 81 deletions src/arch/netlrts/machine.C
Original file line number Diff line number Diff line change
Expand Up @@ -178,26 +178,6 @@
#define _GNU_SOURCE 1
#include <stdarg.h> /*<- was <varargs.h>*/

#define CMK_USE_PRINTF_HACK 0
#if CMK_USE_PRINTF_HACK
/*HACK: turn printf into CmiPrintf, by just defining our own
external symbol "printf". This may be more trouble than it's worth,
since the only advantage is that it works properly with +syncprint.
This version *won't* work with fprintf(stdout,...) or C++ or Fortran I/O,
because they don't call printf. Has to be defined up here because we probably
haven't properly guessed this compiler's prototype for "printf".
*/
static void InternalPrintf(const char *f, va_list l);
int printf(const char *fmt, ...) {
int nChar;
va_list p; va_start(p, fmt);
InternalPrintf(fmt,p);
va_end(p);
return 10;
}
#endif


#include "converse.h"
#include "cmirdmautils.h"
Expand Down Expand Up @@ -1146,18 +1126,20 @@ void CcsImpl_reply(CcsImplHeader *hdr,int repLen,const void *repData)
}
#endif

#if CMK_USE_LRTS_STDIO
/*****************************************************************************
*
* CmiPrintf, CmiError, CmiScanf
* LrtsPrintf, LrtsError, LrtsScanf
*
*****************************************************************************/
static void InternalWriteToTerminal(int isStdErr,const char *str,int len);
static void InternalPrintf(const char *f, va_list l)

int LrtsPrintf(const char *f, va_list l)
{
ChMessage replymsg;
char *buffer = (char *)CmiTmpAlloc(PRINTBUFSIZE);
CmiStdoutFlush();
vsnprintf(buffer, PRINTBUFSIZE, f, l);
int ret = vsnprintf(buffer, PRINTBUFSIZE, f, l);
if(Cmi_syncprint) {
LOCK_IF_AVAILABLE();
ctrl_sendone_nolock("printsyn", buffer,strlen(buffer)+1,NULL,0);
Expand All @@ -1169,14 +1151,15 @@ static void InternalPrintf(const char *f, va_list l)
}
InternalWriteToTerminal(0,buffer,strlen(buffer));
CmiTmpFree(buffer);
return ret;
}

static void InternalError(const char *f, va_list l)
int LrtsError(const char *f, va_list l)
{
ChMessage replymsg;
char *buffer = (char *)CmiTmpAlloc(PRINTBUFSIZE);
CmiStdoutFlush();
vsnprintf(buffer, PRINTBUFSIZE, f, l);
int ret = vsnprintf(buffer, PRINTBUFSIZE, f, l);
if(Cmi_syncprint) {
ctrl_sendone_locking("printerrsyn", buffer,strlen(buffer)+1,NULL,0);
LOCK_IF_AVAILABLE();
Expand All @@ -1188,15 +1171,16 @@ static void InternalError(const char *f, va_list l)
}
InternalWriteToTerminal(1,buffer,strlen(buffer));
CmiTmpFree(buffer);
return ret;
}

static int InternalScanf(char *fmt, va_list l)
int LrtsScanf(const char *fmt, va_list l)
{
ChMessage replymsg;
char *ptr[20];
char *p; int nargs, i;
nargs=0;
p=fmt;
p = const_cast<char *>(fmt);
while (*p) {
if ((p[0]=='%')&&(p[1]=='*')) { p+=2; continue; }
if ((p[0]=='%')&&(p[1]=='%')) { p+=2; continue; }
Expand All @@ -1206,72 +1190,35 @@ static int InternalScanf(char *fmt, va_list l)
if (nargs > 18) KillEveryone("CmiScanf only does 18 args.\n");
for (i=0; i<nargs; i++) ptr[i]=va_arg(l, char *);
CmiLock(Cmi_scanf_mutex);
if (Cmi_charmrun_fd!=-1)
{/*Send charmrun the format string*/
ctrl_sendone_locking("scanf", fmt, strlen(fmt)+1,NULL,0);
/*Wait for the reply (characters to scan) from charmrun*/
LOCK_IF_AVAILABLE();
ChMessage_recv(Cmi_charmrun_fd,&replymsg);
i = sscanf((char*)replymsg.data, fmt,
ptr[ 0], ptr[ 1], ptr[ 2], ptr[ 3], ptr[ 4], ptr[ 5],
ptr[ 6], ptr[ 7], ptr[ 8], ptr[ 9], ptr[10], ptr[11],
ptr[12], ptr[13], ptr[14], ptr[15], ptr[16], ptr[17]);
ChMessage_free(&replymsg);
UNLOCK_IF_AVAILABLE();
} else
{/*Just do the scanf normally*/
i=scanf(fmt, ptr[ 0], ptr[ 1], ptr[ 2], ptr[ 3], ptr[ 4], ptr[ 5],
ptr[ 6], ptr[ 7], ptr[ 8], ptr[ 9], ptr[10], ptr[11],
ptr[12], ptr[13], ptr[14], ptr[15], ptr[16], ptr[17]);
}
/*Send charmrun the format string*/
ctrl_sendone_locking("scanf", fmt, strlen(fmt)+1,NULL,0);
/*Wait for the reply (characters to scan) from charmrun*/
LOCK_IF_AVAILABLE();
ChMessage_recv(Cmi_charmrun_fd,&replymsg);
i = sscanf((char*)replymsg.data, fmt,
ptr[ 0], ptr[ 1], ptr[ 2], ptr[ 3], ptr[ 4], ptr[ 5],
ptr[ 6], ptr[ 7], ptr[ 8], ptr[ 9], ptr[10], ptr[11],
ptr[12], ptr[13], ptr[14], ptr[15], ptr[16], ptr[17]);
ChMessage_free(&replymsg);
UNLOCK_IF_AVAILABLE();
CmiUnlock(Cmi_scanf_mutex);
return i;
}
#if CMK_CMIPRINTF_IS_A_BUILTIN

/*New stdarg.h declarations*/
void CmiPrintf(const char *fmt, ...)
int LrtsUsePrintf()
{
if (quietMode) return;
CpdSystemEnter();
{
va_list p; va_start(p, fmt);
if (Cmi_charmrun_fd!=-1 && _writeToStdout)
InternalPrintf(fmt, p);
else
vfprintf(stdout,fmt,p);
va_end(p);
}
CpdSystemExit();
return Cmi_charmrun_fd != -1 && _writeToStdout;
}

void CmiError(const char *fmt, ...)
int LrtsUseError()
{
CpdSystemEnter();
{
va_list p; va_start (p, fmt);
if (Cmi_charmrun_fd!=-1)
InternalError(fmt, p);
else
vfprintf(stderr,fmt,p);
va_end(p);
}
CpdSystemExit();
return Cmi_charmrun_fd != -1;
}

int CmiScanf(const char *fmt, ...)
int LrtsUseScanf()
{
int i;
CpdSystemEnter();
{
va_list p; va_start(p, fmt);
i = InternalScanf((char *)fmt, p);
va_end(p);
}
CpdSystemExit();
return i;
return Cmi_charmrun_fd != -1;
}

#endif

/***************************************************************************
Expand Down
7 changes: 3 additions & 4 deletions src/arch/ofi/conv-common.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@
every machine. */
#define CMK_CMIDELIVERS_USE_COMMON_CODE 1

/* specifies if the functions CmiPrintf, CmiError and CmiScanf are implemented
in machine.C (1), or if the standard definitions in convcore.C should be used
(0). */
#define CMK_CMIPRINTF_IS_A_BUILTIN 0
/* specifies if the functions LrtsPrintf, LrtsError and LrtsScanf are present
in machine.C (1), or if not (0). */
#define CMK_USE_LRTS_STDIO 0

/* define the converse headers. For most of the purposes, only the UNIQUE header
needs to be modified, the others will follow.
Expand Down
2 changes: 1 addition & 1 deletion src/arch/pami/conv-common.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

#define CMK_CMIDELIVERS_USE_COMMON_CODE 1

#define CMK_CMIPRINTF_IS_A_BUILTIN 0
#define CMK_USE_LRTS_STDIO 0

#define CMK_HANDLE_SIGUSR 1

Expand Down
2 changes: 1 addition & 1 deletion src/arch/pamilrts/conv-common.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#define CMK_HAS_PARTITION 1
#define CMK_HAS_INTEROP 1

#define CMK_CMIPRINTF_IS_A_BUILTIN 0
#define CMK_USE_LRTS_STDIO 0

#define CMK_HANDLE_SIGUSR 1

Expand Down
7 changes: 3 additions & 4 deletions src/arch/template/conv-common.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
every machine. */
#define CMK_CMIDELIVERS_USE_COMMON_CODE 1

/* specifies if the functions CmiPrintf, CmiError and CmiScanf are implemented
in machine.C (1), or if the standard definitions in convcore.C should be used
(0). */
#define CMK_CMIPRINTF_IS_A_BUILTIN 0
/* specifies if the functions LrtsPrintf, LrtsError and LrtsScanf are present
in machine.C (1), or if not (0). */
#define CMK_USE_LRTS_STDIO 0

/* define the converse headers. For most of the purposes, only the UNIQUE header
needs to be modified, the others will follow.
Expand Down
17 changes: 10 additions & 7 deletions src/arch/template/machine.C
Original file line number Diff line number Diff line change
Expand Up @@ -260,18 +260,21 @@ int CmiBarrier(void);
int CmiBarrierZero(void);


/** PRINTF FUNCTIONS
/** STDIO FUNCTIONS
* Default code is provided in convcore.C but for particular architectures they
* can be reimplemented. At present only netlrts- versions reimplement them.
* Default code is provided in convcore.C but for particular machine layers they
* can branch to custom reimplementations.
*/

#if CMK_CMIPRINTF_IS_A_BUILTIN
#if CMK_USE_LRTS_STDIO

void CmiPrintf(const char *, ...);
void CmiError(const char *, ...);
int CmiScanf(const char *, ...);
int LrtsPrintf(const char *, va_list);
int LrtsError(const char *, va_list);
int LrtsScanf(const char *, va_list);
int LrtsUsePrintf(void);
int LrtsUseError(void);
int LrtsUseScanf(void);

#endif

Expand Down
7 changes: 3 additions & 4 deletions src/arch/ucx/conv-common.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@
every machine. */
#define CMK_CMIDELIVERS_USE_COMMON_CODE 1

/* specifies if the functions CmiPrintf, CmiError and CmiScanf are implemented
in machine.C (1), or if the standard definitions in convcore.c should be used
(0). */
#define CMK_CMIPRINTF_IS_A_BUILTIN 0
/* specifies if the functions LrtsPrintf, LrtsError and LrtsScanf are present
in machine.C (1), or if not (0). */
#define CMK_USE_LRTS_STDIO 0

/* define the converse headers. For most of the purposes, only the UNIQUE header
needs to be modified, the others will follow.
Expand Down
9 changes: 9 additions & 0 deletions src/arch/util/machine-lrts.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,13 @@ void LrtsBarrier(void);
/* ### lock functions ### */
#include "lrtslock.h"

#if CMK_USE_LRTS_STDIO
int LrtsPrintf(const char *, va_list);
int LrtsError(const char *, va_list);
int LrtsScanf(const char *, va_list);
int LrtsUsePrintf(void);
int LrtsUseError(void);
int LrtsUseScanf(void);
#endif

#endif
2 changes: 1 addition & 1 deletion src/arch/verbs/conv-common.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#define CMK_NET_VERSION 1

#define CMK_CMIPRINTF_IS_A_BUILTIN 1
#define CMK_USE_LRTS_STDIO 1

#define CMK_CMIDELIVERS_USE_COMMON_CODE 1

Expand Down

0 comments on commit 5798eba

Please sign in to comment.