Skip to content

Singleton Spawn tests #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,7 @@ collective-big-count/test_scatterv
collective-big-count/*_uniform_count

comm_split_type/cmsplit_type

singleton/hello_c
singleton/simple_spawn
singleton/simple_spawn_multiple
18 changes: 18 additions & 0 deletions singleton/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
CC=mpicc
CFLAGS=-Wall -g -O0

PROGS=hello_c simple_spawn simple_spawn_multiple

all: $(PROGS)

hello_c: hello_c.c
$(CC) hello_c.c $(CFLAGS) -o hello_c

simple_spawn: simple_spawn.c
$(CC) simple_spawn.c $(CFLAGS) -o simple_spawn

simple_spawn_multiple: simple_spawn_multiple.c
$(CC) simple_spawn_multiple.c $(CFLAGS) -o simple_spawn_multiple

clean:
$(RM) $(PROGS) *.o
27 changes: 27 additions & 0 deletions singleton/hello_c.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
#include "mpi.h"

int main(int argc, char* argv[])
{
int mcw_rank, mcw_size, len;
char name[MPI_MAX_PROCESSOR_NAME];

MPI_Init(&argc, &argv);

MPI_Comm_rank(MPI_COMM_WORLD, &mcw_rank);
MPI_Comm_size(MPI_COMM_WORLD, &mcw_size);
MPI_Get_processor_name(name, &len);

MPI_Barrier( MPI_COMM_WORLD );

printf("%3d/%3d) [%s] %d Hello, world!\n",
mcw_rank, mcw_size, name, (int)getpid());
fflush(NULL);

MPI_Finalize();

return 0;
}
38 changes: 38 additions & 0 deletions singleton/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash -e

echo "====================="
echo "Testing: Hello with mpirun"
echo "====================="
mpirun --np 1 ./hello_c

echo "====================="
echo "Testing: Hello as a singleton"
echo "====================="
./hello_c


echo "====================="
echo "Testing: MPI_Comm_spawn with mpirun"
echo "====================="
mpirun --np 1 ./simple_spawn ./simple_spawn

echo "====================="
echo "Testing: MPI_Comm_spawn as a singleton"
echo "====================="
./simple_spawn ./simple_spawn


echo "====================="
echo "Testing: MPI_Comm_spawn_multiple with mpirun"
echo "====================="
mpirun --np 1 ./simple_spawn_multiple ./simple_spawn_multiple

echo "====================="
echo "Testing: MPI_Comm_spawn_multiple as a singleton"
echo "====================="
./simple_spawn_multiple ./simple_spawn_multiple


echo "====================="
echo "Success"
echo "====================="
24 changes: 24 additions & 0 deletions singleton/simple_spawn.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include <mpi.h>
#include <stdio.h>

int main(int argc, char *argv[])
{
MPI_Comm parent, intercomm;

MPI_Init(NULL, NULL);

MPI_Comm_get_parent(&parent);
if (MPI_COMM_NULL != parent)
MPI_Comm_disconnect(&parent);

if (argc > 1) {
printf("Spawning '%s' ... ", argv[1]);
MPI_Comm_spawn(argv[1], MPI_ARGV_NULL,
1, MPI_INFO_NULL, 0, MPI_COMM_SELF,
&intercomm, MPI_ERRCODES_IGNORE);
MPI_Comm_disconnect(&intercomm);
printf("OK\n");
}

MPI_Finalize();
}
48 changes: 48 additions & 0 deletions singleton/simple_spawn_multiple.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include <mpi.h>
#include <stdio.h>
#include <string.h>

int main(int argc, char *argv[])
{
MPI_Comm parent, intercomm;
int maxprocs[2];
char *command[2];
char **spawn_argv[2];
char *argv0[2];
char *argv1[2];
MPI_Info info[2];

MPI_Init(NULL, NULL);

MPI_Comm_get_parent(&parent);
if (MPI_COMM_NULL != parent) {
printf("Hello from a Child (%s)\n", argv[1]);
fflush(NULL);
MPI_Barrier(parent);
MPI_Comm_disconnect(&parent);
}
else if(argc > 1) {
maxprocs[0] = 1;
maxprocs[1] = 2;
command[0] = strdup(argv[1]);
command[1] = strdup(argv[1]);
spawn_argv[0] = argv0;
spawn_argv[1] = argv1;
argv0[0] = strdup("A");
argv0[1] = NULL;
argv1[0] = strdup("B");
argv1[1] = NULL;
info[0] = MPI_INFO_NULL;
info[1] = MPI_INFO_NULL;

printf("Spawning Multiple '%s' ... ", argv[1]);
MPI_Comm_spawn_multiple(2, command, spawn_argv, maxprocs, info,
0, MPI_COMM_SELF,
&intercomm, MPI_ERRCODES_IGNORE);
MPI_Barrier(intercomm);
MPI_Comm_disconnect(&intercomm);
printf("OK\n");
}

MPI_Finalize();
}