MPI and C: loop through file of commands in file -


hi want parallelize process on 40 cpus, each job runs 1 process.

i using c , mpi torque (pbs) scheduler on cluster.

here script.

#include <stdio.h> #include <stdlib.h> #include <mpi.h> #include <unistd.h>  const char file_name[] = "/home/foo/c/mpi/cov_test/test_command.txt"; const char wrk_dir[] = "/home/foo/c/mpi/cov_test"; char comm[39][256]; int main(int argc, char **argv) {     int rank;     int size;     int count =0;     file *in_file;     char line[256];     char *pos;      in_file = fopen(file_name, "r");     if (in_file == null) {             printf("cannot open %s\n", file_name);             exit(8);     }     if(in_file)     {             while(fgets(line, sizeof(line), in_file))             {       /* remove newline @ end of file     *                      * maybe not best way it? *                      * mpicc compiler throws error   */                     if((pos=strchr(line, '\n')) != null)                             *pos = '\0';                     strcpy(comm[count], line);                      count++;             }     }      chdir(wrk_dir);       chdir(wrk_dir);      mpi_init(&argc,&argv);     mpi_comm_rank(mpi_comm_world, &rank);     mpi_comm_size(mpi_comm_world, &size);      /* saw on posting */     int start = (rank*count)/size;     int end = ((rank+1)*count)/size;      for(int i= start; < end; i++) {              printf("%s\n", comm[rank]);             /*system(comm[rank]);*/     }      mpi_finalize(); } 

the output first command of file "test_command.txt"

here torque submission file

#!/bin/bash #pbs -q condo #pbs -l walltime=01:00:00 #pbs -l nodes=5:ppn=8 #pbs -j oe #pbs -o /home/foo/c/mpi/cov_test/pilot_mpi_out  #had export perl libraries export perl5lib=/home/foo/myperl/lib/perl5:/home/foo/myperl/share/perl5:$perl5lib cd $home/c/mpi/cov_test /opt/openmpi/bin/mpirun -machinefile $pbs_nodefile -np 40 ./pilot_mpi_test-2 

i'm new c might (probably) doing ghastly. time :)

it should printf("%s\n", comm[i]); instead of printf("%s\n", comm[rank]);.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -