Skip to content

Instantly share code, notes, and snippets.

@t-nissie
Last active November 16, 2016 09:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save t-nissie/38df694682cbdb08023567731f432fbf to your computer and use it in GitHub Desktop.
Save t-nissie/38df694682cbdb08023567731f432fbf to your computer and use it in GitHub Desktop.
MPIで大きなsize_tをMPI_UINT64_Tとして渡して、大きな配列を確保/初期化 (first touch) する。MPI_AINTまたはMPI_COUNTを使うべき?
// large_array.c
// Gist: https://gist.github.com/t-nissie/38df694682cbdb08023567731f432fbf
// Description: pass a size_t as MPI_UINT64_T, allocate a large array of double, then first-touch it
// Author: Takeshi Nishimatsu
// License: GPLv3
// Reference: https://github.com/jeffhammond/BigMPI/blob/master/test/test_reduce_x.c
////
#include <mpi.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv)
{
int i_error, mpi_my_rank;
double start, finish;
double *ary;
size_t N, i;
i_error = MPI_Init(&argc,&argv);
i_error = MPI_Comm_rank(MPI_COMM_WORLD, &mpi_my_rank);
if (mpi_my_rank==0) {
i_error = sscanf(argv[1],"%zu",&N);
}
MPI_Bcast(&N, 1, MPI_UINT64_T, 0, MPI_COMM_WORLD);
ary = (double *) malloc(N*sizeof(double));
if (ary==0) {
i_error = MPI_Abort(MPI_COMM_WORLD, 1);
}
start = MPI_Wtime();
for (i=0; i<N; ++i) {
ary[i] = 0.0;
}
finish = MPI_Wtime();
printf("%3d %20zu %12.5f\n", mpi_my_rank, N, finish - start);
i_error = MPI_Finalize();
}
//Local variables:
//compile-command: "mpicc -c large_array.c && mpicc -o large_array large_array.o && mpiexec -np 4 ./large_array 1000"
//End:
#!/usr/bin/csh -f
#@ job_name = 2G
#@ output = $(job_name).$(jobid).$(stepid).out
#@ error = $(job_name).$(jobid).$(stepid).err
#@ notification = complete
#@ notify_user = t-nissie@example.com
#@ job_type = parallel
#@ total_tasks = 2
#@ stack_limit = 960mb
#@ task_affinity = cpu(1)
#@ cpus_per_core = 1
#@ queue
# Description: queuing script for SR16000
# Compilation: mpcc -c large_array.c && mpcc -o large_array large_array.o
# Usage: submit EJCF general -jcf large_array
##
poe ./large_array 2000000000
==> 2G.441629.0.out <==
1 2000000000 9.62017
0 2000000000 9.64697
==> 4G.441630.0.out <==
1 4000000000 19.24187
0 4000000000 19.29837
==> 6G.441631.0.out <==
1 6000000000 28.86055
0 6000000000 28.94758
==> 7G.441632.0.out <==
---> error with exit code of 1
maybe, out of memory
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment