Bitwise comparison of cols


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Bitwise comparison of cols
# 8  
Old 11-09-2013
Thank you drl ...

Pardon my ignorance, from your post I can follow that the code can break up up the input file to feed into a number of parallel CPU operations,, and due to parallel processing, the real time reduces significantly.. You are right that most of your post is too advanced for me to understand,

can I utilize your code directly along with Chublers to do the parallel processing without the help of a code-literate colleague ? You have mentioned you saved Chublers code in the file a1, then save your script as s1.sh and run ./s1 ?
# 9  
Old 11-10-2013
Hi.
Quote:
Originally Posted by ritakadm
can I utilize your code directly along with Chublers to do the parallel processing without the help of a code-literate colleague ?
My post was to illustrate the idea of parallelizing the solution. In order for this to become a production code, the perl code parallel (or something similar) needs to be available. Is it on your system?

Then for each section of data, your header -- "Org1 Org2 Org3 .... Org750" needs to be present at the beginning. Do you know how that might be done?

The hardware system needs to have more than one core (CPU) available. What hardware, OS, are you using?

The final results from command parallel would need to be collected and summed for the same counts from different instances. Can you do that, based on how the code of Chubler produces output?

If I were designing such a production code, I would want to be able to run tests on smaller sections of the data so that I could be sure that all parts of the tasks are correct, and that the entire process is near optimal and balanced (IO and CPU) for the platform, hardware, OS, utilitiies.

Best wishes ... cheers, drl
# 10  
Old 11-10-2013
This code should split the file up into Pieces and run the solution in parallel.

Set CPUS= to the number of parallel instances you would like to run (no more than the number of CPUs you have in the system), and SOURCE= to your source datafile name.

While this is running the passN.log files will have their % complete.

Code:
CPUS=4
SOURCE=og
lines=$(wc -l < $SOURCE)
end=0
i=1

while [ $i -le $CPUS ]
do
   ((start=end+1))
   ((end=lines*i/CPUS))
   awk -v s=$start -v e=$end 'NR==1||((NR>=s&&NR<=e))' $SOURCE > pass$i
   ((i++))
done

i=0
while [ $i -le $CPUS ]
do
    nohup awk -vL=$((lines/CPUS)) 'NR==1{for(cols=1;cols<=NF;cols++)H[cols]=$cols;next}
    {for(i=1;i<=NF;i++)
        for(j=i+1;j<=NF;j++)
           if($i==$j) c[i,j]++
    }
    P!=int(NR/L*100) {
       P=int(NR/L*100);
       printf("Processed %d%%%c", P, 13) > "/dev/stderr"
    }
    END{
       for(i=1;i<cols;i++)
          for(j=i+1;j<cols;j++)
          print H[i],H[j],0+c[i,j]
    } ' pass$i > pass$i.out 2> pass$i.log &
    ((i++))
done


Once the have finished you will have passN.out data files that can be summed to give your final totals with:

Code:
awk '
   {L[FNR]=$1 " " $2;N[FNR]+=$3}
   END{for(i=1;i<=FNR;i++) print L[i],N[i]}' pass[0-9]*.out > result.txt

As drl pointed out you should really prove this first with a smaller data file (eg 1000 lines or so) before investing many days of CPU processing on the full sized dataset.
These 2 Users Gave Thanks to Chubler_XL For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Bitwise operation for state machine

Hello All, I am writing basic state machine which maintains 8 different states and there is posibility that system may be in multiple states at a time (Except for state1 to state3. menas only once state can be active at a time from state1 to state3). I have declared... (9 Replies)
Discussion started by: anand.shah
9 Replies

2. Shell Programming and Scripting

how to use bitwise or operator in /bin/sh

please any one can suggest me how to use bitesie || opearator to do this #initallize a=0 b=0 #condition if then a=0 else a=1 fi #bitwise or opeartion b = a || b Please view this code tag video for how to use code tags when posting code and data. (3 Replies)
Discussion started by: Palaniappan
3 Replies

3. FAQ Submission Queue

Analysis in bitwise XOR

The purpose of this article is revealing the unrevealed parts of the bitwise XOR. As we aware, the truth table for the XOR operator is : A B A^B 0 0 0 0 1 1 1 0 1 1 1 0 For example , 1^2 will be calculated as given below: First the operands... (1 Reply)
Discussion started by: pandeesh
1 Replies

4. Emergency UNIX and Linux Support

bitwise and between two 32 bit binaries

Hello All, i have two 16 bit binaries that in two different variables, i want to perform a bitwise AND between the two and store the result in a different variable. can anyone throw some light on doing this in a bourne shell... eg var1= 1110101010101011 ... (8 Replies)
Discussion started by: venu
8 Replies

5. Shell Programming and Scripting

Grouping matches by cols

Dear all I have a large file w. ~ 10 million lines. The first two cols have matching partners. For example: A A A B B B or A A B A B B The matches may be separated by an unknown number of lines. My intention is to group them and add a "group" value in the last col. For... (12 Replies)
Discussion started by: gbalsu
12 Replies

6. Programming

bitwise and if

Hi Suppose we have these code lines: #define _IN_USE 0x001 /* set when process slot is in use */ #define _EXITING 0x002 /* set when exit is expected */ #define _REFRESHING 0x004 ... 1 main () { 2 3 unsigned r_flags =_REFRESHING; 4 5 if (r_flag &... (3 Replies)
Discussion started by: Puntino
3 Replies

7. Shell Programming and Scripting

Bitwise negation

I am taking an online course on Unix scripting. The topic is Unix arithmetic operators and the lesson is Logical and bitwise operations. It is not clear how much storage space Unix uses to represent integers that are typed. Bitwise negation caused me to question how many bits are used to... (3 Replies)
Discussion started by: dLloydm
3 Replies

8. Programming

resetting counter using bitwise XOR

Hi ! How to reset a variable to 0 after a reset value, say 10 using bitwise XOR. For example, int cnt=0; if(cnt<10) cnt++; else cnt = 0; How can we achieve this by using XOR only. thanks, (1 Reply)
Discussion started by: mrgubbala
1 Replies

9. UNIX for Advanced & Expert Users

bitwise operators

can anybody write a program to divide a number by another number using bitwise operators (9 Replies)
Discussion started by: areef4u
9 Replies

10. Programming

Bit-fields and Bitwise operators

Hi, Is it possible to use bitwise operators in bit fields? For example: typedef struct Mystruct { unsigned char A :1 ; unsigned char B :1 ; } Mystruct; and assume struct Mystruct STR_1S, STR_2S, tempSTRS = {0}; then the following line: tempSTRS = STR_1S & STR_2S; gives the... (3 Replies)
Discussion started by: amatsaka
3 Replies
Login or Register to Ask a Question